Skip to content

Commit 76d6615

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:ad1ca5f4a2bc into origin/amd-gfx:b6266caaf444
Local branch origin/amd-gfx b6266ca Merged main:c30776ab9a14 into origin/amd-gfx:7e0640a99a92 Remote branch main ad1ca5f [clang] Concepts: support pack expansions for type constraints (llvm#132626)
2 parents b6266ca + ad1ca5f commit 76d6615

File tree

368 files changed

+15391
-6739
lines changed

Some content is hidden

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

368 files changed

+15391
-6739
lines changed

.ci/compute_projects.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ def _get_modified_projects(modified_files: list[str]) -> Set[str]:
200200
# documentation builds.
201201
if len(path_parts) > 2 and path_parts[1] == "docs":
202202
continue
203+
# Exclude files for the gn build. We do not test it within premerge
204+
# and changes occur often enough that they otherwise take up
205+
# capacity.
206+
if len(path_parts) > 3 and path_parts[:3] == ("llvm", "utils", "gn"):
207+
continue
203208
modified_projects.add(pathlib.Path(modified_file).parts[0])
204209
return modified_projects
205210

.ci/compute_projects_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ def test_exclude_docs(self):
179179
self.assertEqual(env_variables["runtimes_to_build"], "")
180180
self.assertEqual(env_variables["runtimes_check_targets"], "")
181181

182+
def test_exclude_gn(self):
183+
env_variables = compute_projects.get_env_variables(
184+
["llvm/utils/gn/build/BUILD.gn"], "Linux"
185+
)
186+
self.assertEqual(env_variables["projects_to_build"], "")
187+
self.assertEqual(env_variables["project_check_targets"], "")
188+
self.assertEqual(env_variables["runtimes_to_build"], "")
189+
self.assertEqual(env_variables["runtimes_check_targets"], "")
190+
182191

183192
if __name__ == "__main__":
184193
unittest.main()

clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static std::vector<FixItHint> handleReturnType(const FunctionDecl *Function,
356356
if (!TypeText)
357357
return {};
358358

359-
SmallVector<const Expr *, 3> ExistingConstraints;
359+
SmallVector<AssociatedConstraint, 3> ExistingConstraints;
360360
Function->getAssociatedConstraints(ExistingConstraints);
361361
if (!ExistingConstraints.empty()) {
362362
// FIXME - Support adding new constraints to existing ones. Do we need to
@@ -404,7 +404,7 @@ handleTrailingTemplateType(const FunctionTemplateDecl *FunctionTemplate,
404404
if (!ConditionText)
405405
return {};
406406

407-
SmallVector<const Expr *, 3> ExistingConstraints;
407+
SmallVector<AssociatedConstraint, 3> ExistingConstraints;
408408
Function->getAssociatedConstraints(ExistingConstraints);
409409
if (!ExistingConstraints.empty()) {
410410
// FIXME - Support adding new constraints to existing ones. Do we need to

clang-tools-extra/clangd/AST.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ getQualification(ASTContext &Context, const DeclContext *DestContext,
119119
// There can't be any more tag parents after hitting a namespace.
120120
assert(!ReachedNS);
121121
(void)ReachedNS;
122-
NNS = NestedNameSpecifier::Create(Context, nullptr, false,
123-
TD->getTypeForDecl());
122+
NNS = NestedNameSpecifier::Create(Context, nullptr, TD->getTypeForDecl());
124123
} else if (auto *NSD = llvm::dyn_cast<NamespaceDecl>(CurContext)) {
125124
ReachedNS = true;
126125
NNS = NestedNameSpecifier::Create(Context, nullptr, NSD);

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,6 @@ bool allowIndex(CodeCompletionContext &CC) {
14671467
return true;
14681468
case NestedNameSpecifier::Super:
14691469
case NestedNameSpecifier::TypeSpec:
1470-
case NestedNameSpecifier::TypeSpecWithTemplate:
14711470
// Unresolved inside a template.
14721471
case NestedNameSpecifier::Identifier:
14731472
return false;

clang-tools-extra/clangd/DumpAST.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ class DumpVisitor : public RecursiveASTVisitor<DumpVisitor> {
157157
NNS_KIND(Identifier);
158158
NNS_KIND(Namespace);
159159
NNS_KIND(TypeSpec);
160-
NNS_KIND(TypeSpecWithTemplate);
161160
NNS_KIND(Global);
162161
NNS_KIND(Super);
163162
NNS_KIND(NamespaceAlias);

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,6 @@ struct TargetFinder {
500500
}
501501
return;
502502
case NestedNameSpecifier::TypeSpec:
503-
case NestedNameSpecifier::TypeSpecWithTemplate:
504503
add(QualType(NNS->getAsType(), 0), Flags);
505504
return;
506505
case NestedNameSpecifier::Global:

clang-tools-extra/include-cleaner/lib/WalkAST.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
144144
case NestedNameSpecifier::Global:
145145
return true;
146146
case NestedNameSpecifier::TypeSpec:
147-
case NestedNameSpecifier::TypeSpecWithTemplate:
148147
case NestedNameSpecifier::Super:
149148
case NestedNameSpecifier::Identifier:
150149
return false;

clang/docs/ReleaseNotes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ Improvements to Clang's diagnostics
275275
- Diagnostics on chained comparisons (``a < b < c``) are now an error by default. This can be disabled with
276276
``-Wno-error=parentheses``.
277277
- Clang now better preserves the sugared types of pointers to member.
278+
- Clang now better preserves the presence of the template keyword with dependent
279+
prefixes.
280+
- When printing types for diagnostics, clang now doesn't suppress the scopes of
281+
template arguments contained within nested names.
278282
- The ``-Wshift-bool`` warning has been added to warn about shifting a boolean. (#GH28334)
279283
- Fixed diagnostics adding a trailing ``::`` when printing some source code
280284
constructs, like base classes.
@@ -366,6 +370,9 @@ Bug Fixes to C++ Support
366370
- Clang now uses the parameter location for abbreviated function templates in ``extern "C"``. (#GH46386)
367371
- Clang will emit an error instead of crash when use co_await or co_yield in
368372
C++26 braced-init-list template parameter initialization. (#GH78426)
373+
- Improved fix for an issue with pack expansions of type constraints, where this
374+
now also works if the constraint has non-type or template template parameters.
375+
(#GH131798)
369376
- Fixes matching of nested template template parameters. (#GH130362)
370377
- Correctly diagnoses template template paramters which have a pack parameter
371378
not in the last position.

clang/include/clang/AST/ASTConcept.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,15 @@ class TypeConstraint {
229229
/// type-constraint.
230230
Expr *ImmediatelyDeclaredConstraint = nullptr;
231231
ConceptReference *ConceptRef;
232+
int ArgumentPackSubstitutionIndex;
232233

233234
public:
234235
TypeConstraint(ConceptReference *ConceptRef,
235-
Expr *ImmediatelyDeclaredConstraint)
236+
Expr *ImmediatelyDeclaredConstraint,
237+
int ArgumentPackSubstitutionIndex)
236238
: ImmediatelyDeclaredConstraint(ImmediatelyDeclaredConstraint),
237-
ConceptRef(ConceptRef) {}
239+
ConceptRef(ConceptRef),
240+
ArgumentPackSubstitutionIndex(ArgumentPackSubstitutionIndex) {}
238241

239242
/// \brief Get the immediately-declared constraint expression introduced by
240243
/// this type-constraint, that is - the constraint expression that is added to
@@ -245,6 +248,10 @@ class TypeConstraint {
245248

246249
ConceptReference *getConceptReference() const { return ConceptRef; }
247250

251+
int getArgumentPackSubstitutionIndex() const {
252+
return ArgumentPackSubstitutionIndex;
253+
}
254+
248255
// FIXME: Instead of using these concept related functions the callers should
249256
// directly work with the corresponding ConceptReference.
250257
ConceptDecl *getNamedConcept() const { return ConceptRef->getNamedConcept(); }

clang/include/clang/AST/ASTContext.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,9 +1798,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
17981798
QualType
17991799
getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
18001800
unsigned Index,
1801-
std::optional<unsigned> PackIndex,
1802-
SubstTemplateTypeParmTypeFlag Flag =
1803-
SubstTemplateTypeParmTypeFlag::None) const;
1801+
std::optional<unsigned> PackIndex) const;
18041802
QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl,
18051803
unsigned Index, bool Final,
18061804
const TemplateArgument &ArgPack);
@@ -1837,15 +1835,14 @@ class ASTContext : public RefCountedBase<ASTContext> {
18371835
TagDecl *OwnedTagDecl = nullptr) const;
18381836
QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
18391837
NestedNameSpecifier *NNS,
1840-
const IdentifierInfo *Name,
1841-
QualType Canon = QualType()) const;
1838+
const IdentifierInfo *Name) const;
18421839

18431840
QualType getDependentTemplateSpecializationType(
1844-
ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
1845-
const IdentifierInfo *Name, ArrayRef<TemplateArgumentLoc> Args) const;
1841+
ElaboratedTypeKeyword Keyword, const DependentTemplateStorage &Name,
1842+
ArrayRef<TemplateArgumentLoc> Args) const;
18461843
QualType getDependentTemplateSpecializationType(
1847-
ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
1848-
const IdentifierInfo *Name, ArrayRef<TemplateArgument> Args) const;
1844+
ElaboratedTypeKeyword Keyword, const DependentTemplateStorage &Name,
1845+
ArrayRef<TemplateArgument> Args, bool IsCanonical = false) const;
18491846

18501847
TemplateArgument getInjectedTemplateArg(NamedDecl *ParamDecl) const;
18511848

@@ -2393,11 +2390,9 @@ class ASTContext : public RefCountedBase<ASTContext> {
23932390
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
23942391
bool TemplateKeyword,
23952392
TemplateName Template) const;
2393+
TemplateName
2394+
getDependentTemplateName(const DependentTemplateStorage &Name) const;
23962395

2397-
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
2398-
const IdentifierInfo *Name) const;
2399-
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
2400-
OverloadedOperatorKind Operator) const;
24012396
TemplateName
24022397
getSubstTemplateTemplateParm(TemplateName replacement, Decl *AssociatedDecl,
24032398
unsigned Index,

clang/include/clang/AST/ASTImporter.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,14 @@ class TypeSourceInfo;
446446
/// returns nullptr only if the FromId was nullptr.
447447
IdentifierInfo *Import(const IdentifierInfo *FromId);
448448

449+
/// Import the given identifier or overloaded operator from the "from"
450+
/// context into the "to" context.
451+
///
452+
/// \returns The equivalent identifier or overloaded operator in the "to"
453+
/// context.
454+
IdentifierOrOverloadedOperator
455+
Import(IdentifierOrOverloadedOperator FromIO);
456+
449457
/// Import the given Objective-C selector from the "from"
450458
/// context into the "to" context.
451459
///

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ class ASTNodeTraverser
396396
// FIXME: Provide a NestedNameSpecifier visitor.
397397
NestedNameSpecifier *Qualifier = T->getQualifier();
398398
if (NestedNameSpecifier::SpecifierKind K = Qualifier->getKind();
399-
K == NestedNameSpecifier::TypeSpec ||
400-
K == NestedNameSpecifier::TypeSpecWithTemplate)
399+
K == NestedNameSpecifier::TypeSpec)
401400
Visit(Qualifier->getAsType());
402401
if (T->isSugared())
403402
Visit(T->getMostRecentCXXRecordDecl()->getTypeForDecl());

clang/include/clang/AST/AbstractBasicReader.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,8 @@ class DataStreamBasicReader : public BasicReaderBase<Impl> {
279279
continue;
280280

281281
case NestedNameSpecifier::TypeSpec:
282-
case NestedNameSpecifier::TypeSpecWithTemplate:
283282
cur = NestedNameSpecifier::Create(ctx, cur,
284-
kind == NestedNameSpecifier::TypeSpecWithTemplate,
285-
asImpl().readQualType().getTypePtr());
283+
asImpl().readQualType().getTypePtr());
286284
continue;
287285

288286
case NestedNameSpecifier::Global:

clang/include/clang/AST/AbstractBasicWriter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ class DataStreamBasicWriter : public BasicWriterBase<Impl> {
260260
continue;
261261

262262
case NestedNameSpecifier::TypeSpec:
263-
case NestedNameSpecifier::TypeSpecWithTemplate:
264263
asImpl().writeQualType(QualType(NNS->getAsType(), 0));
265264
continue;
266265

clang/include/clang/AST/Decl.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ class UnresolvedSetImpl;
7878
class VarTemplateDecl;
7979
enum class ImplicitParamKind;
8080

81+
// Holds a constraint expression along with a pack expansion index, if
82+
// expanded.
83+
struct AssociatedConstraint {
84+
const Expr *ConstraintExpr;
85+
int ArgumentPackSubstitutionIndex;
86+
87+
explicit AssociatedConstraint(const Expr *ConstraintExpr,
88+
int ArgumentPackSubstitutionIndex = -1)
89+
: ConstraintExpr(ConstraintExpr),
90+
ArgumentPackSubstitutionIndex(ArgumentPackSubstitutionIndex) {}
91+
};
92+
8193
/// The top declaration context.
8294
class TranslationUnitDecl : public Decl,
8395
public DeclContext,
@@ -2631,9 +2643,10 @@ class FunctionDecl : public DeclaratorDecl,
26312643
///
26322644
/// Use this instead of getTrailingRequiresClause for concepts APIs that
26332645
/// accept an ArrayRef of constraint expressions.
2634-
void getAssociatedConstraints(SmallVectorImpl<const Expr *> &AC) const {
2646+
void
2647+
getAssociatedConstraints(SmallVectorImpl<AssociatedConstraint> &AC) const {
26352648
if (auto *TRC = getTrailingRequiresClause())
2636-
AC.push_back(TRC);
2649+
AC.emplace_back(TRC);
26372650
}
26382651

26392652
/// Get the message that indicates why this function was deleted.

clang/include/clang/AST/DeclTemplate.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ class TemplateParameterList final
195195
///
196196
/// The constraints in the resulting list are to be treated as if in a
197197
/// conjunction ("and").
198-
void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const;
198+
void getAssociatedConstraints(
199+
llvm::SmallVectorImpl<AssociatedConstraint> &AC) const;
199200

200201
bool hasAssociatedConstraints() const;
201202

@@ -422,7 +423,8 @@ class TemplateDecl : public NamedDecl {
422423
/// including constraint-expressions derived from the requires-clause,
423424
/// trailing requires-clause (for functions and methods) and constrained
424425
/// template parameters.
425-
void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const;
426+
void getAssociatedConstraints(
427+
llvm::SmallVectorImpl<AssociatedConstraint> &AC) const;
426428

427429
bool hasAssociatedConstraints() const;
428430

@@ -1341,7 +1343,8 @@ class TemplateTypeParmDecl final : public TypeDecl,
13411343
}
13421344

13431345
void setTypeConstraint(ConceptReference *CR,
1344-
Expr *ImmediatelyDeclaredConstraint);
1346+
Expr *ImmediatelyDeclaredConstraint,
1347+
int ArgumentPackSubstitutionIndex);
13451348

13461349
/// Determine whether this template parameter has a type-constraint.
13471350
bool hasTypeConstraint() const {
@@ -1353,9 +1356,11 @@ class TemplateTypeParmDecl final : public TypeDecl,
13531356
///
13541357
/// Use this instead of getTypeConstraint for concepts APIs that
13551358
/// accept an ArrayRef of constraint expressions.
1356-
void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const {
1359+
void getAssociatedConstraints(
1360+
llvm::SmallVectorImpl<AssociatedConstraint> &AC) const {
13571361
if (HasTypeConstraint)
1358-
AC.push_back(getTypeConstraint()->getImmediatelyDeclaredConstraint());
1362+
AC.emplace_back(getTypeConstraint()->getImmediatelyDeclaredConstraint(),
1363+
getTypeConstraint()->getArgumentPackSubstitutionIndex());
13591364
}
13601365

13611366
SourceRange getSourceRange() const override LLVM_READONLY;
@@ -1574,9 +1579,10 @@ class NonTypeTemplateParmDecl final
15741579
///
15751580
/// Use this instead of getPlaceholderImmediatelyDeclaredConstraint for
15761581
/// concepts APIs that accept an ArrayRef of constraint expressions.
1577-
void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const {
1582+
void getAssociatedConstraints(
1583+
llvm::SmallVectorImpl<AssociatedConstraint> &AC) const {
15781584
if (Expr *E = getPlaceholderTypeConstraint())
1579-
AC.push_back(E);
1585+
AC.emplace_back(E);
15801586
}
15811587

15821588
// Implement isa/cast/dyncast/etc.
@@ -2169,7 +2175,8 @@ class ClassTemplatePartialSpecializationDecl
21692175
///
21702176
/// The constraints in the resulting list are to be treated as if in a
21712177
/// conjunction ("and").
2172-
void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const {
2178+
void getAssociatedConstraints(
2179+
llvm::SmallVectorImpl<AssociatedConstraint> &AC) const {
21732180
TemplateParams->getAssociatedConstraints(AC);
21742181
}
21752182

@@ -2943,7 +2950,8 @@ class VarTemplatePartialSpecializationDecl
29432950
///
29442951
/// The constraints in the resulting list are to be treated as if in a
29452952
/// conjunction ("and").
2946-
void getAssociatedConstraints(llvm::SmallVectorImpl<const Expr *> &AC) const {
2953+
void getAssociatedConstraints(
2954+
llvm::SmallVectorImpl<AssociatedConstraint> &AC) const {
29472955
TemplateParams->getAssociatedConstraints(AC);
29482956
}
29492957

clang/include/clang/AST/NestedNameSpecifier.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ class NestedNameSpecifier : public llvm::FoldingSetNode {
5252
enum StoredSpecifierKind {
5353
StoredIdentifier = 0,
5454
StoredDecl = 1,
55-
StoredTypeSpec = 2,
56-
StoredTypeSpecWithTemplate = 3
55+
StoredTypeSpec = 2
5756
};
5857

5958
/// The nested name specifier that precedes this nested name
@@ -89,10 +88,6 @@ class NestedNameSpecifier : public llvm::FoldingSetNode {
8988
/// A type, stored as a Type*.
9089
TypeSpec,
9190

92-
/// A type that was preceded by the 'template' keyword,
93-
/// stored as a Type*.
94-
TypeSpecWithTemplate,
95-
9691
/// The global specifier '::'. There is no stored value.
9792
Global,
9893

@@ -137,9 +132,8 @@ class NestedNameSpecifier : public llvm::FoldingSetNode {
137132
const NamespaceAliasDecl *Alias);
138133

139134
/// Builds a nested name specifier that names a type.
140-
static NestedNameSpecifier *Create(const ASTContext &Context,
141-
NestedNameSpecifier *Prefix,
142-
bool Template, const Type *T);
135+
static NestedNameSpecifier *
136+
Create(const ASTContext &Context, NestedNameSpecifier *Prefix, const Type *T);
143137

144138
/// Builds a specifier that consists of just an identifier.
145139
///
@@ -194,8 +188,7 @@ class NestedNameSpecifier : public llvm::FoldingSetNode {
194188

195189
/// Retrieve the type stored in this nested name specifier.
196190
const Type *getAsType() const {
197-
if (Prefix.getInt() == StoredTypeSpec ||
198-
Prefix.getInt() == StoredTypeSpecWithTemplate)
191+
if (Prefix.getInt() == StoredTypeSpec)
199192
return (const Type *)Specifier;
200193

201194
return nullptr;
@@ -401,13 +394,10 @@ class NestedNameSpecifierLocBuilder {
401394
/// \param Context The AST context in which this nested-name-specifier
402395
/// resides.
403396
///
404-
/// \param TemplateKWLoc The location of the 'template' keyword, if present.
405-
///
406397
/// \param TL The TypeLoc that describes the type preceding the '::'.
407398
///
408399
/// \param ColonColonLoc The location of the trailing '::'.
409-
void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL,
410-
SourceLocation ColonColonLoc);
400+
void Extend(ASTContext &Context, TypeLoc TL, SourceLocation ColonColonLoc);
411401

412402
/// Extend the current nested-name-specifier by another
413403
/// nested-name-specifier component of the form 'identifier::'.

0 commit comments

Comments
 (0)