Skip to content

Commit 69bd3d5

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:34929853bc39 into amd-gfx:b0d0d197e7c8
Local branch amd-gfx b0d0d19 Merged main:acebaa01623b into amd-gfx:58cb02d5f29e Remote branch main 3492985 Fix `llvm/test/DebugInfo/Generic/discriminated-union.ll` on big-endian targets (llvm#125849)
2 parents b0d0d19 + 3492985 commit 69bd3d5

File tree

180 files changed

+4418
-3345
lines changed

Some content is hidden

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

180 files changed

+4418
-3345
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ Bug Fixes to Attribute Support
145145
Bug Fixes to C++ Support
146146
^^^^^^^^^^^^^^^^^^^^^^^^
147147

148+
- Clang is now better at keeping track of friend function template instance contexts. (#GH55509)
149+
148150
Bug Fixes to AST Handling
149151
^^^^^^^^^^^^^^^^^^^^^^^^^
150152

clang/docs/analyzer/developer-docs.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ Contents:
1111
developer-docs/InitializerLists
1212
developer-docs/nullability
1313
developer-docs/RegionStore
14+
developer-docs/PerformanceInvestigation
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
=========================
2+
Performance Investigation
3+
=========================
4+
5+
Multiple factors contribute to the time it takes to analyze a file with Clang Static Analyzer.
6+
A translation unit contains multiple entry points, each of which take multiple steps to analyze.
7+
8+
You can add the ``-ftime-trace=file.json`` option to break down the analysis time into individual entry points and steps within each entry point.
9+
You can explore the generated JSON file in a Chromium browser using the ``chrome://tracing`` URL,
10+
or using `speedscope <https://speedscope.app>`_.
11+
Once you narrow down to specific analysis steps you are interested in, you can more effectively employ heavier profilers,
12+
such as `Perf <https://perfwiki.github.io/main/>`_ and `Callgrind <https://valgrind.org/docs/manual/cl-manual.html>`_.
13+
14+
Each analysis step has a time scope in the trace, corresponds to processing of an exploded node, and is designated with a ``ProgramPoint``.
15+
If the ``ProgramPoint`` is associated with a location, you can see it on the scope metadata label.
16+
17+
Here is an example of a time trace produced with
18+
19+
.. code-block:: bash
20+
:caption: Clang Static Analyzer invocation to generate a time trace of string.c analysis.
21+
22+
clang -cc1 -nostdsysteminc -analyze -analyzer-constraints=range \
23+
-setup-static-analyzer -analyzer-checker=core,unix,alpha.unix.cstring,debug.ExprInspection \
24+
-verify ./clang/test/Analysis/string.c \
25+
-ftime-trace=trace.json -ftime-trace-granularity=1
26+
27+
.. image:: ../images/speedscope.png
28+
29+
On the speedscope screenshot above, under the first time ruler is the bird's-eye view of the entire trace that spans a little over 60 milliseconds.
30+
Under the second ruler (focused on the 18.09-18.13ms time point) you can see a narrowed-down portion.
31+
The second box ("HandleCode memset...") that spans entire screen (and actually extends beyond it) corresponds to the analysis of ``memset16_region_cast()`` entry point that is defined in the "string.c" test file on line 1627.
32+
Below it, you can find multiple sub-scopes each corresponding to processing of a single exploded node.
33+
34+
- First: a ``PostStmt`` for some statement on line 1634. This scope has a selected subscope "CheckerManager::runCheckersForCallEvent (Pre)" that takes 5 microseconds.
35+
- Four other nodes, too small to be discernible at this zoom level
36+
- Last on this screenshot: another ``PostStmt`` for a statement on line 1635.
37+
38+
In addition to the ``-ftime-trace`` option, you can use ``-ftime-trace-granularity`` to fine-tune the time trace.
39+
40+
- ``-ftime-trace-granularity=NN`` dumps only time scopes that are longer than NN microseconds.
41+
- ``-ftime-trace-verbose`` enables some additional dumps in the frontend related to template instantiations.
42+
At the moment, it has no effect on the traces from the static analyzer.
43+
44+
Note: Both Chrome-tracing and speedscope tools might struggle with time traces above 100 MB in size.
45+
Luckily, in most cases the default max-steps boundary of 225 000 produces the traces of approximately that size
46+
for a single entry point.
47+
You can use ``-analyze-function=get_global_options`` together with ``-ftime-trace`` to narrow down analysis to a specific entry point.
53.5 KB
Loading

clang/include/clang/AST/Decl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,6 +2298,13 @@ class FunctionDecl : public DeclaratorDecl,
22982298
FunctionDeclBits.IsLateTemplateParsed = ILT;
22992299
}
23002300

2301+
bool isInstantiatedFromMemberTemplate() const {
2302+
return FunctionDeclBits.IsInstantiatedFromMemberTemplate;
2303+
}
2304+
void setInstantiatedFromMemberTemplate(bool Val = true) {
2305+
FunctionDeclBits.IsInstantiatedFromMemberTemplate = Val;
2306+
}
2307+
23012308
/// Whether this function is "trivial" in some specialized C++ senses.
23022309
/// Can only be true for default constructors, copy constructors,
23032310
/// copy assignment operators, and destructors. Not meaningful until

clang/include/clang/AST/DeclBase.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,8 @@ class DeclContext {
17801780
uint64_t HasImplicitReturnZero : 1;
17811781
LLVM_PREFERRED_TYPE(bool)
17821782
uint64_t IsLateTemplateParsed : 1;
1783+
LLVM_PREFERRED_TYPE(bool)
1784+
uint64_t IsInstantiatedFromMemberTemplate : 1;
17831785

17841786
/// Kind of contexpr specifier as defined by ConstexprSpecKind.
17851787
LLVM_PREFERRED_TYPE(ConstexprSpecKind)
@@ -1830,7 +1832,7 @@ class DeclContext {
18301832
};
18311833

18321834
/// Number of inherited and non-inherited bits in FunctionDeclBitfields.
1833-
enum { NumFunctionDeclBits = NumDeclContextBits + 31 };
1835+
enum { NumFunctionDeclBits = NumDeclContextBits + 32 };
18341836

18351837
/// Stores the bits used by CXXConstructorDecl. If modified
18361838
/// NumCXXConstructorDeclBits and the accessor
@@ -1841,12 +1843,12 @@ class DeclContext {
18411843
LLVM_PREFERRED_TYPE(FunctionDeclBitfields)
18421844
uint64_t : NumFunctionDeclBits;
18431845

1844-
/// 20 bits to fit in the remaining available space.
1846+
/// 19 bits to fit in the remaining available space.
18451847
/// Note that this makes CXXConstructorDeclBitfields take
18461848
/// exactly 64 bits and thus the width of NumCtorInitializers
18471849
/// will need to be shrunk if some bit is added to NumDeclContextBitfields,
18481850
/// NumFunctionDeclBitfields or CXXConstructorDeclBitfields.
1849-
uint64_t NumCtorInitializers : 17;
1851+
uint64_t NumCtorInitializers : 16;
18501852
LLVM_PREFERRED_TYPE(bool)
18511853
uint64_t IsInheritingConstructor : 1;
18521854

@@ -1860,7 +1862,7 @@ class DeclContext {
18601862
};
18611863

18621864
/// Number of inherited and non-inherited bits in CXXConstructorDeclBitfields.
1863-
enum { NumCXXConstructorDeclBits = NumFunctionDeclBits + 20 };
1865+
enum { NumCXXConstructorDeclBits = NumFunctionDeclBits + 19 };
18641866

18651867
/// Stores the bits used by ObjCMethodDecl.
18661868
/// If modified NumObjCMethodDeclBits and the accessor

clang/include/clang/AST/DeclTemplate.h

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,26 @@ class FunctionTemplateDecl : public RedeclarableTemplateDecl {
10111011
return getTemplatedDecl()->isThisDeclarationADefinition();
10121012
}
10131013

1014+
bool isCompatibleWithDefinition() const {
1015+
return getTemplatedDecl()->isInstantiatedFromMemberTemplate() ||
1016+
isThisDeclarationADefinition();
1017+
}
1018+
1019+
// This bit closely tracks 'RedeclarableTemplateDecl::InstantiatedFromMember',
1020+
// except this is per declaration, while the redeclarable field is
1021+
// per chain. This indicates a template redeclaration which
1022+
// is compatible with the definition, in the non-trivial case
1023+
// where this is not already a definition.
1024+
// This is only really needed for instantiating the definition of friend
1025+
// function templates, which can have redeclarations in different template
1026+
// contexts.
1027+
// The bit is actually stored in the FunctionDecl for space efficiency
1028+
// reasons.
1029+
void setInstantiatedFromMemberTemplate(FunctionTemplateDecl *D) {
1030+
getTemplatedDecl()->setInstantiatedFromMemberTemplate();
1031+
RedeclarableTemplateDecl::setInstantiatedFromMemberTemplate(D);
1032+
}
1033+
10141034
/// Return the specialization with the provided arguments if it exists,
10151035
/// otherwise return the insertion point.
10161036
FunctionDecl *findSpecialization(ArrayRef<TemplateArgument> Args,
@@ -1842,19 +1862,19 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
18421862
unsigned SpecializationKind : 3;
18431863

18441864
/// Indicate that we have matched a parameter pack with a non pack
1845-
/// argument, when the opposite match is also allowed (strict pack match).
1865+
/// argument, when the opposite match is also allowed.
18461866
/// This needs to be cached as deduction is performed during declaration,
18471867
/// and we need the information to be preserved so that it is consistent
18481868
/// during instantiation.
1849-
bool MatchedPackOnParmToNonPackOnArg : 1;
1869+
bool StrictPackMatch : 1;
18501870

18511871
protected:
18521872
ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK,
18531873
DeclContext *DC, SourceLocation StartLoc,
18541874
SourceLocation IdLoc,
18551875
ClassTemplateDecl *SpecializedTemplate,
18561876
ArrayRef<TemplateArgument> Args,
1857-
bool MatchedPackOnParmToNonPackOnArg,
1877+
bool StrictPackMatch,
18581878
ClassTemplateSpecializationDecl *PrevDecl);
18591879

18601880
ClassTemplateSpecializationDecl(ASTContext &C, Kind DK);
@@ -1867,7 +1887,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
18671887
Create(ASTContext &Context, TagKind TK, DeclContext *DC,
18681888
SourceLocation StartLoc, SourceLocation IdLoc,
18691889
ClassTemplateDecl *SpecializedTemplate,
1870-
ArrayRef<TemplateArgument> Args, bool MatchedPackOnParmToNonPackOnArg,
1890+
ArrayRef<TemplateArgument> Args, bool StrictPackMatch,
18711891
ClassTemplateSpecializationDecl *PrevDecl);
18721892
static ClassTemplateSpecializationDecl *CreateDeserialized(ASTContext &C,
18731893
GlobalDeclID ID);
@@ -1938,9 +1958,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
19381958
SpecializationKind = TSK;
19391959
}
19401960

1941-
bool hasMatchedPackOnParmToNonPackOnArg() const {
1942-
return MatchedPackOnParmToNonPackOnArg;
1943-
}
1961+
bool hasStrictPackMatch() const { return StrictPackMatch; }
19441962

19451963
/// Get the point of instantiation (if any), or null if none.
19461964
SourceLocation getPointOfInstantiation() const {

clang/include/clang/Analysis/ProgramPoint.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class ProgramPoint {
8585
LoopExitKind,
8686
EpsilonKind};
8787

88+
static StringRef getProgramPointKindName(Kind K);
89+
std::optional<SourceLocation> getSourceLocation() const;
90+
8891
private:
8992
const void *Data1;
9093
llvm::PointerIntPair<const void *, 2, unsigned> Data2;

clang/include/clang/Sema/Overload.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ class Sema;
933933
/// Have we matched any packs on the parameter side, versus any non-packs on
934934
/// the argument side, in a context where the opposite matching is also
935935
/// allowed?
936-
bool HasMatchedPackOnParmToNonPackOnArg : 1;
936+
bool StrictPackMatch : 1;
937937

938938
/// True if the candidate was found using ADL.
939939
LLVM_PREFERRED_TYPE(CallExpr::ADLCallKind)
@@ -1010,8 +1010,7 @@ class Sema;
10101010
friend class OverloadCandidateSet;
10111011
OverloadCandidate()
10121012
: IsSurrogate(false), IgnoreObjectArgument(false),
1013-
TookAddressOfOverload(false),
1014-
HasMatchedPackOnParmToNonPackOnArg(false),
1013+
TookAddressOfOverload(false), StrictPackMatch(false),
10151014
IsADLCandidate(llvm::to_underlying(CallExpr::NotADL)),
10161015
RewriteKind(CRK_None) {}
10171016
};

clang/include/clang/Sema/Sema.h

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10180,18 +10180,15 @@ class Sema final : public SemaBase {
1018010180
/// \param PartialOverloading true if we are performing "partial" overloading
1018110181
/// based on an incomplete set of function arguments. This feature is used by
1018210182
/// code completion.
10183-
void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl,
10184-
ArrayRef<Expr *> Args,
10185-
OverloadCandidateSet &CandidateSet,
10186-
bool SuppressUserConversions = false,
10187-
bool PartialOverloading = false,
10188-
bool AllowExplicit = true,
10189-
bool AllowExplicitConversion = false,
10190-
ADLCallKind IsADLCandidate = ADLCallKind::NotADL,
10191-
ConversionSequenceList EarlyConversions = {},
10192-
OverloadCandidateParamOrder PO = {},
10193-
bool AggregateCandidateDeduction = false,
10194-
bool HasMatchedPackOnParmToNonPackOnArg = false);
10183+
void AddOverloadCandidate(
10184+
FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef<Expr *> Args,
10185+
OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false,
10186+
bool PartialOverloading = false, bool AllowExplicit = true,
10187+
bool AllowExplicitConversion = false,
10188+
ADLCallKind IsADLCandidate = ADLCallKind::NotADL,
10189+
ConversionSequenceList EarlyConversions = {},
10190+
OverloadCandidateParamOrder PO = {},
10191+
bool AggregateCandidateDeduction = false, bool StrictPackMatch = false);
1019510192

1019610193
/// Add all of the function declarations in the given function set to
1019710194
/// the overload candidate set.
@@ -10227,7 +10224,7 @@ class Sema final : public SemaBase {
1022710224
bool PartialOverloading = false,
1022810225
ConversionSequenceList EarlyConversions = {},
1022910226
OverloadCandidateParamOrder PO = {},
10230-
bool HasMatchedPackOnParmToNonPackOnArg = false);
10227+
bool StrictPackMatch = false);
1023110228

1023210229
/// Add a C++ member function template as a candidate to the candidate
1023310230
/// set, using template argument deduction to produce an appropriate member
@@ -10274,7 +10271,7 @@ class Sema final : public SemaBase {
1027410271
CXXRecordDecl *ActingContext, Expr *From, QualType ToType,
1027510272
OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit,
1027610273
bool AllowExplicit, bool AllowResultConversion = true,
10277-
bool HasMatchedPackOnParmToNonPackOnArg = false);
10274+
bool StrictPackMatch = false);
1027810275

