[clang] [Clang] Fix build of PackIndexingTypeLocs (PR #232194)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 14 23:22:34 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Younan Zhang (zyn0217)
<details>
<summary>Changes</summary>
Their typelocs were not built correctly.
This helps fix the issue as reported in https://github.com/llvm/llvm-project/pull/231191
Assisted-by: LLDB and my hands
---
Full diff: https://github.com/llvm/llvm-project/pull/232194.diff
10 Files Affected:
- (modified) clang/include/clang/Sema/Sema.h (+5-7)
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+5-2)
- (modified) clang/lib/Parse/ParseExprCXX.cpp (+10-9)
- (modified) clang/lib/Sema/DeclSpec.cpp (+2-2)
- (modified) clang/lib/Sema/SemaCXXScopeSpec.cpp (+10-11)
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+3-3)
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+5-5)
- (modified) clang/lib/Sema/SemaType.cpp (+6-8)
- (modified) clang/lib/Sema/TreeTransform.h (+5-8)
- (modified) clang/test/SemaCXX/cxx2c-pack-indexing.cpp (+1-1)
``````````diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 711e083e4cedd..865defa98a1b3 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3505,10 +3505,9 @@ class Sema final : public SemaBase {
bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, const DeclSpec &DS,
SourceLocation ColonColonLoc);
- bool ActOnCXXNestedNameSpecifierIndexedPack(CXXScopeSpec &SS,
- const DeclSpec &DS,
- SourceLocation ColonColonLoc,
- QualType Type);
+ ParsedType ActOnCXXNestedNameSpecifierIndexedPack(
+ CXXScopeSpec &SS, const DeclSpec &DS, TypeSourceInfo *PatternLoc,
+ SourceLocation ColonColonLoc, QualType Type);
/// IsInvalidUnlessNestedName - This method is used for error recovery
/// purposes to determine whether the specified identifier is only valid as
@@ -15627,10 +15626,9 @@ class Sema final : public SemaBase {
QualType BuildDecltypeType(Expr *E, bool AsUnevaluated = true);
QualType ActOnPackIndexingType(QualType Pattern, Expr *IndexExpr,
- SourceLocation Loc,
- SourceLocation EllipsisLoc);
+ SourceLocation Loc);
QualType BuildPackIndexingType(QualType Pattern, Expr *IndexExpr,
- SourceLocation Loc, SourceLocation EllipsisLoc,
+ SourceLocation Loc,
bool FullySubstituted = false,
ArrayRef<QualType> Expansions = {});
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index aded5d96aa83f..4cf445d68bdbe 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1157,8 +1157,11 @@ SourceLocation Parser::ParsePackIndexingType(DeclSpec &DS) {
return Tok.getEndLoc();
}
- ParsedType Ty = Actions.getTypeName(*Tok.getIdentifierInfo(),
- Tok.getLocation(), getCurScope());
+ ParsedType Ty = Actions.getTypeName(
+ *Tok.getIdentifierInfo(), Tok.getLocation(), getCurScope(),
+ /*SS=*/nullptr, /*isClassName=*/false, /*HasTrailingDot=*/false,
+ /*ObjectType=*/nullptr, /*IsCtorOrDtorName=*/false,
+ /*WantNontrivialTypeSourceInfo=*/true);
if (!Ty) {
DS.SetTypeSpecError();
return Tok.getEndLoc();
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index ea71efc9c9358..5bb21e70b9d84 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -205,10 +205,10 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
if (DS.getTypeSpecType() == DeclSpec::TST_error)
return false;
- QualType Pattern = Sema::GetTypeFromParser(DS.getRepAsType());
- QualType Type =
- Actions.ActOnPackIndexingType(Pattern, DS.getPackIndexingExpr(),
- DS.getBeginLoc(), DS.getEllipsisLoc());
+ TypeSourceInfo *PatternTSI = nullptr;
+ QualType Pattern = Sema::GetTypeFromParser(DS.getRepAsType(), &PatternTSI);
+ QualType Type = Actions.ActOnPackIndexingType(
+ Pattern, DS.getPackIndexingExpr(), DS.getBeginLoc());
if (Type.isNull())
return false;
@@ -226,13 +226,14 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
getCurScope()->isFunctionDeclarationScope())
Diag(Start, diag::warn_pre_cxx26_ambiguous_pack_indexing_type) << Type;
- if (!TryConsumeToken(tok::coloncolon, CCLoc)) {
- AnnotateExistingIndexedTypeNamePack(ParsedType::make(Type), Start,
- EndLoc);
+ TryConsumeToken(tok::coloncolon, CCLoc);
+ ParsedType T = Actions.ActOnCXXNestedNameSpecifierIndexedPack(
+ SS, DS, PatternTSI, CCLoc, Type);
+ if (CCLoc.isInvalid()) {
+ AnnotateExistingIndexedTypeNamePack(T, Start, EndLoc);
return false;
}
- if (Actions.ActOnCXXNestedNameSpecifierIndexedPack(SS, DS, CCLoc,
- std::move(Type)))
+ if (!T)
SS.SetInvalid(SourceRange(Start, CCLoc));
HasScopeSpecifier = true;
}
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 1bc3bb45dc897..ef174b3337171 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -779,8 +779,8 @@ bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc,
// we got there from a an annotation. Reconstruct the type
// Ugly...
QualType QT = Rep.get();
- const PackIndexingType *LIT = cast<PackIndexingType>(QT);
- TypeRep = ParsedType::make(LIT->getPattern());
+ const PackIndexingType *LIT =
+ cast<PackIndexingType>(cast<LocInfoType>(QT)->getType());
PackIndexingExpr = LIT->getIndexExpr();
}
return false;
diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index 8a8636ac4c4a6..5c365de430831 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -853,28 +853,27 @@ bool Sema::ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS,
return false;
}
-bool Sema::ActOnCXXNestedNameSpecifierIndexedPack(CXXScopeSpec &SS,
- const DeclSpec &DS,
- SourceLocation ColonColonLoc,
- QualType Type) {
+ParsedType Sema::ActOnCXXNestedNameSpecifierIndexedPack(
+ CXXScopeSpec &SS, const DeclSpec &DS, TypeSourceInfo *PatternLoc,
+ SourceLocation ColonColonLoc, QualType Type) {
if (SS.isInvalid() || DS.getTypeSpecType() == DeclSpec::TST_error)
- return true;
+ return ParsedType();
assert(DS.getTypeSpecType() == DeclSpec::TST_typename_pack_indexing);
if (Type.isNull())
- return true;
+ return ParsedType();
assert(SS.isEmpty());
TypeLocBuilder TLB;
- TLB.pushTrivial(getASTContext(),
- cast<PackIndexingType>(Type.getTypePtr())->getPattern(),
- DS.getBeginLoc());
+ TLB.pushFullCopy(PatternLoc->getTypeLoc());
PackIndexingTypeLoc PIT = TLB.push<PackIndexingTypeLoc>(Type);
PIT.setEllipsisLoc(DS.getEllipsisLoc());
- SS.Make(Context, TLB.getTypeLocInContext(Context, Type), ColonColonLoc);
- return false;
+ TypeSourceInfo *TSI = TLB.getTypeSourceInfo(Context, Type);
+ if (ColonColonLoc.isValid())
+ SS.Make(Context, TSI->getTypeLoc(), ColonColonLoc);
+ return CreateParsedType(Type, TSI);
}
bool Sema::IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS,
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index f80fb2a3446b3..cd9771526bee3 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -4535,9 +4535,9 @@ Sema::BuildMemInitializer(Decl *ConstructorD,
Diag(DS.getTypeSpecTypeLoc(), diag::err_decltype_auto_invalid);
return true;
} else if (DS.getTypeSpecType() == TST_typename_pack_indexing) {
- BaseType =
- BuildPackIndexingType(DS.getRepAsType().get(), DS.getPackIndexingExpr(),
- DS.getBeginLoc(), DS.getEllipsisLoc());
+ BaseType = GetTypeFromParser(DS.getRepAsType(), &TInfo);
+ if (BaseType.isNull())
+ return true;
} else {
LookupResult R(*this, MemberOrBase, IdLoc, LookupOrdinaryName);
LookupParsedName(R, S, &SS, /*ObjectType=*/QualType());
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d9bd060f7a0bf..dd737ba3ce248 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -7548,11 +7548,11 @@ ExprResult Sema::ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
break;
}
case DeclSpec::TST_typename_pack_indexing: {
- T = ActOnPackIndexingType(DS.getRepAsType().get(), DS.getPackIndexingExpr(),
- DS.getBeginLoc(), DS.getEllipsisLoc());
- TLB.pushTrivial(getASTContext(),
- cast<PackIndexingType>(T.getTypePtr())->getPattern(),
- DS.getBeginLoc());
+ TypeSourceInfo *TSI = nullptr;
+ T = GetTypeFromParser(DS.getRepAsType(), &TSI);
+ T = ActOnPackIndexingType(T, DS.getPackIndexingExpr(),
+ DS.getBeginLoc());
+ TLB.pushFullCopy(TSI->getTypeLoc());
PackIndexingTypeLoc PITL = TLB.push<PackIndexingTypeLoc>(T);
PITL.setEllipsisLoc(DS.getEllipsisLoc());
break;
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 1cb96b556971a..c5f7b6b4b4065 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1300,9 +1300,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
case DeclSpec::TST_typename_pack_indexing: {
Expr *E = DS.getPackIndexingExpr();
assert(E && "Didn't get an expression for pack indexing");
- QualType Pattern = S.GetTypeFromParser(DS.getRepAsType());
- Result = S.BuildPackIndexingType(Pattern, E, DS.getBeginLoc(),
- DS.getEllipsisLoc());
+ Result = S.GetTypeFromParser(DS.getRepAsType());
if (Result.isNull()) {
declarator.setInvalidType(true);
Result = Context.IntTy;
@@ -6121,7 +6119,9 @@ namespace {
}
void VisitPackIndexingTypeLoc(PackIndexingTypeLoc TL) {
assert(DS.getTypeSpecType() == DeclSpec::TST_typename_pack_indexing);
- TL.setEllipsisLoc(DS.getEllipsisLoc());
+ TypeSourceInfo *TInfo = nullptr;
+ Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo);
+ TL.copy(TInfo->getTypeLoc());
}
void VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
assert(DS.isTransformTypeTrait(DS.getTypeSpecType()));
@@ -10185,8 +10185,7 @@ QualType Sema::BuildDecltypeType(Expr *E, bool AsUnevaluated) {
}
QualType Sema::ActOnPackIndexingType(QualType Pattern, Expr *IndexExpr,
- SourceLocation Loc,
- SourceLocation EllipsisLoc) {
+ SourceLocation Loc) {
if (!IndexExpr)
return QualType();
@@ -10194,7 +10193,7 @@ QualType Sema::ActOnPackIndexingType(QualType Pattern, Expr *IndexExpr,
if (!Pattern->containsUnexpandedParameterPack())
Diag(Loc, diag::err_expected_name_of_pack) << Pattern;
- QualType Type = BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc);
+ QualType Type = BuildPackIndexingType(Pattern, IndexExpr, Loc);
if (!Type.isNull())
DiagCompat(Loc, diag_compat::pack_indexing);
@@ -10203,7 +10202,6 @@ QualType Sema::ActOnPackIndexingType(QualType Pattern, Expr *IndexExpr,
QualType Sema::BuildPackIndexingType(QualType Pattern, Expr *IndexExpr,
SourceLocation Loc,
- SourceLocation EllipsisLoc,
bool FullySubstituted,
ArrayRef<QualType> Expansions) {
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 73367d6bea063..7f56a29e72909 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -1138,7 +1138,6 @@ class TreeTransform {
QualType RebuildPackIndexingType(QualType Pattern, Expr *IndexExpr,
SourceLocation Loc,
- SourceLocation EllipsisLoc,
bool FullySubstituted,
ArrayRef<QualType> Expansions = {});
@@ -7287,8 +7286,7 @@ TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB,
if (NotYetExpanded) {
FullySubstituted = false;
QualType Out = getDerived().RebuildPackIndexingType(
- Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
- FullySubstituted);
+ Pack, IndexExpr.get(), TL.getBeginLoc(), FullySubstituted);
if (Out.isNull())
return QualType();
@@ -7326,8 +7324,8 @@ TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB,
QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
QualType Out = getDerived().RebuildPackIndexingType(
- Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
- FullySubstituted, SubtitutedTypes);
+ Result, IndexExpr.get(), TL.getBeginLoc(), FullySubstituted,
+ SubtitutedTypes);
if (Out.isNull())
return Out;
@@ -18339,9 +18337,8 @@ QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, SourceLocation) {
template <typename Derived>
QualType TreeTransform<Derived>::RebuildPackIndexingType(
QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
- SourceLocation EllipsisLoc, bool FullySubstituted,
- ArrayRef<QualType> Expansions) {
- return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
+ bool FullySubstituted, ArrayRef<QualType> Expansions) {
+ return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc,
FullySubstituted, Expansions);
}
diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
index 0892394955a60..bbd708d3b63f5 100644
--- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
+++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
@@ -370,7 +370,7 @@ void foo(auto...x){
//expected-error at -1 {{invalid index 4294967296 for pack 'x' of size 1}}
using T1 = T...[(__int128)18446744073709551615U+1];
- // expected-warning at -1 3{{implicit conversion from '__int128' to '__size_t'}}
+ // expected-warning at -1 2{{implicit conversion from '__int128' to '__size_t'}}
// expected-error at -2 2{{evaluates to 18446744073709551616, which cannot be narrowed to type '__size_t' (aka 'unsigned long')}}
}
int test(){
``````````
</details>
https://github.com/llvm/llvm-project/pull/232194
More information about the cfe-commits
mailing list