Skip to content

Commit c1a350e

Browse files
Merge branch 'main' into P2278R4_cbegin
2 parents eaf5c51 + c2a892f commit c1a350e

File tree

232 files changed

+9150
-1386
lines changed

Some content is hidden

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

232 files changed

+9150
-1386
lines changed

clang/include/clang/AST/DeclTemplate.h

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -857,16 +857,6 @@ class RedeclarableTemplateDecl : public TemplateDecl,
857857
/// \endcode
858858
bool isMemberSpecialization() const { return Common.getInt(); }
859859

860-
/// Determines whether any redeclaration of this template was
861-
/// a specialization of a member template.
862-
bool hasMemberSpecialization() const {
863-
for (const auto *D : redecls()) {
864-
if (D->isMemberSpecialization())
865-
return true;
866-
}
867-
return false;
868-
}
869-
870860
/// Note that this member template is a specialization.
871861
void setMemberSpecialization() {
872862
assert(!isMemberSpecialization() && "already a member specialization");
@@ -1965,13 +1955,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
19651955
/// specialization which was specialized by this.
19661956
llvm::PointerUnion<ClassTemplateDecl *,
19671957
ClassTemplatePartialSpecializationDecl *>
1968-
getSpecializedTemplateOrPartial() const {
1969-
if (const auto *PartialSpec =
1970-
SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1971-
return PartialSpec->PartialSpecialization;
1972-
1973-
return SpecializedTemplate.get<ClassTemplateDecl*>();
1974-
}
1958+
getSpecializedTemplateOrPartial() const;
19751959

19761960
/// Retrieve the set of template arguments that should be used
19771961
/// to instantiate members of the class template or class template partial
@@ -2208,17 +2192,6 @@ class ClassTemplatePartialSpecializationDecl
22082192
return InstantiatedFromMember.getInt();
22092193
}
22102194

2211-
/// Determines whether any redeclaration of this this class template partial
2212-
/// specialization was a specialization of a member partial specialization.
2213-
bool hasMemberSpecialization() const {
2214-
for (const auto *D : redecls()) {
2215-
if (cast<ClassTemplatePartialSpecializationDecl>(D)
2216-
->isMemberSpecialization())
2217-
return true;
2218-
}
2219-
return false;
2220-
}
2221-
22222195
/// Note that this member template is a specialization.
22232196
void setMemberSpecialization() { return InstantiatedFromMember.setInt(true); }
22242197

@@ -2740,13 +2713,7 @@ class VarTemplateSpecializationDecl : public VarDecl,
27402713
/// Retrieve the variable template or variable template partial
27412714
/// specialization which was specialized by this.
27422715
llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2743-
getSpecializedTemplateOrPartial() const {
2744-
if (const auto *PartialSpec =
2745-
SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2746-
return PartialSpec->PartialSpecialization;
2747-
2748-
return SpecializedTemplate.get<VarTemplateDecl *>();
2749-
}
2716+
getSpecializedTemplateOrPartial() const;
27502717

27512718
/// Retrieve the set of template arguments that should be used
27522719
/// to instantiate the initializer of the variable template or variable
@@ -2980,18 +2947,6 @@ class VarTemplatePartialSpecializationDecl
29802947
return InstantiatedFromMember.getInt();
29812948
}
29822949

2983-
/// Determines whether any redeclaration of this this variable template
2984-
/// partial specialization was a specialization of a member partial
2985-
/// specialization.
2986-
bool hasMemberSpecialization() const {
2987-
for (const auto *D : redecls()) {
2988-
if (cast<VarTemplatePartialSpecializationDecl>(D)
2989-
->isMemberSpecialization())
2990-
return true;
2991-
}
2992-
return false;
2993-
}
2994-
29952950
/// Note that this member template is a specialization.
29962951
void setMemberSpecialization() { return InstantiatedFromMember.setInt(true); }
29972952

@@ -3164,6 +3119,9 @@ class VarTemplateDecl : public RedeclarableTemplateDecl {
31643119
return makeSpecIterator(getSpecializations(), true);
31653120
}
31663121

3122+
/// Merge \p Prev with our RedeclarableTemplateDecl::Common.
3123+
void mergePrevDecl(VarTemplateDecl *Prev);
3124+
31673125
// Implement isa/cast/dyncast support
31683126
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
31693127
static bool classofKind(Kind K) { return K == VarTemplate; }

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12718,7 +12718,18 @@ def err_acc_num_arg_conflict
1271812718
def err_acc_clause_in_clause_region
1271912719
: Error<"loop with a '%0' clause may not exist in the region of a '%1' "
1272012720
"clause%select{| on a 'kernels' compute construct}2">;
12721-
12721+
def err_acc_gang_reduction_conflict
12722+
: Error<"%select{OpenACC 'gang' clause with a 'dim' value greater than "
12723+
"1|OpenACC 'reduction' clause}0 cannot "
12724+
"appear on the same 'loop' construct as a %select{'reduction' "
12725+
"clause|'gang' clause with a 'dim' value greater than 1}0">;
12726+
def err_acc_gang_reduction_numgangs_conflict
12727+
: Error<"OpenACC '%0' clause cannot appear on the same 'loop' construct "
12728+
"as a '%1' clause inside a compute construct with a "
12729+
"'num_gangs' clause with more than one argument">;
12730+
def err_reduction_op_mismatch
12731+
: Error<"OpenACC 'reduction' variable must have the same operator in all "
12732+
"nested constructs (%0 vs %1)">;
1272212733
// AMDGCN builtins diagnostics
1272312734
def err_amdgcn_global_load_lds_size_invalid_value : Error<"invalid size value">;
1272412735
def note_amdgcn_global_load_lds_size_valid_value : Note<"size must be 1, 2, or 4">;

clang/include/clang/Sema/SemaOpenACC.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class SemaOpenACC : public SemaBase {
6868
/// used to diagnose if there are multiple 'for' loops at any one level.
6969
LLVM_PREFERRED_TYPE(bool)
7070
unsigned CurLevelHasLoopAlready : 1;
71+
7172
} LoopInfo{/*TopLevelLoopSeen=*/false, /*CurLevelHasLoopAlready=*/false};
7273

7374
/// The 'collapse' clause requires quite a bit of checking while
@@ -109,6 +110,14 @@ class SemaOpenACC : public SemaBase {
109110
bool TileDepthSatisfied = true;
110111
} TileInfo;
111112

113+
/// A list of the active reduction clauses, which allows us to check that all
114+
/// vars on nested constructs for the same reduction var have the same
115+
/// reduction operator. Currently this is enforced against all constructs
116+
/// despite the rule being in the 'loop' section. By current reading, this
117+
/// should apply to all anyway, but we may need to make this more like the
118+
/// 'loop' clause enforcement, where this is 'blocked' by a compute construct.
119+
llvm::SmallVector<OpenACCReductionClause *> ActiveReductionClauses;
120+
112121
public:
113122
ComputeConstructInfo &getActiveComputeConstructInfo() {
114123
return ActiveComputeConstructInfo;
@@ -615,7 +624,9 @@ class SemaOpenACC : public SemaBase {
615624

616625
/// Called while semantically analyzing the reduction clause, ensuring the var
617626
/// is the correct kind of reference.
618-
ExprResult CheckReductionVar(Expr *VarExpr);
627+
ExprResult CheckReductionVar(OpenACCDirectiveKind DirectiveKind,
628+
OpenACCReductionOperator ReductionOp,
629+
Expr *VarExpr);
619630

620631
/// Called to check the 'var' type is a variable of pointer type, necessary
621632
/// for 'deviceptr' and 'attach' clauses. Returns true on success.
@@ -634,6 +645,22 @@ class SemaOpenACC : public SemaBase {
634645
// Check a single expression on a gang clause.
635646
ExprResult CheckGangExpr(OpenACCGangKind GK, Expr *E);
636647

648+
// Does the checking for a 'gang' clause that needs to be done in dependent
649+
// and not dependent cases.
650+
OpenACCClause *
651+
CheckGangClause(ArrayRef<const OpenACCClause *> ExistingClauses,
652+
SourceLocation BeginLoc, SourceLocation LParenLoc,
653+
ArrayRef<OpenACCGangKind> GangKinds,
654+
ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
655+
// Does the checking for a 'reduction ' clause that needs to be done in
656+
// dependent and not dependent cases.
657+
OpenACCClause *
658+
CheckReductionClause(ArrayRef<const OpenACCClause *> ExistingClauses,
659+
OpenACCDirectiveKind DirectiveKind,
660+
SourceLocation BeginLoc, SourceLocation LParenLoc,
661+
OpenACCReductionOperator ReductionOp,
662+
ArrayRef<Expr *> Vars, SourceLocation EndLoc);
663+
637664
ExprResult BuildOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc);
638665
ExprResult ActOnOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc);
639666

@@ -686,6 +713,7 @@ class SemaOpenACC : public SemaBase {
686713
SourceLocation OldLoopWorkerClauseLoc;
687714
SourceLocation OldLoopVectorClauseLoc;
688715
llvm::SmallVector<OpenACCLoopConstruct *> ParentlessLoopConstructs;
716+
llvm::SmallVector<OpenACCReductionClause *> ActiveReductionClauses;
689717
LoopInConstructRAII LoopRAII;
690718

691719
public:

clang/lib/AST/ASTImporter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6190,7 +6190,8 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
61906190
ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl(
61916191
ClassTemplateSpecializationDecl *D) {
61926192
ClassTemplateDecl *ClassTemplate;
6193-
if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6193+
if (Error Err = importInto(ClassTemplate,
6194+
D->getSpecializedTemplate()->getCanonicalDecl()))
61946195
return std::move(Err);
61956196

61966197
// Import the context of this declaration.

clang/lib/AST/Decl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,7 +2708,7 @@ VarDecl *VarDecl::getTemplateInstantiationPattern() const {
27082708
if (isTemplateInstantiation(VDTemplSpec->getTemplateSpecializationKind())) {
27092709
auto From = VDTemplSpec->getInstantiatedFrom();
27102710
if (auto *VTD = From.dyn_cast<VarTemplateDecl *>()) {
2711-
while (!VTD->hasMemberSpecialization()) {
2711+
while (!VTD->isMemberSpecialization()) {
27122712
if (auto *NewVTD = VTD->getInstantiatedFromMemberTemplate())
27132713
VTD = NewVTD;
27142714
else
@@ -2718,7 +2718,7 @@ VarDecl *VarDecl::getTemplateInstantiationPattern() const {
27182718
}
27192719
if (auto *VTPSD =
27202720
From.dyn_cast<VarTemplatePartialSpecializationDecl *>()) {
2721-
while (!VTPSD->hasMemberSpecialization()) {
2721+
while (!VTPSD->isMemberSpecialization()) {
27222722
if (auto *NewVTPSD = VTPSD->getInstantiatedFromMember())
27232723
VTPSD = NewVTPSD;
27242724
else
@@ -2732,7 +2732,7 @@ VarDecl *VarDecl::getTemplateInstantiationPattern() const {
27322732
// If this is the pattern of a variable template, find where it was
27332733
// instantiated from. FIXME: Is this necessary?
27342734
if (VarTemplateDecl *VTD = VD->getDescribedVarTemplate()) {
2735-
while (!VTD->hasMemberSpecialization()) {
2735+
while (!VTD->isMemberSpecialization()) {
27362736
if (auto *NewVTD = VTD->getInstantiatedFromMemberTemplate())
27372737
VTD = NewVTD;
27382738
else
@@ -4153,7 +4153,7 @@ FunctionDecl::getTemplateInstantiationPattern(bool ForDefinition) const {
41534153
if (FunctionTemplateDecl *Primary = getPrimaryTemplate()) {
41544154
// If we hit a point where the user provided a specialization of this
41554155
// template, we're done looking.
4156-
while (!ForDefinition || !Primary->hasMemberSpecialization()) {
4156+
while (!ForDefinition || !Primary->isMemberSpecialization()) {
41574157
if (auto *NewPrimary = Primary->getInstantiatedFromMemberTemplate())
41584158
Primary = NewPrimary;
41594159
else
@@ -4170,7 +4170,7 @@ FunctionTemplateDecl *FunctionDecl::getPrimaryTemplate() const {
41704170
if (FunctionTemplateSpecializationInfo *Info
41714171
= TemplateOrSpecialization
41724172
.dyn_cast<FunctionTemplateSpecializationInfo*>()) {
4173-
return Info->getTemplate();
4173+
return Info->getTemplate()->getMostRecentDecl();
41744174
}
41754175
return nullptr;
41764176
}

clang/lib/AST/DeclCXX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,7 @@ const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {
20302030
if (auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
20312031
auto From = TD->getInstantiatedFrom();
20322032
if (auto *CTD = From.dyn_cast<ClassTemplateDecl *>()) {
2033-
while (!CTD->hasMemberSpecialization()) {
2033+
while (!CTD->isMemberSpecialization()) {
20342034
if (auto *NewCTD = CTD->getInstantiatedFromMemberTemplate())
20352035
CTD = NewCTD;
20362036
else
@@ -2040,7 +2040,7 @@ const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {
20402040
}
20412041
if (auto *CTPSD =
20422042
From.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) {
2043-
while (!CTPSD->hasMemberSpecialization()) {
2043+
while (!CTPSD->isMemberSpecialization()) {
20442044
if (auto *NewCTPSD = CTPSD->getInstantiatedFromMemberTemplate())
20452045
CTPSD = NewCTPSD;
20462046
else

clang/lib/AST/DeclTemplate.cpp

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,17 @@ ClassTemplateSpecializationDecl::getSpecializedTemplate() const {
993993
if (const auto *PartialSpec =
994994
SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
995995
return PartialSpec->PartialSpecialization->getSpecializedTemplate();
996-
return SpecializedTemplate.get<ClassTemplateDecl*>();
996+
return SpecializedTemplate.get<ClassTemplateDecl *>()->getMostRecentDecl();
997+
}
998+
999+
llvm::PointerUnion<ClassTemplateDecl *,
1000+
ClassTemplatePartialSpecializationDecl *>
1001+
ClassTemplateSpecializationDecl::getSpecializedTemplateOrPartial() const {
1002+
if (const auto *PartialSpec =
1003+
SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1004+
return PartialSpec->PartialSpecialization->getMostRecentDecl();
1005+
1006+
return SpecializedTemplate.get<ClassTemplateDecl *>()->getMostRecentDecl();
9971007
}
9981008

9991009
SourceRange
@@ -1283,6 +1293,39 @@ VarTemplateDecl::newCommon(ASTContext &C) const {
12831293
return CommonPtr;
12841294
}
12851295

1296+
void VarTemplateDecl::mergePrevDecl(VarTemplateDecl *Prev) {
1297+
// If we haven't created a common pointer yet, then it can just be created
1298+
// with the usual method.
1299+
if (!getCommonPtrInternal())
1300+
return;
1301+
1302+
Common *ThisCommon = static_cast<Common *>(getCommonPtrInternal());
1303+
Common *PrevCommon = nullptr;
1304+
SmallVector<VarTemplateDecl *, 8> PreviousDecls;
1305+
for (; Prev; Prev = Prev->getPreviousDecl()) {
1306+
if (CommonBase *C = Prev->getCommonPtrInternal()) {
1307+
PrevCommon = static_cast<Common *>(C);
1308+
break;
1309+
}
1310+
PreviousDecls.push_back(Prev);
1311+
}
1312+
1313+
// If the previous redecl chain hasn't created a common pointer yet, then just
1314+
// use this common pointer.
1315+
if (!PrevCommon) {
1316+
for (auto *D : PreviousDecls)
1317+
D->setCommonPtr(ThisCommon);
1318+
return;
1319+
}
1320+
1321+
// Ensure we don't leak any important state.
1322+
assert(ThisCommon->Specializations.empty() &&
1323+
ThisCommon->PartialSpecializations.empty() &&
1324+
"Can't merge incompatible declarations!");
1325+
1326+
setCommonPtr(PrevCommon);
1327+
}
1328+
12861329
VarTemplateSpecializationDecl *
12871330
VarTemplateDecl::findSpecialization(ArrayRef<TemplateArgument> Args,
12881331
void *&InsertPos) {
@@ -1405,7 +1448,16 @@ VarTemplateDecl *VarTemplateSpecializationDecl::getSpecializedTemplate() const {
14051448
if (const auto *PartialSpec =
14061449
SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
14071450
return PartialSpec->PartialSpecialization->getSpecializedTemplate();
1408-
return SpecializedTemplate.get<VarTemplateDecl *>();
1451+
return SpecializedTemplate.get<VarTemplateDecl *>()->getMostRecentDecl();
1452+
}
1453+
1454+
llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
1455+
VarTemplateSpecializationDecl::getSpecializedTemplateOrPartial() const {
1456+
if (const auto *PartialSpec =
1457+
SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1458+
return PartialSpec->PartialSpecialization->getMostRecentDecl();
1459+
1460+
return SpecializedTemplate.get<VarTemplateDecl *>()->getMostRecentDecl();
14091461
}
14101462

14111463
SourceRange VarTemplateSpecializationDecl::getSourceRange() const {

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4694,8 +4694,10 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
46944694

46954695
// Keep a chain of previous declarations.
46964696
New->setPreviousDecl(Old);
4697-
if (NewTemplate)
4697+
if (NewTemplate) {
4698+
NewTemplate->mergePrevDecl(OldTemplate);
46984699
NewTemplate->setPreviousDecl(OldTemplate);
4700+
}
46994701

47004702
// Inherit access appropriately.
47014703
New->setAccess(Old->getAccess());

clang/lib/Sema/SemaInit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9954,7 +9954,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
99549954
auto SynthesizeAggrGuide = [&](InitListExpr *ListInit) {
99559955
auto *Pattern = Template;
99569956
while (Pattern->getInstantiatedFromMemberTemplate()) {
9957-
if (Pattern->hasMemberSpecialization())
9957+
if (Pattern->isMemberSpecialization())
99589958
break;
99599959
Pattern = Pattern->getInstantiatedFromMemberTemplate();
99609960
}

0 commit comments

Comments
 (0)