Skip to content

Commit 2ef836c

Browse files
committed
Merge remote-tracking branch 'origin/main' into clang-explain-std-layout
2 parents 7d6b608 + b8e8ff3 commit 2ef836c

File tree

49 files changed

+987
-554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+987
-554
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ Non-comprehensive list of changes in this release
329329
``__reference_constructs_from_temporary`` should be used instead. (#GH44056)
330330
- Added `__builtin_get_vtable_pointer` to directly load the primary vtable pointer from a
331331
polymorphic object.
332+
- ``libclang`` receives a family of new bindings to query basic facts about
333+
GCC-style inline assembly blocks, including whether the block is ``volatile``
334+
and its template string following the LLVM IR ``asm`` format. (#GH143424)
332335
- Clang no longer rejects reinterpret_cast conversions between indirect
333336
ARC-managed pointers and other pointer types. The prior behavior was overly
334337
strict and inconsistent with the ARC specification.
@@ -644,7 +647,7 @@ Improvements to Clang's diagnostics
644647
#GH69470, #GH59391, #GH58172, #GH46215, #GH45915, #GH45891, #GH44490,
645648
#GH36703, #GH32903, #GH23312, #GH69874.
646649

647-
650+
648651
Improvements to Clang's time-trace
649652
----------------------------------
650653

clang/include/clang-c/Index.h

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#define CINDEX_VERSION_MAJOR 0
3737
#define CINDEX_VERSION_MINOR 64
3838

39-
#define CINDEX_VERSION_ENCODE(major, minor) (((major)*10000) + ((minor)*1))
39+
#define CINDEX_VERSION_ENCODE(major, minor) (((major) * 10000) + ((minor) * 1))
4040

4141
#define CINDEX_VERSION \
4242
CINDEX_VERSION_ENCODE(CINDEX_VERSION_MAJOR, CINDEX_VERSION_MINOR)
@@ -4495,6 +4495,129 @@ CINDEX_LINKAGE CXStringSet *clang_Cursor_getCXXManglings(CXCursor);
44954495
*/
44964496
CINDEX_LINKAGE CXStringSet *clang_Cursor_getObjCManglings(CXCursor);
44974497

4498+
/**
4499+
* @}
4500+
*/
4501+
4502+
/**
4503+
* \defgroup CINDEX_MODULE Inline Assembly introspection
4504+
*
4505+
* The functions in this group provide access to information about GCC-style
4506+
* inline assembly statements.
4507+
*
4508+
* @{
4509+
*/
4510+
4511+
/**
4512+
* Given a CXCursor_GCCAsmStmt cursor, return the assembly template string.
4513+
* As per LLVM IR Assembly Template language, template placeholders for
4514+
* inputs and outputs are either of the form $N where N is a decimal number
4515+
* as an index into the input-output specification,
4516+
* or ${N:M} where N is a decimal number also as an index into the
4517+
* input-output specification and M is the template argument modifier.
4518+
* The index N in both cases points into the the total inputs and outputs,
4519+
* or more specifically, into the list of outputs followed by the inputs,
4520+
* starting from index 0 as the first available template argument.
4521+
*
4522+
* This function also returns a valid empty string if the cursor does not point
4523+
* at a GCC inline assembly block.
4524+
*
4525+
* Users are responsible for releasing the allocation of returned string via
4526+
* \c clang_disposeString.
4527+
*/
4528+
4529+
CINDEX_LINKAGE CXString clang_Cursor_getGCCAssemblyTemplate(CXCursor);
4530+
4531+
/**
4532+
* Given a CXCursor_GCCAsmStmt cursor, check if the assembly block has goto
4533+
* labels.
4534+
* This function also returns 0 if the cursor does not point at a GCC inline
4535+
* assembly block.
4536+
*/
4537+
4538+
CINDEX_LINKAGE unsigned clang_Cursor_isGCCAssemblyHasGoto(CXCursor);
4539+
4540+
/**
4541+
* Given a CXCursor_GCCAsmStmt cursor, count the number of outputs.
4542+
* This function also returns 0 if the cursor does not point at a GCC inline
4543+
* assembly block.
4544+
*/
4545+
4546+
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumOutputs(CXCursor);
4547+
4548+
/**
4549+
* Given a CXCursor_GCCAsmStmt cursor, count the number of inputs.
4550+
* This function also returns 0 if the cursor does not point at a GCC inline
4551+
* assembly block.
4552+
*/
4553+
4554+
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumInputs(CXCursor);
4555+
4556+
/**
4557+
* Given a CXCursor_GCCAsmStmt cursor, get the constraint and expression cursor
4558+
* to the Index-th input.
4559+
* This function returns 1 when the cursor points at a GCC inline assembly
4560+
* statement, `Index` is within bounds and both the `Constraint` and `Expr` are
4561+
* not NULL.
4562+
* Otherwise, this function returns 0 but leaves `Constraint` and `Expr`
4563+
* intact.
4564+
*
4565+
* Users are responsible for releasing the allocation of `Constraint` via
4566+
* \c clang_disposeString.
4567+
*/
4568+
4569+
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyInput(CXCursor Cursor,
4570+
unsigned Index,
4571+
CXString *Constraint,
4572+
CXCursor *Expr);
4573+
4574+
/**
4575+
* Given a CXCursor_GCCAsmStmt cursor, get the constraint and expression cursor
4576+
* to the Index-th output.
4577+
* This function returns 1 when the cursor points at a GCC inline assembly
4578+
* statement, `Index` is within bounds and both the `Constraint` and `Expr` are
4579+
* not NULL.
4580+
* Otherwise, this function returns 0 but leaves `Constraint` and `Expr`
4581+
* intact.
4582+
*
4583+
* Users are responsible for releasing the allocation of `Constraint` via
4584+
* \c clang_disposeString.
4585+
*/
4586+
4587+
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyOutput(CXCursor Cursor,
4588+
unsigned Index,
4589+
CXString *Constraint,
4590+
CXCursor *Expr);
4591+
4592+
/**
4593+
* Given a CXCursor_GCCAsmStmt cursor, count the clobbers in it.
4594+
* This function also returns 0 if the cursor does not point at a GCC inline
4595+
* assembly block.
4596+
*/
4597+
4598+
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumClobbers(CXCursor Cursor);
4599+
4600+
/**
4601+
* Given a CXCursor_GCCAsmStmt cursor, get the Index-th clobber of it.
4602+
* This function returns a valid empty string if the cursor does not point
4603+
* at a GCC inline assembly block or `Index` is out of bounds.
4604+
*
4605+
* Users are responsible for releasing the allocation of returned string via
4606+
* \c clang_disposeString.
4607+
*/
4608+
4609+
CINDEX_LINKAGE CXString clang_Cursor_getGCCAssemblyClobber(CXCursor Cursor,
4610+
unsigned Index);
4611+
4612+
/**
4613+
* Given a CXCursor_GCCAsmStmt cursor, check if the inline assembly is
4614+
* `volatile`.
4615+
* This function returns 0 if the cursor does not point at a GCC inline
4616+
* assembly block.
4617+
*/
4618+
4619+
CINDEX_LINKAGE unsigned clang_Cursor_isGCCAssemblyVolatile(CXCursor Cursor);
4620+
44984621
/**
44994622
* @}
45004623
*/

clang/include/clang/Analysis/FlowSensitive/StorageLocation.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ class RecordStorageLocation final : public StorageLocation {
168168
return {Children.begin(), Children.end()};
169169
}
170170

171-
bool hasChild(const ValueDecl &D) const { return Children.contains(&D); }
172-
173171
private:
174172
FieldToLoc Children;
175173
SyntheticFieldMap SyntheticFields;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,7 @@ def note_unsatisfied_trait
17681768
"%TriviallyRelocatable{trivially relocatable}|"
17691769
"%Replaceable{replaceable}|"
17701770
"%TriviallyCopyable{trivially copyable}|"
1771+
"%Empty{empty}|"
17711772
"%StandardLayout{standard-layout}"
17721773
"}1">;
17731774

@@ -1788,6 +1789,10 @@ def note_unsatisfied_trait_reason
17881789
"%NonReplaceableField{has a non-replaceable member %1 of type %2}|"
17891790
"%NTCBase{has a non-trivially-copyable base %1}|"
17901791
"%NTCField{has a non-trivially-copyable member %1 of type %2}|"
1792+
"%NonEmptyMember{has a non-static data member %1 of type %2}|"
1793+
"%VirtualFunction{has a virtual function %1}|"
1794+
"%NonEmptyBase{has a base class %1 that is not empty}|"
1795+
"%NonZeroLengthField{field %1 is a non-zero-length bit-field}|"
17911796
"%NonStandardLayoutBase{has a non-standard-layout base %1}|"
17921797
"%MixedAccess{has mixed access specifiers}|"
17931798
"%MixedAccessField{field %1 has a different access specifier than field %2}|"

clang/include/clang/Serialization/ASTReader.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,6 @@ class ASTReader
464464
using ModuleReverseIterator = ModuleManager::ModuleReverseIterator;
465465

466466
private:
467-
using LocSeq = SourceLocationSequence;
468-
469467
/// The receiver of some callbacks invoked by ASTReader.
470468
std::unique_ptr<ASTReaderListener> Listener;
471469

@@ -2445,18 +2443,16 @@ class ASTReader
24452443
/// Read a source location from raw form and return it in its
24462444
/// originating module file's source location space.
24472445
std::pair<SourceLocation, unsigned>
2448-
ReadUntranslatedSourceLocation(RawLocEncoding Raw,
2449-
LocSeq *Seq = nullptr) const {
2450-
return SourceLocationEncoding::decode(Raw, Seq);
2446+
ReadUntranslatedSourceLocation(RawLocEncoding Raw) const {
2447+
return SourceLocationEncoding::decode(Raw);
24512448
}
24522449

24532450
/// Read a source location from raw form.
2454-
SourceLocation ReadSourceLocation(ModuleFile &MF, RawLocEncoding Raw,
2455-
LocSeq *Seq = nullptr) const {
2451+
SourceLocation ReadSourceLocation(ModuleFile &MF, RawLocEncoding Raw) const {
24562452
if (!MF.ModuleOffsetMap.empty())
24572453
ReadModuleOffsetMap(MF);
24582454

2459-
auto [Loc, ModuleFileIndex] = ReadUntranslatedSourceLocation(Raw, Seq);
2455+
auto [Loc, ModuleFileIndex] = ReadUntranslatedSourceLocation(Raw);
24602456
ModuleFile *OwningModuleFile =
24612457
ModuleFileIndex == 0 ? &MF : MF.TransitiveImports[ModuleFileIndex - 1];
24622458

@@ -2484,9 +2480,9 @@ class ASTReader
24842480

24852481
/// Read a source location.
24862482
SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
2487-
const RecordDataImpl &Record, unsigned &Idx,
2488-
LocSeq *Seq = nullptr) {
2489-
return ReadSourceLocation(ModuleFile, Record[Idx++], Seq);
2483+
const RecordDataImpl &Record,
2484+
unsigned &Idx) {
2485+
return ReadSourceLocation(ModuleFile, Record[Idx++]);
24902486
}
24912487

24922488
/// Read a FileID.
@@ -2505,7 +2501,7 @@ class ASTReader
25052501

25062502
/// Read a source range.
25072503
SourceRange ReadSourceRange(ModuleFile &F, const RecordData &Record,
2508-
unsigned &Idx, LocSeq *Seq = nullptr);
2504+
unsigned &Idx);
25092505

25102506
static llvm::BitVector ReadBitVector(const RecordData &Record,
25112507
const StringRef Blob);

clang/include/clang/Serialization/ASTRecordReader.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class OMPChildren;
3232
class ASTRecordReader
3333
: public serialization::DataStreamBasicReader<ASTRecordReader> {
3434
using ModuleFile = serialization::ModuleFile;
35-
using LocSeq = SourceLocationSequence;
3635

3736
ASTReader *Reader;
3837
ModuleFile *F;
@@ -160,7 +159,7 @@ class ASTRecordReader
160159
TypeSourceInfo *readTypeSourceInfo();
161160

162161
/// Reads the location information for a type.
163-
void readTypeLoc(TypeLoc TL, LocSeq *Seq = nullptr);
162+
void readTypeLoc(TypeLoc TL);
164163

165164
/// Map a local type ID within a given AST file to a global type ID.
166165
serialization::TypeID getGlobalTypeID(serialization::TypeID LocalID) const {
@@ -287,13 +286,13 @@ class ASTRecordReader
287286
void readOpenACCRoutineDeclAttr(OpenACCRoutineDeclAttr *A);
288287

289288
/// Read a source location, advancing Idx.
290-
SourceLocation readSourceLocation(LocSeq *Seq = nullptr) {
291-
return Reader->ReadSourceLocation(*F, Record, Idx, Seq);
289+
SourceLocation readSourceLocation() {
290+
return Reader->ReadSourceLocation(*F, Record, Idx);
292291
}
293292

294293
/// Read a source range, advancing Idx.
295-
SourceRange readSourceRange(LocSeq *Seq = nullptr) {
296-
return Reader->ReadSourceRange(*F, Record, Idx, Seq);
294+
SourceRange readSourceRange() {
295+
return Reader->ReadSourceRange(*F, Record, Idx);
297296
}
298297

299298
/// Read an arbitrary constant value, advancing Idx.

clang/include/clang/Serialization/ASTRecordWriter.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class TypeLoc;
2929
/// An object for streaming information to a record.
3030
class ASTRecordWriter
3131
: public serialization::DataStreamBasicWriter<ASTRecordWriter> {
32-
using LocSeq = SourceLocationSequence;
3332

3433
ASTWriter *Writer;
3534
ASTWriter::RecordDataImpl *Record;
@@ -147,8 +146,8 @@ class ASTRecordWriter
147146
void AddFunctionDefinition(const FunctionDecl *FD);
148147

149148
/// Emit a source location.
150-
void AddSourceLocation(SourceLocation Loc, LocSeq *Seq = nullptr) {
151-
return Writer->AddSourceLocation(Loc, *Record, Seq);
149+
void AddSourceLocation(SourceLocation Loc) {
150+
return Writer->AddSourceLocation(Loc, *Record);
152151
}
153152
void writeSourceLocation(SourceLocation Loc) {
154153
AddSourceLocation(Loc);
@@ -174,8 +173,8 @@ class ASTRecordWriter
174173
}
175174

176175
/// Emit a source range.
177-
void AddSourceRange(SourceRange Range, LocSeq *Seq = nullptr) {
178-
return Writer->AddSourceRange(Range, *Record, Seq);
176+
void AddSourceRange(SourceRange Range) {
177+
return Writer->AddSourceRange(Range, *Record);
179178
}
180179

181180
void writeBool(bool Value) {
@@ -245,7 +244,7 @@ class ASTRecordWriter
245244
void AddTypeSourceInfo(TypeSourceInfo *TInfo);
246245

247246
/// Emits source location information for a type. Does not emit the type.
248-
void AddTypeLoc(TypeLoc TL, LocSeq *Seq = nullptr);
247+
void AddTypeLoc(TypeLoc TL);
249248

250249
/// Emits a template argument location info.
251250
void AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind,

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ class ASTWriter : public ASTDeserializationListener,
115115
using TypeIdxMap = llvm::DenseMap<QualType, serialization::TypeIdx,
116116
serialization::UnsafeQualTypeDenseMapInfo>;
117117

118-
using LocSeq = SourceLocationSequence;
119-
120118
/// The bitstream writer used to emit this precompiled header.
121119
llvm::BitstreamWriter &Stream;
122120

@@ -733,16 +731,14 @@ class ASTWriter : public ASTDeserializationListener,
733731
void AddFileID(FileID FID, RecordDataImpl &Record);
734732

735733
/// Emit a source location.
736-
void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record,
737-
LocSeq *Seq = nullptr);
734+
void AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record);
738735

739736
/// Return the raw encodings for source locations.
740737
SourceLocationEncoding::RawLocEncoding
741-
getRawSourceLocationEncoding(SourceLocation Loc, LocSeq *Seq = nullptr);
738+
getRawSourceLocationEncoding(SourceLocation Loc);
742739

743740
/// Emit a source range.
744-
void AddSourceRange(SourceRange Range, RecordDataImpl &Record,
745-
LocSeq *Seq = nullptr);
741+
void AddSourceRange(SourceRange Range, RecordDataImpl &Record);
746742

747743
/// Emit a reference to an identifier.
748744
void AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record);

0 commit comments

Comments
 (0)