Skip to content

Commit 428d71d

Browse files
authored
merge main into amd-staging (llvm#4254)
2 parents e087fcc + fc668cc commit 428d71d

Some content is hidden

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

43 files changed

+2170
-1290
lines changed

.github/workflows/containers/github-action-ci/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
FROM docker.io/library/ubuntu:24.04 as base
1+
FROM docker.io/library/ubuntu:24.04 AS base
22
ENV LLVM_SYSROOT=/opt/llvm
33

4-
FROM base as stage1-toolchain
4+
FROM base AS stage1-toolchain
55
ENV LLVM_VERSION=21.1.1
66

77
RUN apt-get update && \
@@ -37,7 +37,7 @@ RUN cmake -B ./build -G Ninja ./llvm \
3737

3838
RUN ninja -C ./build stage2-clang-bolt stage2-install-distribution && ninja -C ./build install-distribution
3939

40-
FROM base as ci-container
40+
FROM base AS ci-container
4141

4242
COPY --from=stage1-toolchain $LLVM_SYSROOT $LLVM_SYSROOT
4343

@@ -97,7 +97,7 @@ RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
9797
USER gha
9898
WORKDIR /home/gha
9999

100-
FROM ci-container as ci-container-agent
100+
FROM ci-container AS ci-container-agent
101101

102102
ENV GITHUB_RUNNER_VERSION=2.328.0
103103

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,8 @@ Improvements to Clang's diagnostics
547547
"format specifies type 'unsigned int' but the argument has type 'int', which differs in signedness [-Wformat-signedness]"
548548
"signedness of format specifier 'u' is incompatible with 'c' [-Wformat-signedness]"
549549
and the API-visible diagnostic id will be appropriate.
550-
550+
- Clang now produces better diagnostics for template template parameter matching
551+
involving 'auto' template parameters.
551552
- Fixed false positives in ``-Waddress-of-packed-member`` diagnostics when
552553
potential misaligned members get processed before they can get discarded.
553554
(#GH144729)
@@ -608,6 +609,7 @@ Bug Fixes in This Version
608609
first parameter. (#GH113323).
609610
- Fixed a crash with incompatible pointer to integer conversions in designated
610611
initializers involving string literals. (#GH154046)
612+
- Fix crash on CTAD for alias template. (#GH131342)
611613
- Clang now emits a frontend error when a function marked with the `flatten` attribute
612614
calls another function that requires target features not enabled in the caller. This
613615
prevents a fatal error in the backend.

clang/include/clang/AST/ExprCXX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4714,7 +4714,7 @@ class SubstNonTypeTemplateParmExpr : public Expr {
47144714
// sugared: it doesn't need to be resugared later.
47154715
bool getFinal() const { return Final; }
47164716

4717-
NamedDecl *getParameter() const;
4717+
NonTypeTemplateParmDecl *getParameter() const;
47184718

47194719
bool isReferenceParameter() const { return AssociatedDeclAndRef.getInt(); }
47204720

clang/include/clang/AST/TypeBase.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3495,7 +3495,9 @@ class AdjustedType : public Type, public llvm::FoldingSetNode {
34953495

34963496
AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy,
34973497
QualType CanonicalPtr)
3498-
: Type(TC, CanonicalPtr, OriginalTy->getDependence()),
3498+
: Type(TC, CanonicalPtr,
3499+
AdjustedTy->getDependence() |
3500+
(OriginalTy->getDependence() & ~TypeDependence::Dependent)),
34993501
OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}
35003502

35013503
public:

clang/include/clang/Sema/Sema.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11714,6 +11714,23 @@ class Sema final : public SemaBase {
1171411714
const TemplateArgumentListInfo *TemplateArgs,
1171511715
bool IsAddressOfOperand);
1171611716

11717+
UnsignedOrNone getPackIndex(TemplateArgument Pack) const {
11718+
return Pack.pack_size() - 1 - *ArgPackSubstIndex;
11719+
}
11720+
11721+
TemplateArgument
11722+
getPackSubstitutedTemplateArgument(TemplateArgument Arg) const {
11723+
Arg = Arg.pack_elements()[*ArgPackSubstIndex];
11724+
if (Arg.isPackExpansion())
11725+
Arg = Arg.getPackExpansionPattern();
11726+
return Arg;
11727+
}
11728+
11729+
ExprResult BuildSubstNonTypeTemplateParmExpr(
11730+
Decl *AssociatedDecl, const NonTypeTemplateParmDecl *NTTP,
11731+
SourceLocation loc, TemplateArgument Replacement,
11732+
UnsignedOrNone PackIndex, bool Final);
11733+
1171711734
/// Form a template name from a name that is syntactically required to name a
1171811735
/// template, either due to use of the 'template' keyword or because a name in
1171911736
/// this syntactic context is assumed to name a template (C++

clang/lib/AST/ExprCXX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,8 +1725,8 @@ SizeOfPackExpr *SizeOfPackExpr::CreateDeserialized(ASTContext &Context,
17251725
return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs);
17261726
}
17271727

1728-
NamedDecl *SubstNonTypeTemplateParmExpr::getParameter() const {
1729-
return cast<NamedDecl>(
1728+
NonTypeTemplateParmDecl *SubstNonTypeTemplateParmExpr::getParameter() const {
1729+
return cast<NonTypeTemplateParmDecl>(
17301730
getReplacedTemplateParameterList(getAssociatedDecl())->asArray()[Index]);
17311731
}
17321732

clang/lib/AST/StmtProfile.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,8 @@ void StmtProfiler::VisitExpr(const Expr *S) {
13531353
}
13541354

13551355
void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
1356-
VisitExpr(S);
1356+
// Profile exactly as the sub-expression.
1357+
Visit(S->getSubExpr());
13571358
}
13581359

13591360
void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,40 @@ Sema::BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
775775
TemplateArgs);
776776
}
777777

778+
ExprResult Sema::BuildSubstNonTypeTemplateParmExpr(
779+
Decl *AssociatedDecl, const NonTypeTemplateParmDecl *NTTP,
780+
SourceLocation Loc, TemplateArgument Arg, UnsignedOrNone PackIndex,
781+
bool Final) {
782+
// The template argument itself might be an expression, in which case we just
783+
// return that expression. This happens when substituting into an alias
784+
// template.
785+
Expr *Replacement;
786+
bool refParam = true;
787+
if (Arg.getKind() == TemplateArgument::Expression) {
788+
Replacement = Arg.getAsExpr();
789+
refParam = Replacement->isLValue();
790+
if (refParam && Replacement->getType()->isRecordType()) {
791+
QualType ParamType =
792+
NTTP->isExpandedParameterPack()
793+
? NTTP->getExpansionType(*SemaRef.ArgPackSubstIndex)
794+
: NTTP->getType();
795+
if (const auto *PET = dyn_cast<PackExpansionType>(ParamType))
796+
ParamType = PET->getPattern();
797+
refParam = ParamType->isReferenceType();
798+
}
799+
} else {
800+
ExprResult result =
801+
SemaRef.BuildExpressionFromNonTypeTemplateArgument(Arg, Loc);
802+
if (result.isInvalid())
803+
return ExprError();
804+
Replacement = result.get();
805+
refParam = Arg.getNonTypeTemplateArgumentType()->isReferenceType();
806+
}
807+
return new (SemaRef.Context) SubstNonTypeTemplateParmExpr(
808+
Replacement->getType(), Replacement->getValueKind(), Loc, Replacement,
809+
AssociatedDecl, NTTP->getIndex(), PackIndex, refParam, Final);
810+
}
811+
778812
bool Sema::DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation,
779813
NamedDecl *Instantiation,
780814
bool InstantiatedFromMember,
@@ -7068,22 +7102,8 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
70687102

70697103
// If the parameter type somehow involves auto, deduce the type now.
70707104
DeducedType *DeducedT = ParamType->getContainedDeducedType();
7071-
if (getLangOpts().CPlusPlus17 && DeducedT && !DeducedT->isDeduced()) {
7072-
// During template argument deduction, we allow 'decltype(auto)' to
7073-
// match an arbitrary dependent argument.
7074-
// FIXME: The language rules don't say what happens in this case.
7075-
// FIXME: We get an opaque dependent type out of decltype(auto) if the
7076-
// expression is merely instantiation-dependent; is this enough?
7077-
if (DeductionArg->isTypeDependent()) {
7078-
auto *AT = dyn_cast<AutoType>(DeducedT);
7079-
if (AT && AT->isDecltypeAuto()) {
7080-
SugaredConverted = TemplateArgument(Arg, /*IsCanonical=*/false);
7081-
CanonicalConverted = TemplateArgument(
7082-
Context.getCanonicalTemplateArgument(SugaredConverted));
7083-
return Arg;
7084-
}
7085-
}
7086-
7105+
bool IsDeduced = DeducedT && !DeducedT->isDeduced();
7106+
if (IsDeduced) {
70877107
// When checking a deduced template argument, deduce from its type even if
70887108
// the type is dependent, in order to check the types of non-type template
70897109
// arguments line up properly in partial ordering.
@@ -7112,17 +7132,21 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
71127132
// along with the other associated constraints after
71137133
// checking the template argument list.
71147134
/*IgnoreConstraints=*/true);
7115-
if (Result == TemplateDeductionResult::AlreadyDiagnosed) {
7116-
return ExprError();
7117-
} else if (Result != TemplateDeductionResult::Success) {
7118-
if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
7119-
Diag(Arg->getExprLoc(),
7120-
diag::err_non_type_template_parm_type_deduction_failure)
7121-
<< Param->getDeclName() << NTTP->getType() << Arg->getType()
7122-
<< Arg->getSourceRange();
7135+
if (Result != TemplateDeductionResult::Success) {
7136+
ParamType = TSI->getType();
7137+
if (StrictCheck || !DeductionArg->isTypeDependent()) {
7138+
if (Result == TemplateDeductionResult::AlreadyDiagnosed)
7139+
return ExprError();
7140+
if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
7141+
Diag(Arg->getExprLoc(),
7142+
diag::err_non_type_template_parm_type_deduction_failure)
7143+
<< Param->getDeclName() << NTTP->getType() << Arg->getType()
7144+
<< Arg->getSourceRange();
7145+
NoteTemplateParameterLocation(*Param);
7146+
return ExprError();
71237147
}
7124-
NoteTemplateParameterLocation(*Param);
7125-
return ExprError();
7148+
ParamType = SubstAutoTypeDependent(ParamType);
7149+
assert(!ParamType.isNull() && "substituting DependentTy can't fail");
71267150
}
71277151
}
71287152
// CheckNonTypeTemplateParameterType will produce a diagnostic if there's
@@ -7144,14 +7168,16 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
71447168
// type-dependent, there's nothing we can check now.
71457169
if (ParamType->isDependentType() || DeductionArg->isTypeDependent()) {
71467170
// Force the argument to the type of the parameter to maintain invariants.
7147-
ExprResult E = ImpCastExprToType(
7148-
DeductionArg, ParamType.getNonLValueExprType(Context), CK_Dependent,
7149-
ParamType->isLValueReferenceType() ? VK_LValue
7150-
: ParamType->isRValueReferenceType() ? VK_XValue
7151-
: VK_PRValue);
7152-
if (E.isInvalid())
7153-
return ExprError();
7154-
setDeductionArg(E.get());
7171+
if (!IsDeduced) {
7172+
ExprResult E = ImpCastExprToType(
7173+
DeductionArg, ParamType.getNonLValueExprType(Context), CK_Dependent,
7174+
ParamType->isLValueReferenceType() ? VK_LValue
7175+
: ParamType->isRValueReferenceType() ? VK_XValue
7176+
: VK_PRValue);
7177+
if (E.isInvalid())
7178+
return ExprError();
7179+
setDeductionArg(E.get());
7180+
}
71557181
SugaredConverted = TemplateArgument(Arg, /*IsCanonical=*/false);
71567182
CanonicalConverted = TemplateArgument(
71577183
Context.getCanonicalTemplateArgument(SugaredConverted));
@@ -8555,6 +8581,7 @@ static SourceRange findTemplateParameter(unsigned Depth, TypeLoc TL) {
85558581
static bool CheckNonTypeTemplatePartialSpecializationArgs(
85568582
Sema &S, SourceLocation TemplateNameLoc, NonTypeTemplateParmDecl *Param,
85578583
const TemplateArgument *Args, unsigned NumArgs, bool IsDefaultArgument) {
8584+
bool HasError = false;
85588585
for (unsigned I = 0; I != NumArgs; ++I) {
85598586
if (Args[I].getKind() == TemplateArgument::Pack) {
85608587
if (CheckNonTypeTemplatePartialSpecializationArgs(
@@ -8569,6 +8596,10 @@ static bool CheckNonTypeTemplatePartialSpecializationArgs(
85698596
continue;
85708597

85718598
Expr *ArgExpr = Args[I].getAsExpr();
8599+
if (ArgExpr->containsErrors()) {
8600+
HasError = true;
8601+
continue;
8602+
}
85728603

85738604
// We can have a pack expansion of any of the bullets below.
85748605
if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(ArgExpr))
@@ -8638,7 +8669,7 @@ static bool CheckNonTypeTemplatePartialSpecializationArgs(
86388669
}
86398670
}
86408671

8641-
return false;
8672+
return HasError;
86428673
}
86438674

86448675
bool Sema::CheckTemplatePartialSpecializationArgs(

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5262,18 +5262,6 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *Init, QualType &Result,
52625262
SmallVector<DeducedTemplateArgument, 1> Deduced;
52635263
Deduced.resize(1);
52645264

5265-
// If deduction failed, don't diagnose if the initializer is dependent; it
5266-
// might acquire a matching type in the instantiation.
5267-
auto DeductionFailed = [&](TemplateDeductionResult TDK) {
5268-
if (Init->isTypeDependent()) {
5269-
Result =
5270-
SubstituteDeducedTypeTransform(*this, DependentResult).Apply(Type);
5271-
assert(!Result.isNull() && "substituting DependentTy can't fail");
5272-
return TemplateDeductionResult::Success;
5273-
}
5274-
return TDK;
5275-
};
5276-
52775265
SmallVector<OriginalCallArg, 4> OriginalCallArgs;
52785266

52795267
QualType DeducedType;
@@ -5323,9 +5311,9 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *Init, QualType &Result,
53235311
Diag(Info.getLocation(), diag::err_auto_inconsistent_deduction)
53245312
<< Info.FirstArg << Info.SecondArg << DeducedFromInitRange
53255313
<< Init->getSourceRange();
5326-
return DeductionFailed(TemplateDeductionResult::AlreadyDiagnosed);
5314+
return TemplateDeductionResult::AlreadyDiagnosed;
53275315
}
5328-
return DeductionFailed(TDK);
5316+
return TDK;
53295317
}
53305318

53315319
if (DeducedFromInitRange.isInvalid() &&
@@ -5347,12 +5335,12 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *Init, QualType &Result,
53475335
OriginalCallArgs,
53485336
/*Decomposed=*/false, /*ArgIdx=*/0, /*TDF=*/0, FailedTSC);
53495337
TDK != TemplateDeductionResult::Success)
5350-
return DeductionFailed(TDK);
5338+
return TDK;
53515339
}
53525340

53535341
// Could be null if somehow 'auto' appears in a non-deduced context.
53545342
if (Deduced[0].getKind() != TemplateArgument::Type)
5355-
return DeductionFailed(TemplateDeductionResult::Incomplete);
5343+
return TemplateDeductionResult::Incomplete;
53565344
DeducedType = Deduced[0].getAsType();
53575345

53585346
if (InitList) {
@@ -5366,7 +5354,7 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *Init, QualType &Result,
53665354
if (!Context.hasSameType(DeducedType, Result)) {
53675355
Info.FirstArg = Result;
53685356
Info.SecondArg = DeducedType;
5369-
return DeductionFailed(TemplateDeductionResult::Inconsistent);
5357+
return TemplateDeductionResult::Inconsistent;
53705358
}
53715359
DeducedType = Context.getCommonSugaredType(Result, DeducedType);
53725360
}
@@ -5390,7 +5378,7 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *Init, QualType &Result,
53905378
CheckOriginalCallArgDeduction(*this, Info, OriginalArg, DeducedA);
53915379
TDK != TemplateDeductionResult::Success) {
53925380
Result = QualType();
5393-
return DeductionFailed(TDK);
5381+
return TDK;
53945382
}
53955383
}
53965384

@@ -5412,13 +5400,17 @@ TypeSourceInfo *Sema::SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto,
54125400
}
54135401

54145402
QualType Sema::SubstAutoTypeDependent(QualType TypeWithAuto) {
5415-
return SubstituteDeducedTypeTransform(*this, DependentAuto{false})
5403+
return SubstituteDeducedTypeTransform(
5404+
*this,
5405+
DependentAuto{/*IsPack=*/isa<PackExpansionType>(TypeWithAuto)})
54165406
.TransformType(TypeWithAuto);
54175407
}
54185408

54195409
TypeSourceInfo *
54205410
Sema::SubstAutoTypeSourceInfoDependent(TypeSourceInfo *TypeWithAuto) {
5421-
return SubstituteDeducedTypeTransform(*this, DependentAuto{false})
5411+
return SubstituteDeducedTypeTransform(
5412+
*this, DependentAuto{/*IsPack=*/isa<PackExpansionType>(
5413+
TypeWithAuto->getType())})
54225414
.TransformType(TypeWithAuto);
54235415
}
54245416

0 commit comments

Comments
 (0)