Skip to content

Commit 2d225ae

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merge llvm/main into amd-debug
2 parents 94ce1b8 + 1739a0e commit 2d225ae

39 files changed

+1322
-383
lines changed

clang/include/clang/AST/TemplateName.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,17 @@ class TemplateName {
335335
/// structure, if any.
336336
QualifiedTemplateName *getAsQualifiedTemplateName() const;
337337

338-
/// Retrieve the underlying qualified template name,
339-
/// looking through underlying nodes.
340-
QualifiedTemplateName *getAsAdjustedQualifiedTemplateName() const;
341-
342338
/// Retrieve the underlying dependent template name
343339
/// structure, if any.
344340
DependentTemplateName *getAsDependentTemplateName() const;
345341

346-
// Retrieve the qualifier stored in either a underlying DependentTemplateName
347-
// or QualifiedTemplateName.
348-
NestedNameSpecifier getQualifier() const;
342+
// Retrieve the qualifier and template keyword stored in either a underlying
343+
// DependentTemplateName or QualifiedTemplateName.
344+
std::tuple<NestedNameSpecifier, bool> getQualifierAndTemplateKeyword() const;
345+
346+
NestedNameSpecifier getQualifier() const {
347+
return std::get<0>(getQualifierAndTemplateKeyword());
348+
}
349349

350350
/// Retrieve the using shadow declaration through which the underlying
351351
/// template declaration is introduced, if any.

clang/include/clang/AST/TypeLoc.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,11 +1872,10 @@ class TemplateSpecializationTypeLoc :
18721872
if (!getLocalData()->QualifierData)
18731873
return NestedNameSpecifierLoc();
18741874

1875-
auto *QTN =
1876-
getTypePtr()->getTemplateName().getAsAdjustedQualifiedTemplateName();
1877-
assert(QTN && "missing qualification");
1878-
return NestedNameSpecifierLoc(QTN->getQualifier(),
1879-
getLocalData()->QualifierData);
1875+
NestedNameSpecifier Qualifier =
1876+
getTypePtr()->getTemplateName().getQualifier();
1877+
assert(Qualifier && "missing qualification");
1878+
return NestedNameSpecifierLoc(Qualifier, getLocalData()->QualifierData);
18801879
}
18811880

18821881
SourceLocation getTemplateKeywordLoc() const {
@@ -2503,10 +2502,9 @@ class DeducedTemplateSpecializationTypeLoc
25032502
void *Data = getLocalData()->QualifierData;
25042503
if (!Data)
25052504
return NestedNameSpecifierLoc();
2506-
NestedNameSpecifier Qualifier = getTypePtr()
2507-
->getTemplateName()
2508-
.getAsAdjustedQualifiedTemplateName()
2509-
->getQualifier();
2505+
NestedNameSpecifier Qualifier =
2506+
getTypePtr()->getTemplateName().getQualifier();
2507+
assert(Qualifier && "missing qualification");
25102508
return NestedNameSpecifierLoc(Qualifier, Data);
25112509
}
25122510

@@ -2521,10 +2519,7 @@ class DeducedTemplateSpecializationTypeLoc
25212519
}
25222520

25232521
assert(QualifierLoc.getNestedNameSpecifier() ==
2524-
getTypePtr()
2525-
->getTemplateName()
2526-
.getAsAdjustedQualifiedTemplateName()
2527-
->getQualifier() &&
2522+
getTypePtr()->getTemplateName().getQualifier() &&
25282523
"Inconsistent nested-name-specifier pointer");
25292524
getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
25302525
}

clang/lib/AST/ASTContext.cpp

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5474,18 +5474,15 @@ TagType *ASTContext::getTagTypeInternal(ElaboratedTypeKeyword Keyword,
54745474
return T;
54755475
}
54765476

5477-
static bool getNonInjectedClassName(const TagDecl *&TD) {
5477+
static const TagDecl *getNonInjectedClassName(const TagDecl *TD) {
54785478
if (const auto *RD = dyn_cast<CXXRecordDecl>(TD);
5479-
RD && RD->isInjectedClassName()) {
5480-
TD = cast<TagDecl>(RD->getDeclContext());
5481-
return true;
5482-
}
5483-
return false;
5479+
RD && RD->isInjectedClassName())
5480+
return cast<TagDecl>(RD->getDeclContext());
5481+
return TD;
54845482
}
54855483

