Skip to content

Commit 8294793

Browse files
committed
Merged main:67f0277cc3ae into amd-gfx:2e95c33542fb
Local branch amd-gfx 2e95c33 Merged main:e45fc5140df7bb60242a989ac7fc5cd0c0563234 into amd-gfx:ba271becfbe2 Remote branch main 67f0277 [ELF] Replace config-> with ctx.arg. in Writer Change-Id: I8f55ca8966ddf875cee03df1384ed6ba48965eaa
2 parents 2e95c33 + 67f0277 commit 8294793

File tree

79 files changed

+3665
-2259
lines changed

Some content is hidden

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

79 files changed

+3665
-2259
lines changed

clang-tools-extra/modularize/Modularize.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,10 @@ class EntityMap : public std::map<std::string, SmallVector<Entry, 2>> {
508508
// Sort contents.
509509
llvm::sort(H->second);
510510

511-
// Check whether we've seen this header before.
512-
auto KnownH = AllHeaderContents.find(H->first);
513-
if (KnownH == AllHeaderContents.end()) {
514-
// We haven't seen this header before; record its contents.
515-
AllHeaderContents.insert(*H);
511+
// Record this header and its contents if we haven't seen it before.
512+
auto [KnownH, Inserted] = AllHeaderContents.insert(*H);
513+
if (Inserted)
516514
continue;
517-
}
518515

519516
// If the header contents are the same, we're done.
520517
if (H->second == KnownH->second)

clang/CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
899899
-instrument --instrumentation-file-append-pid
900900
--instrumentation-file=${BOLT_FDATA}
901901
COMMENT "Instrumenting clang binary with BOLT"
902+
USES_TERMINAL
902903
VERBATIM
903904
)
904905
add_custom_target(clang-bolt-training-deps DEPENDS clang-instrumented)
@@ -907,20 +908,19 @@ if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
907908
endif()
908909