1027910276
/// Adds a conversion function template specialization
1028010277
/// candidate to the overload set, using template argument deduction
@@ -11694,7 +11691,7 @@ class Sema final : public SemaBase {
1169411691

1169511692
/// Is set to true when, in the context of TTP matching, a pack parameter
1169611693
/// matches non-pack arguments.
11697-
bool MatchedPackOnParmToNonPackOnArg = false;
11694+
bool StrictPackMatch = false;
1169811695
};
1169911696

1170011697
/// Check that the given template argument corresponds to the given
@@ -11803,7 +11800,7 @@ class Sema final : public SemaBase {
1180311800
TemplateParameterList *Params,
1180411801
TemplateArgumentLoc &Arg,
1180511802
bool PartialOrdering,
11806-
bool *MatchedPackOnParmToNonPackOnArg);
11803+
bool *StrictPackMatch);
1180711804

1180811805
void NoteTemplateLocation(const NamedDecl &Decl,
1180911806
std::optional<SourceRange> ParamRange = {});
@@ -12497,7 +12494,7 @@ class Sema final : public SemaBase {
1249712494
bool isTemplateTemplateParameterAtLeastAsSpecializedAs(
1249812495
TemplateParameterList *PParam, TemplateDecl *PArg, TemplateDecl *AArg,
1249912496
const DefaultArguments &DefaultArgs, SourceLocation ArgLoc,
12500-
bool PartialOrdering, bool *MatchedPackOnParmToNonPackOnArg);
12497+
bool PartialOrdering, bool *StrictPackMatch);
1250112498

