Skip to content

Commit f7a0895

Browse files
authored
Merge branch 'release/20.x' into Backport_AVX10
2 parents fa4e3e4 + 3d5f5ef commit f7a0895

File tree

88 files changed

+2663
-1030
lines changed

Some content is hidden

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

88 files changed

+2663
-1030
lines changed

.github/workflows/libclang-abi-tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ jobs:
103103
uses: llvm/actions/install-ninja@main
104104
- name: Install abi-compliance-checker
105105
run: |
106+
sudo apt-get update
106107
sudo apt-get install abi-dumper autoconf pkg-config
107108
- name: Install universal-ctags
108109
run: |
@@ -154,7 +155,9 @@ jobs:
154155
path: build-latest
155156

156157
- name: Install abi-compliance-checker
157-
run: sudo apt-get install abi-compliance-checker
158+
run: |
159+
sudo apt-get update
160+
sudo apt-get install abi-compliance-checker
158161
- name: Compare ABI
159162
run: |
160163
for lib in ${{ needs.abi-dump-setup.outputs.ABI_LIBS }}; do

.github/workflows/llvm-tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ jobs:
9191
uses: llvm/actions/install-ninja@main
9292
- name: Install abi-compliance-checker
9393
run: |
94+
sudo apt-get update
9495
sudo apt-get install abi-dumper autoconf pkg-config
9596
- name: Install universal-ctags
9697
run: |
@@ -163,7 +164,9 @@ jobs:
163164
path: symbol-list
164165