54865484
CanQualType ASTContext::getCanonicalTagType(const TagDecl *TD) const {
5487-
::getNonInjectedClassName(TD);
5488-
TD = TD->getCanonicalDecl();
5485+
TD = ::getNonInjectedClassName(TD)->getCanonicalDecl();
54895486
if (TD->TypeForDecl)
54905487
return TD->TypeForDecl->getCanonicalTypeUnqualified();
54915488

@@ -5501,40 +5498,42 @@ CanQualType ASTContext::getCanonicalTagType(const TagDecl *TD) const {
55015498
QualType ASTContext::getTagType(ElaboratedTypeKeyword Keyword,
55025499
NestedNameSpecifier Qualifier,
55035500
const TagDecl *TD, bool OwnsTag) const {
5501+
5502+
const TagDecl *NonInjectedTD = ::getNonInjectedClassName(TD);
5503+
bool IsInjected = TD != NonInjectedTD;
5504+
55045505
ElaboratedTypeKeyword PreferredKeyword =
5505-
getLangOpts().CPlusPlus
5506-
? ElaboratedTypeKeyword::None
5507-
: KeywordHelpers::getKeywordForTagTypeKind(TD->getTagKind());
5506+
getLangOpts().CPlusPlus ? ElaboratedTypeKeyword::None
5507+
: KeywordHelpers::getKeywordForTagTypeKind(
5508+
NonInjectedTD->getTagKind());
55085509

55095510
if (Keyword == PreferredKeyword && !Qualifier && !OwnsTag) {
55105511
if (const Type *T = TD->TypeForDecl; T && !T->isCanonicalUnqualified())
55115512
return QualType(T, 0);
55125513

5513-
bool IsInjected = ::getNonInjectedClassName(TD);
5514-
const Type *CanonicalType = getCanonicalTagType(TD).getTypePtr();
5514+
const Type *CanonicalType = getCanonicalTagType(NonInjectedTD).getTypePtr();
55155515
const Type *T =
55165516
getTagTypeInternal(Keyword,
5517-
/*Qualifier=*/std::nullopt, TD,
5517+
/*Qualifier=*/std::nullopt, NonInjectedTD,
55185518
/*OwnsTag=*/false, IsInjected, CanonicalType,
55195519
/*WithFoldingSetNode=*/false);
55205520
TD->TypeForDecl = T;
55215521
return QualType(T, 0);
55225522
}
55235523

5524-
bool IsInjected = ::getNonInjectedClassName(TD);
5525-
55265524
llvm::FoldingSetNodeID ID;
5527-
TagTypeFoldingSetPlaceholder::Profile(ID, Keyword, Qualifier, TD, OwnsTag,
5528-
IsInjected);
5525+
TagTypeFoldingSetPlaceholder::Profile(ID, Keyword, Qualifier, NonInjectedTD,
5526+
OwnsTag, IsInjected);
55295527

55305528
void *InsertPos = nullptr;
55315529
if (TagTypeFoldingSetPlaceholder *T =
55325530
TagTypes.FindNodeOrInsertPos(ID, InsertPos))
55335531
return QualType(T->getTagType(), 0);
55345532

5535-
const Type *CanonicalType = getCanonicalTagType(TD).getTypePtr();
5536-
TagType *T = getTagTypeInternal(Keyword, Qualifier, TD, OwnsTag, IsInjected,
5537-
CanonicalType, /*WithFoldingSetNode=*/true);
5533+
const Type *CanonicalType = getCanonicalTagType(NonInjectedTD).getTypePtr();
5534+
TagType *T =
5535+
getTagTypeInternal(Keyword, Qualifier, NonInjectedTD, OwnsTag, IsInjected,
5536+
CanonicalType, /*WithFoldingSetNode=*/true);
55385537
TagTypes.InsertNode(TagTypeFoldingSetPlaceholder::fromTagType(T), InsertPos);
55395538
return QualType(T, 0);
55405539
}
@@ -10447,6 +10446,12 @@ TemplateName ASTContext::getQualifiedTemplateName(NestedNameSpecifier Qualifier,
1044710446
assert(Template.getKind() == TemplateName::Template ||
1044810447
Template.getKind() == TemplateName::UsingTemplate);
1044910448

10449+
if (Template.getAsTemplateDecl()->getKind() == Decl::TemplateTemplateParm) {
10450+
assert(!Qualifier && "unexpected qualified template template parameter");
10451+
assert(TemplateKeyword == false);
10452+
return Template;
10453+
}
10454+
1045010455
// FIXME: Canonicalization?
1045110456
llvm::FoldingSetNodeID ID;
1045210457
QualifiedTemplateName::Profile(ID, Qualifier, TemplateKeyword, Template);

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5230,6 +5230,12 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
52305230
const Function *Func = getFunction(FuncDecl);
52315231
if (!Func)
52325232
return false;
5233+
5234+
// In error cases, the function may be called with fewer arguments than
5235+
// parameters.
5236+
if (E->getNumArgs() < Func->getNumWrittenParams())
5237+
return false;
5238+
52335239
assert(HasRVO == Func->hasRVO());
52345240

52355241
bool HasQualifier = false;

clang/lib/AST/ByteCode/EvaluationResult.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ bool EvaluationResult::checkFullyInitialized(InterpState &S,
178178
static void collectBlocks(const Pointer &Ptr,
179179
llvm::SetVector<const Block *> &Blocks) {
180180
auto isUsefulPtr = [](const Pointer &P) -> bool {
181-
return P.isLive() && !P.isZero() && !P.isDummy() && P.isDereferencable() &&
182-
!P.isUnknownSizeArray() && !P.isOnePastEnd();
181+
return P.isLive() && P.isBlockPointer() && !P.isZero() && !P.isDummy() &&
182+
P.isDereferencable() && !P.isUnknownSizeArray() && !P.isOnePastEnd();
183183
};
184184

185185
if (!isUsefulPtr(Ptr))

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,11 @@ std::optional<APValue> Pointer::toRValue(const Context &Ctx,
785785

786786
// Complex types.
787787
if (const auto *CT = Ty->getAs<ComplexType>()) {
788-
QualType ElemTy = CT->getElementType();
788+
// Can happen via C casts.
789+
if (!Ptr.getFieldDesc()->isPrimitiveArray())
790+
return false;
789791

792+
QualType ElemTy = CT->getElementType();
790793
if (ElemTy->isIntegerType()) {
791794
OptPrimType ElemT = Ctx.classify(ElemTy);
792795
assert(ElemT);

0 commit comments

Comments
 (0)