909910
# Optimize original (pre-bolt) Clang using the collected profile
910-
set(CLANG_OPTIMIZED ${CMAKE_CURRENT_BINARY_DIR}/clang.bolt)
911911
add_custom_target(clang-bolt
912-
DEPENDS ${CLANG_OPTIMIZED}
913-
)
914-
add_custom_command(OUTPUT ${CLANG_OPTIMIZED}
915912
DEPENDS clang-bolt-profile
916-
COMMAND llvm-bolt ${CLANG_PATH}
917-
-o ${CLANG_OPTIMIZED}
913+
COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_FILE:clang> ${CLANG_PATH}-prebolt
914+
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CLANG_PATH}-prebolt ${CLANG_PATH}++-prebolt
915+
COMMAND llvm-bolt ${CLANG_PATH}-prebolt
916+
-o $<TARGET_FILE:clang>
918917
-data ${BOLT_FDATA}
919-
-reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions
920-
-split-all-cold -split-eh -dyno-stats -icf=1 -use-gnu-stack
918+
-reorder-blocks=ext-tsp -reorder-functions=cdsort -split-functions
919+
-split-all-cold -split-eh -dyno-stats -use-gnu-stack
920+
-split-strategy=cdsplit -update-debug-sections
921921
${BOLT_NO_LBR}
922-
COMMAND ${CMAKE_COMMAND} -E rename ${CLANG_OPTIMIZED} $<TARGET_FILE:clang>
923922
COMMENT "Optimizing Clang with BOLT"
923+
USES_TERMINAL
924924
VERBATIM
925925
)
926926
endif()

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,6 @@ Bug Fixes to C++ Support
409409
- Fixed an assertion failure in debug mode, and potential crashes in release mode, when
410410
diagnosing a failed cast caused indirectly by a failed implicit conversion to the type of the constructor parameter.
411411
- Fixed an assertion failure by adjusting integral to boolean vector conversions (#GH108326)
412-
- Clang now uses the correct set of template argument lists when comparing the constraints of
413-
out-of-line definitions and member templates explicitly specialized for a given implicit instantiation of
414-
a class template. (#GH102320)
415412

416413
Bug Fixes to AST Handling
417414
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/DeclTemplate.h

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
781781
EntryType *Entry, void *InsertPos);
782782

783783
struct CommonBase {
784-
CommonBase() {}
784+
CommonBase() : InstantiatedFromMember(nullptr, false) {}
785785

786786
/// The template from which this was most
787787
/// directly instantiated (or null).
788-
RedeclarableTemplateDecl *InstantiatedFromMember = nullptr;
788+
///
789+
/// The boolean value indicates whether this template
790+
/// was explicitly specialized.
791+
llvm::PointerIntPair<RedeclarableTemplateDecl*, 1, bool>
792+
InstantiatedFromMember;
789793

790794
/// If non-null, points to an array of specializations (including
791795
/// partial specializations) known only by their external declaration IDs.
@@ -805,19 +809,14 @@ class RedeclarableTemplateDecl : public TemplateDecl,
805809
};
806810

807811
/// Pointer to the common data shared by all declarations of this
808-
/// template, and a flag indicating if the template is a member
809-
/// specialization.
810-
mutable llvm::PointerIntPair<CommonBase *, 1, bool> Common;
811-
812-
CommonBase *getCommonPtrInternal() const { return Common.getPointer(); }
812+
/// template.
813+
mutable CommonBase *Common = nullptr;
813814

814815
/// Retrieves the "common" pointer shared by all (re-)declarations of
815816
/// the same template. Calling this routine may implicitly allocate memory
816817
/// for the common pointer.
817818
CommonBase *getCommonPtr() const;
818819

819-
void setCommonPtr(CommonBase *C) const { Common.setPointer(C); }
820-
821820
virtual CommonBase *newCommon(ASTContext &C) const = 0;
822821

823822
// Construct a template decl with name, parameters, and templated element.
@@ -858,12 +857,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
858857
/// template<> template<typename T>
859858
/// struct X<int>::Inner { /* ... */ };
860859
/// \endcode
861-
bool isMemberSpecialization() const { return Common.getInt(); }
860+
bool isMemberSpecialization() const {
861+
return getCommonPtr()->InstantiatedFromMember.getInt();
862+
}
862863

863864
/// Note that this member template is a specialization.
864865
void setMemberSpecialization() {
865-
assert(!isMemberSpecialization() && "already a member specialization");
866-
Common.setInt(true);
866+
assert(getCommonPtr()->InstantiatedFromMember.getPointer() &&
867+
"Only member templates can be member template specializations");
868+
getCommonPtr()->InstantiatedFromMember.setInt(true);
867869
}
868870

869871
/// Retrieve the member template from which this template was
@@ -903,12 +905,12 @@ class RedeclarableTemplateDecl : public TemplateDecl,
903905
/// void X<T>::f(T, U);
904906
/// \endcode
905907
RedeclarableTemplateDecl *getInstantiatedFromMemberTemplate() const {
906-
return getCommonPtr()->InstantiatedFromMember;
908+
return getCommonPtr()->InstantiatedFromMember.getPointer();
907909
}
908910

909911
void setInstantiatedFromMemberTemplate(RedeclarableTemplateDecl *TD) {
910-
assert(!getCommonPtr()->InstantiatedFromMember);
911-
getCommonPtr()->InstantiatedFromMember = TD;
912+
assert(!getCommonPtr()->InstantiatedFromMember.getPointer());
913+
getCommonPtr()->InstantiatedFromMember.setPointer(TD);
912914
}
913915

914916
/// Retrieve the "injected" template arguments that correspond to the
@@ -1987,8 +1989,6 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
19871989
/// template arguments have been deduced.
19881990
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec,
19891991
const TemplateArgumentList *TemplateArgs) {
1990-
assert(!isa<ClassTemplatePartialSpecializationDecl>(this) &&
1991-
"A partial specialization cannot be instantiated from a template");
19921992
assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() &&
19931993
"Already set to a class template partial specialization!");
19941994
auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
@@ -2000,8 +2000,6 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
20002000
/// Note that this class template specialization is an instantiation
20012001
/// of the given class template.
20022002
void setInstantiationOf(ClassTemplateDecl *TemplDecl) {
2003-
assert(!isa<ClassTemplatePartialSpecializationDecl>(this) &&
2004-
"A partial specialization cannot be instantiated from a template");
20052003
assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() &&
20062004
"Previously set to a class template partial specialization!");
20072005
SpecializedTemplate = TemplDecl;
@@ -2189,11 +2187,18 @@ class ClassTemplatePartialSpecializationDecl
21892187
/// struct X<int>::Inner<T*> { /* ... */ };
21902188
/// \endcode
21912189
bool isMemberSpecialization() const {
2192-
return InstantiatedFromMember.getInt();
2190+
const auto *First =
2191+
cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2192+
return First->InstantiatedFromMember.getInt();
21932193
}
21942194

21952195
/// Note that this member template is a specialization.
2196-
void setMemberSpecialization() { return InstantiatedFromMember.setInt(true); }
2196+
void setMemberSpecialization() {
2197+
auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2198+
assert(First->InstantiatedFromMember.getPointer() &&
2199+
"Only member templates can be member template specializations");
2200+
return First->InstantiatedFromMember.setInt(true);
2201+
}
21972202