165166
- name: Install abi-compliance-checker
166-
run: sudo apt-get install abi-compliance-checker
167+
run: |
168+
sudo apt-get update
169+
sudo apt-get install abi-compliance-checker
167170
- name: Compare ABI
168171
run: |
169172
if [ -s symbol-list/llvm.symbols ]; then

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,13 @@ Bug Fixes to C++ Support
10581058
- Fixed a substitution bug in transforming CTAD aliases when the type alias contains a non-pack template argument
10591059
corresponding to a pack parameter (#GH124715)
10601060
- Clang is now better at keeping track of friend function template instance contexts. (#GH55509)
1061+
- Fixes matching of nested template template parameters. (#GH130362)
1062+
- Correctly diagnoses template template paramters which have a pack parameter
1063+
not in the last position.
10611064
- Fixed an integer overflow bug in computing template parameter depths when synthesizing CTAD guides. (#GH128691)
10621065
- Fixed an incorrect pointer access when checking access-control on concepts. (#GH131530)
1066+
- Fixed various alias CTAD bugs involving variadic template arguments. (#GH123591), (#GH127539), (#GH129077),
1067+
(#GH129620), and (#GH129998).
10631068

10641069
Bug Fixes to AST Handling
10651070
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Sema/Sema.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11279,14 +11279,16 @@ class Sema final : public SemaBase {
1127911279

1128011280
/// The context in which we are checking a template parameter list.
1128111281
enum TemplateParamListContext {
11282-
TPC_ClassTemplate,
11283-
TPC_VarTemplate,
11282+
// For this context, Class, Variable, TypeAlias, and non-pack Template
11283+
// Template Parameters are treated uniformly.
11284+
TPC_Other,
11285+
1128411286
TPC_FunctionTemplate,
1128511287
TPC_ClassTemplateMember,
1128611288
TPC_FriendClassTemplate,
1128711289
TPC_FriendFunctionTemplate,
1128811290
TPC_FriendFunctionTemplateDefinition,
11289-
TPC_TypeAliasTemplate
11291+
TPC_TemplateTemplateParameterPack,
1129011292
};
1129111293

1129211294
/// Checks the validity of a template parameter list, possibly

clang/lib/Driver/ToolChains/Hexagon.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
313313
// handled somewhere else.
314314
Args.ClaimAllArgs(options::OPT_static_libgcc);
315315

316+
CmdArgs.push_back("--eh-frame-hdr");
316317
//----------------------------------------------------------------------------
317318
//
318319
//----------------------------------------------------------------------------
@@ -802,9 +803,7 @@ bool HexagonToolChain::isAutoHVXEnabled(const llvm::opt::ArgList &Args) {
802803
// Returns the default CPU for Hexagon. This is the default compilation target
803804
// if no Hexagon processor is selected at the command-line.
804805
//
805-
StringRef HexagonToolChain::GetDefaultCPU() {
806-
return "hexagonv60";
807-
}
806+
StringRef HexagonToolChain::GetDefaultCPU() { return "hexagonv68"; }
808807

809808
StringRef HexagonToolChain::GetTargetCPUVersion(const ArgList &Args) {
810809
Arg *CpuArg = nullptr;

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8145,7 +8145,7 @@ NamedDecl *Sema::ActOnVariableDeclarator(
81458145
(D.getCXXScopeSpec().isSet() && DC && DC->isRecord() &&
81468146
DC->isDependentContext())
81478147
? TPC_ClassTemplateMember
8148-
: TPC_VarTemplate))
8148+
: TPC_Other))
81498149
NewVD->setInvalidDecl();
81508150

81518151
// If we are providing an explicit specialization of a static variable

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13533,7 +13533,7 @@ Decl *Sema::ActOnAliasDeclaration(Scope *S, AccessSpecifier AS,
1353313533
// Merge any previous default template arguments into our parameters,
1353413534
// and check the parameter list.
1353513535
if (CheckTemplateParameterList(TemplateParams, OldTemplateParams,
13536-
TPC_TypeAliasTemplate))
13536+
TPC_Other))
1353713537
return nullptr;
1353813538

1353913539
TypeAliasTemplateDecl *NewDecl =

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,8 +1591,16 @@ NamedDecl *Sema::ActOnTemplateTemplateParameter(
15911591
assert(S->isTemplateParamScope() &&
15921592
"Template template parameter not in template parameter scope!");
15931593

1594-
// Construct the parameter object.
15951594
bool IsParameterPack = EllipsisLoc.isValid();
1595+
1596+
bool Invalid = false;
1597+
if (CheckTemplateParameterList(
1598+
Params,
1599+
/*OldParams=*/nullptr,
1600+
IsParameterPack ? TPC_TemplateTemplateParameterPack : TPC_Other))
1601+
Invalid = true;
1602+
1603+
// Construct the parameter object.
15961604
TemplateTemplateParmDecl *Param = TemplateTemplateParmDecl::Create(
15971605
Context, Context.getTranslationUnitDecl(),
15981606
NameLoc.isInvalid() ? TmpLoc : NameLoc, Depth, Position, IsParameterPack,
@@ -1615,9 +1623,12 @@ NamedDecl *Sema::ActOnTemplateTemplateParameter(
16151623
if (Params->size() == 0) {
16161624
Diag(Param->getLocation(), diag::err_template_template_parm_no_parms)
16171625
<< SourceRange(Params->getLAngleLoc(), Params->getRAngleLoc());
1618-
Param->setInvalidDecl();
1626+
Invalid = true;
16191627
}
16201628

1629+
if (Invalid)
1630+
Param->setInvalidDecl();
1631+
16211632
// C++0x [temp.param]p9:
16221633
// A default template-argument may be specified for any kind of
16231634
// template-parameter that is not a template parameter pack.
@@ -2066,7 +2077,7 @@ DeclResult Sema::CheckClassTemplate(
20662077
SemanticContext->isDependentContext())
20672078
? TPC_ClassTemplateMember
20682079
: TUK == TagUseKind::Friend ? TPC_FriendClassTemplate
2069-
: TPC_ClassTemplate,
2080+
: TPC_Other,
20702081
SkipBody))
20712082
Invalid = true;
20722083

@@ -2208,9 +2219,8 @@ static bool DiagnoseDefaultTemplateArgument(Sema &S,
22082219
SourceLocation ParamLoc,
22092220
SourceRange DefArgRange) {
22102221
switch (TPC) {
2211-
case Sema::TPC_ClassTemplate:
2212-
case Sema::TPC_VarTemplate:
2213-
case Sema::TPC_TypeAliasTemplate:
2222+
case Sema::TPC_Other:
2223+
case Sema::TPC_TemplateTemplateParameterPack:
22142224
return false;
22152225

22162226
case Sema::TPC_FunctionTemplate:
@@ -2383,8 +2393,11 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
23832393
MissingDefaultArg = true;
23842394
} else if (NonTypeTemplateParmDecl *NewNonTypeParm
23852395
= dyn_cast<NonTypeTemplateParmDecl>(*NewParam)) {
2386-
// Check for unexpanded parameter packs.
2387-
if (!NewNonTypeParm->isParameterPack() &&
2396+
// Check for unexpanded parameter packs, except in a template template
2397+
// parameter pack, as in those any unexpanded packs should be expanded
2398+
// along with the parameter itself.
2399+
if (TPC != TPC_TemplateTemplateParameterPack &&
2400+
!NewNonTypeParm->isParameterPack() &&
23882401
DiagnoseUnexpandedParameterPack(NewNonTypeParm->getLocation(),
23892402
NewNonTypeParm->getTypeSourceInfo(),
23902403
UPPC_NonTypeTemplateParameterType)) {
@@ -2492,8 +2505,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
24922505
// If a template parameter of a primary class template or alias template
24932506
// is a template parameter pack, it shall be the last template parameter.
24942507
if (SawParameterPack && (NewParam + 1) != NewParamEnd &&
2495-
(TPC == TPC_ClassTemplate || TPC == TPC_VarTemplate ||
2496-
TPC == TPC_TypeAliasTemplate)) {
2508+
(TPC == TPC_Other || TPC == TPC_TemplateTemplateParameterPack)) {
24972509
Diag((*NewParam)->getLocation(),
24982510
diag::err_template_param_pack_must_be_last_template_parameter);
24992511
Invalid = true;
@@ -2526,8 +2538,8 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
25262538
<< PrevModuleName;
25272539
Invalid = true;
25282540
} else if (MissingDefaultArg &&
2529-
(TPC == TPC_ClassTemplate || TPC == TPC_FriendClassTemplate ||
2530-
TPC == TPC_VarTemplate || TPC == TPC_TypeAliasTemplate)) {
2541+
(TPC == TPC_Other || TPC == TPC_TemplateTemplateParameterPack ||
2542+
TPC == TPC_FriendClassTemplate)) {
25312543
// C++ 23[temp.param]p14:
25322544
// If a template-parameter of a class template, variable template, or
25332545
// alias template has a default template argument, each subsequent

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3427,9 +3427,9 @@ static TemplateDeductionResult FinishTemplateArgumentDeduction(
34273427
if (!P.isPackExpansion() && !A.isPackExpansion()) {
34283428
Info.Param =
34293429
makeTemplateParameter(Template->getTemplateParameters()->getParam(
3430-
(PsStack.empty() ? TemplateArgs.end()
3431-
: PsStack.front().begin()) -
3432-
TemplateArgs.begin()));
3430+
(AsStack.empty() ? CTAI.CanonicalConverted.end()
3431+
: AsStack.front().begin()) -
3432+
1 - CTAI.CanonicalConverted.begin()));
34333433
Info.FirstArg = P;
34343434
Info.SecondArg = A;
34353435
return TemplateDeductionResult::NonDeducedMismatch;
@@ -6625,17 +6625,19 @@ bool Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs(
66256625

66266626
TemplateDeductionResult TDK;
66276627
runWithSufficientStackSpace(Info.getLocation(), [&] {
6628-
TDK = ::FinishTemplateArgumentDeduction(
6629-
*this, AArg, /*IsPartialOrdering=*/true, PArgs, Deduced, Info);
6628+
TDK = ::FinishTemplateArgumentDeduction(*this, AArg, PartialOrdering, PArgs,
6629+
Deduced, Info);
66306630
});
66316631
switch (TDK) {
66326632
case TemplateDeductionResult::Success:
66336633
return true;
66346634

66356635
// It doesn't seem possible to get a non-deduced mismatch when partial
6636-
// ordering TTPs.
6636+
// ordering TTPs, except with an invalid template parameter list which has
6637+
// a parameter after a pack.
66376638
case TemplateDeductionResult::NonDeducedMismatch:
6638-
llvm_unreachable("Unexpected NonDeducedMismatch");
6639+
assert(PArg->isInvalidDecl() && "Unexpected NonDeducedMismatch");
6640+
return false;
66396641

66406642
// Substitution failures should have already been diagnosed.
66416643
case TemplateDeductionResult::AlreadyDiagnosed:

clang/lib/Sema/SemaTemplateDeductionGuide.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,10 @@ struct ConvertConstructorToDeductionGuideTransform {
377377
if (NestedPattern)
378378
Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
379379
auto [Depth, Index] = getDepthAndIndex(Param);
380-
// Depth can still be 0 if FTD belongs to an explicit class template
381-
// specialization with an empty template parameter list. In that case,
382-
// we don't want the NewDepth to overflow, and it should remain 0.
383-
assert(Depth ||
384-
cast<ClassTemplateSpecializationDecl>(FTD->getDeclContext())
385-
->isExplicitSpecialization());
380+
// Depth can be 0 if FTD belongs to a non-template class/a class
381+
// template specialization with an empty template parameter list. In
382+
// that case, we don't want the NewDepth to overflow, and it should
383+
// remain 0.
386384
NamedDecl *NewParam = transformTemplateParameter(
387385
SemaRef, DC, Param, Args, Index + Depth1IndexAdjustment,
388386
Depth ? Depth - 1 : 0);
@@ -989,6 +987,19 @@ getRHSTemplateDeclAndArgs(Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate) {
989987
return {Template, AliasRhsTemplateArgs};
990988
}
991989

990+
bool IsNonDeducedArgument(const TemplateArgument &TA) {
991+
// The following cases indicate the template argument is non-deducible:
992+
// 1. The result is null. E.g. When it comes from a default template
993+
// argument that doesn't appear in the alias declaration.
994+
// 2. The template parameter is a pack and that cannot be deduced from
995+
// the arguments within the alias declaration.
996+
// Non-deducible template parameters will persist in the transformed
997+
// deduction guide.
998+
return TA.isNull() ||
999+
(TA.getKind() == TemplateArgument::Pack &&
1000+
llvm::any_of(TA.pack_elements(), IsNonDeducedArgument));
1001+
}
1002+
9921003
// Build deduction guides for a type alias template from the given underlying
9931004
// deduction guide F.
9941005
FunctionTemplateDecl *
@@ -1057,7 +1068,8 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
10571068
// !!NOTE: DeduceResults respects the sequence of template parameters of
10581069
// the deduction guide f.
10591070
for (unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
1060-
if (const auto &D = DeduceResults[Index]; !D.isNull()) // Deduced
1071+
const auto &D = DeduceResults[Index];
1072+
if (!IsNonDeducedArgument(D))
10611073
DeducedArgs.push_back(D);
10621074
else
10631075
NonDeducedTemplateParamsInFIndex.push_back(Index);
@@ -1121,7 +1133,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
11211133
Args.addOuterTemplateArguments(TransformedDeducedAliasArgs);
11221134
for (unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
11231135
const auto &D = DeduceResults[Index];
1124-
if (D.isNull()) {
1136+
if (IsNonDeducedArgument(D)) {
11251137
// 2): Non-deduced template parameters would be substituted later.
11261138
continue;
11271139
}

0 commit comments

Comments
 (0)