1250212499
/// Mark which template parameters are used in a given expression.
1250312500
///
@@ -13500,7 +13497,7 @@ class Sema final : public SemaBase {
1350013497
SourceLocation PointOfInstantiation,
1350113498
ClassTemplateSpecializationDecl *ClassTemplateSpec,
1350213499
TemplateSpecializationKind TSK, bool Complain,
13503-
bool PrimaryHasMatchedPackOnParmToNonPackOnArg);
13500+
bool PrimaryStrictPackMatch);
1350413501

1350513502
/// Instantiates the definitions of all of the member
1350613503
/// of the given class, which is an instantiation of a class template

clang/include/clang/Sema/TemplateDeduction.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class TemplateDeductionInfo {
5454
/// Have we matched any packs on the parameter side, versus any non-packs on
5555
/// the argument side, in a context where the opposite matching is also
5656
/// allowed?
57-
bool MatchedPackOnParmToNonPackOnArg = false;
57+
bool StrictPackMatch = false;
5858

5959
/// The template parameter depth for which we're performing deduction.
6060
unsigned DeducedDepth;
@@ -92,13 +92,9 @@ class TemplateDeductionInfo {
9292
return DeducedDepth;
9393
}
9494

95-
bool hasMatchedPackOnParmToNonPackOnArg() const {
96-
return MatchedPackOnParmToNonPackOnArg;
97-
}
95+
bool hasStrictPackMatch() const { return StrictPackMatch; }
9896

99-
void setMatchedPackOnParmToNonPackOnArg() {
100-
MatchedPackOnParmToNonPackOnArg = true;
101-
}
97+
void setStrictPackMatch() { StrictPackMatch = true; }
10298

10399
/// Get the number of explicitly-specified arguments.
104100
unsigned getNumExplicitArgs() const {

clang/lib/AST/ASTImporter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6320,10 +6320,10 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl(
63206320

63216321
updateLookupTableForTemplateParameters(*ToTPList);
63226322
} else { // Not a partial specialization.
6323-
if (GetImportedOrCreateDecl(
6324-
D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6325-
*IdLocOrErr, ClassTemplate, TemplateArgs,
6326-
D->hasMatchedPackOnParmToNonPackOnArg(), PrevDecl))
6323+
if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
6324+
DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
6325+
TemplateArgs, D->hasStrictPackMatch(),
6326+
PrevDecl))
63276327
return D2;
63286328

63296329
// Update InsertPos, because preceding import calls may have invalidated

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5604,6 +5604,22 @@ bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) {
56045604

56055605
if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr))
56065606
return false;
5607+
5608+
// Mark all chain links as initialized.
5609+
unsigned InitFieldOffset = 0;
5610+
for (const NamedDecl *ND : IFD->chain().drop_back()) {
5611+
const auto *FD = cast<FieldDecl>(ND);
5612+
const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent());
5613+
assert(FieldRecord);
5614+
NestedField = FieldRecord->getField(FD);
5615+
InitFieldOffset += NestedField->Offset;
5616+
assert(NestedField);
5617+
if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr))
5618+
return false;
5619+
if (!this->emitFinishInitPop(InitExpr))
5620+
return false;
5621+
}
5622+
56075623
} else {
56085624
assert(Init->isDelegatingInitializer());
56095625
if (!this->emitThis(InitExpr))

clang/lib/AST/Decl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3065,6 +3065,7 @@ FunctionDecl::FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC,
30653065
FunctionDeclBits.IsIneligibleOrNotSelected = false;
30663066
FunctionDeclBits.HasImplicitReturnZero = false;
30673067
FunctionDeclBits.IsLateTemplateParsed = false;
3068+
FunctionDeclBits.IsInstantiatedFromMemberTemplate = false;
30683069
FunctionDeclBits.ConstexprKind = static_cast<uint64_t>(ConstexprKind);
30693070
FunctionDeclBits.BodyContainsImmediateEscalatingExpression = false;
30703071
FunctionDeclBits.InstantiationIsPending = false;

0 commit comments

Comments
 (0)