21982203
/// Retrieves the injected specialization type for this partial
21992204
/// specialization. This is not the same as the type-decl-type for
@@ -2263,6 +2268,10 @@ class ClassTemplateDecl : public RedeclarableTemplateDecl {
22632268
return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
22642269
}
22652270

2271+
void setCommonPtr(Common *C) {
2272+
RedeclarableTemplateDecl::Common = C;
2273+
}
2274+
22662275
public:
22672276

22682277
friend class ASTDeclReader;
@@ -2745,8 +2754,6 @@ class VarTemplateSpecializationDecl : public VarDecl,
27452754
/// template arguments have been deduced.
27462755
void setInstantiationOf(VarTemplatePartialSpecializationDecl *PartialSpec,
27472756
const TemplateArgumentList *TemplateArgs) {
2748-
assert(!isa<VarTemplatePartialSpecializationDecl>(this) &&
2749-
"A partial specialization cannot be instantiated from a template");
27502757
assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() &&
27512758
"Already set to a variable template partial specialization!");
27522759
auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
@@ -2758,8 +2765,6 @@ class VarTemplateSpecializationDecl : public VarDecl,
27582765
/// Note that this variable template specialization is an instantiation
27592766
/// of the given variable template.
27602767
void setInstantiationOf(VarTemplateDecl *TemplDecl) {
2761-
assert(!isa<VarTemplatePartialSpecializationDecl>(this) &&
2762-
"A partial specialization cannot be instantiated from a template");
27632768
assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() &&
27642769
"Previously set to a variable template partial specialization!");
27652770
SpecializedTemplate = TemplDecl;
@@ -2944,11 +2949,18 @@ class VarTemplatePartialSpecializationDecl
29442949
/// U* X<int>::Inner<T*> = (T*)(0) + 1;
29452950
/// \endcode
29462951
bool isMemberSpecialization() const {
2947-
return InstantiatedFromMember.getInt();
2952+
const auto *First =
2953+
cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2954+
return First->InstantiatedFromMember.getInt();
29482955
}
29492956

29502957
/// Note that this member template is a specialization.
2951-
void setMemberSpecialization() { return InstantiatedFromMember.setInt(true); }
2958+
void setMemberSpecialization() {
2959+
auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2960+
assert(First->InstantiatedFromMember.getPointer() &&
2961+
"Only member templates can be member template specializations");
2962+
return First->InstantiatedFromMember.setInt(true);
2963+
}
29522964

29532965
SourceRange getSourceRange() const override LLVM_READONLY;
29542966

clang/include/clang/Sema/Sema.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11389,9 +11389,9 @@ class Sema final : public SemaBase {
1138911389
CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc,
1139011390
const ParsedAttributesView &Attr, TemplateParameterList *TemplateParams,
1139111391
AccessSpecifier AS, SourceLocation ModulePrivateLoc,
11392-
SourceLocation FriendLoc,
11393-
ArrayRef<TemplateParameterList *> OuterTemplateParamLists,
11394-
bool IsMemberSpecialization, SkipBodyInfo *SkipBody = nullptr);
11392+
SourceLocation FriendLoc, unsigned NumOuterTemplateParamLists,
11393+
TemplateParameterList **OuterTemplateParamLists,
11394+
SkipBodyInfo *SkipBody = nullptr);
1139511395

1139611396
/// Translates template arguments as provided by the parser
1139711397
/// into template arguments used by semantic analysis.
@@ -11430,8 +11430,7 @@ class Sema final : public SemaBase {
1143011430
DeclResult ActOnVarTemplateSpecialization(
1143111431
Scope *S, Declarator &D, TypeSourceInfo *DI, LookupResult &Previous,
1143211432
SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams,
11433-
StorageClass SC, bool IsPartialSpecialization,
11434-
bool IsMemberSpecialization);
11433+
StorageClass SC, bool IsPartialSpecialization);
1143511434

1143611435
/// Get the specialization of the given variable template corresponding to
1143711436
/// the specified argument list, or a null-but-valid result if the arguments
@@ -13072,14 +13071,28 @@ class Sema final : public SemaBase {
1307213071
/// dealing with a specialization. This is only relevant for function
1307313072
/// template specializations.
1307413073
///
13074+
/// \param Pattern If non-NULL, indicates the pattern from which we will be
13075+
/// instantiating the definition of the given declaration, \p ND. This is
13076+
/// used to determine the proper set of template instantiation arguments for
13077+
/// friend function template specializations.
13078+
///
1307513079
/// \param ForConstraintInstantiation when collecting arguments,
1307613080
/// ForConstraintInstantiation indicates we should continue looking when
1307713081
/// encountering a lambda generic call operator, and continue looking for
1307813082
/// arguments on an enclosing class template.
13083+
///
13084+
/// \param SkipForSpecialization when specified, any template specializations
13085+
/// in a traversal would be ignored.
13086+
/// \param ForDefaultArgumentSubstitution indicates we should continue looking
13087+
/// when encountering a specialized member function template, rather than
13088+
/// returning immediately.
1307913089
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
1308013090
const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false,
1308113091
std::optional<ArrayRef<TemplateArgument>> Innermost = std::nullopt,
13082-
bool RelativeToPrimary = false, bool ForConstraintInstantiation = false);
13092+
bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
13093+
bool ForConstraintInstantiation = false,
13094+
bool SkipForSpecialization = false,
13095+
bool ForDefaultArgumentSubstitution = false);
1308313096

1308413097
/// RAII object to handle the state changes required to synthesize
1308513098
/// a function body.

clang/lib/AST/DeclTemplate.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -309,35 +309,35 @@ bool TemplateDecl::isTypeAlias() const {
309309
void RedeclarableTemplateDecl::anchor() {}
310310

311311
RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() const {
312-
if (CommonBase *C = getCommonPtrInternal())
313-
return C;
312+
if (Common)
313+
return Common;
314314

315315
// Walk the previous-declaration chain until we either find a declaration
316316
// with a common pointer or we run out of previous declarations.
317317
SmallVector<const RedeclarableTemplateDecl *, 2> PrevDecls;
318318
for (const RedeclarableTemplateDecl *Prev = getPreviousDecl(); Prev;
319319
Prev = Prev->getPreviousDecl()) {
320-
if (CommonBase *C = Prev->getCommonPtrInternal()) {
321-
setCommonPtr(C);
320+
if (Prev->Common) {
321+
Common = Prev->Common;
322322
break;
323323
}
324324

325325
PrevDecls.push_back(Prev);
326326
}
327327

328328
// If we never found a common pointer, allocate one now.
329-
if (!getCommonPtrInternal()) {
329+
if (!Common) {
330330
// FIXME: If any of the declarations is from an AST file, we probably
331331
// need an update record to add the common data.
332332

333-
setCommonPtr(newCommon(getASTContext()));
333+
Common = newCommon(getASTContext());
334334
}
335335

336336
// Update any previous declarations we saw with the common pointer.
337337
for (const RedeclarableTemplateDecl *Prev : PrevDecls)
338-
Prev->setCommonPtr(getCommonPtrInternal());
338+
Prev->Common = Common;
339339

340-
return getCommonPtrInternal();
340+
return Common;
341341
}
342342

343343
void RedeclarableTemplateDecl::loadLazySpecializationsImpl() const {
@@ -463,17 +463,19 @@ void FunctionTemplateDecl::addSpecialization(
463463
}
464464

465465
void FunctionTemplateDecl::mergePrevDecl(FunctionTemplateDecl *Prev) {
466+
using Base = RedeclarableTemplateDecl;
467+
466468
// If we haven't created a common pointer yet, then it can just be created
467469
// with the usual method.
468-
if (!getCommonPtrInternal())
470+
if (!Base::Common)
469471
return;
470472

471-
Common *ThisCommon = static_cast<Common *>(getCommonPtrInternal());
473+
Common *ThisCommon = static_cast<Common *>(Base::Common);
472474
Common *PrevCommon = nullptr;
473475
SmallVector<FunctionTemplateDecl *, 8> PreviousDecls;
474476
for (; Prev; Prev = Prev->getPreviousDecl()) {
475-
if (CommonBase *C = Prev->getCommonPtrInternal()) {
476-
PrevCommon = static_cast<Common *>(C);
477+
if (Prev->Base::Common) {
478+
PrevCommon = static_cast<Common *>(Prev->Base::Common);
477479
break;
478480
}
479481
PreviousDecls.push_back(Prev);
@@ -483,15 +485,15 @@ void FunctionTemplateDecl::mergePrevDecl(FunctionTemplateDecl *Prev) {
483485
// use this common pointer.
484486
if (!PrevCommon) {
485487
for (auto *D : PreviousDecls)
486-
D->setCommonPtr(ThisCommon);
488+
D->Base::Common = ThisCommon;
487489
return;
488490
}
489491

490492
// Ensure we don't leak any important state.
491493
assert(ThisCommon->Specializations.size() == 0 &&
492494
"Can't merge incompatible declarations!");
493495

494-
setCommonPtr(PrevCommon);
496+
Base::Common = PrevCommon;
495497
}
496498

497499
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)