Skip to content

Commit 03cc174

Browse files
cor3ntintru
authored andcommitted
Revert "[clang] fix broken canonicalization of DeducedTemplateSpecializationType (#95202)"
This reverts commit 2e1ad93. Reverting #95202 in the 19.x branch Fixes #106182 The change in #95202 causes code to crash and there is no good way to backport a fix for that as there are ABI-impacting changes at play. Instead we revert #95202 in the 19x branch, fixing the regression and preserving the 18.x behavior (which is GCC's behavior) #106335 (comment)
1 parent c8c66e0 commit 03cc174

File tree

7 files changed

+23
-109
lines changed

7 files changed

+23
-109
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,13 +1805,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
18051805
QualType DeducedType,
18061806
bool IsDependent) const;
18071807

1808-
private:
1809-
QualType getDeducedTemplateSpecializationTypeInternal(TemplateName Template,
1810-
QualType DeducedType,
1811-
bool IsDependent,
1812-
QualType Canon) const;
1813-
1814-
public:
18151808
/// Return the unique reference to the type for the specified TagDecl
18161809
/// (struct/union/class/enum) decl.
18171810
QualType getTagDeclType(const TagDecl *Decl) const;

clang/include/clang/AST/TemplateName.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,7 @@ class TemplateName {
347347
/// error.
348348
void dump() const;
349349

350-
void Profile(llvm::FoldingSetNodeID &ID) {
351-
ID.AddPointer(Storage.getOpaqueValue());
352-
}
350+
void Profile(llvm::FoldingSetNodeID &ID);
353351

354352
/// Retrieve the template name as a void pointer.
355353
void *getAsVoidPointer() const { return Storage.getOpaqueValue(); }

clang/include/clang/AST/Type.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6421,27 +6421,30 @@ class DeducedTemplateSpecializationType : public DeducedType,
64216421

64226422
DeducedTemplateSpecializationType(TemplateName Template,
64236423
QualType DeducedAsType,
6424-
bool IsDeducedAsDependent, QualType Canon)
6424+
bool IsDeducedAsDependent)
64256425
: DeducedType(DeducedTemplateSpecialization, DeducedAsType,
64266426
toTypeDependence(Template.getDependence()) |
64276427
(IsDeducedAsDependent
64286428
? TypeDependence::DependentInstantiation
64296429
: TypeDependence::None),
6430-
Canon),
6430+
DeducedAsType.isNull() ? QualType(this, 0)
6431+
: DeducedAsType.getCanonicalType()),
64316432
Template(Template) {}
64326433

64336434
public:
64346435
/// Retrieve the name of the template that we are deducing.
64356436
TemplateName getTemplateName() const { return Template;}
64366437

6437-
void Profile(llvm::FoldingSetNodeID &ID) const {
6438+
void Profile(llvm::FoldingSetNodeID &ID) {
64386439
Profile(ID, getTemplateName(), getDeducedType(), isDependentType());
64396440
}
64406441

64416442
static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template,
64426443
QualType Deduced, bool IsDependent) {
64436444
Template.Profile(ID);
6444-
Deduced.Profile(ID);
6445+
QualType CanonicalType =
6446+
Deduced.isNull() ? Deduced : Deduced.getCanonicalType();
6447+
ID.AddPointer(CanonicalType.getAsOpaquePtr());
64456448
ID.AddBoolean(IsDependent || Template.isDependent());
64466449
}
64476450

clang/lib/AST/ASTContext.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6269,9 +6269,11 @@ QualType ASTContext::getUnconstrainedType(QualType T) const {
62696269
return T;
62706270
}
62716271

6272-
QualType ASTContext::getDeducedTemplateSpecializationTypeInternal(
6273-
TemplateName Template, QualType DeducedType, bool IsDependent,
6274-
QualType Canon) const {
6272+
/// Return the uniqued reference to the deduced template specialization type
6273+
/// which has been deduced to the given type, or to the canonical undeduced
6274+
/// such type, or the canonical deduced-but-dependent such type.
6275+
QualType ASTContext::getDeducedTemplateSpecializationType(
6276+
TemplateName Template, QualType DeducedType, bool IsDependent) const {
62756277
// Look in the folding set for an existing type.
62766278
void *InsertPos = nullptr;
62776279
llvm::FoldingSetNodeID ID;
@@ -6282,8 +6284,7 @@ QualType ASTContext::getDeducedTemplateSpecializationTypeInternal(
62826284
return QualType(DTST, 0);
62836285

62846286
auto *DTST = new (*this, alignof(DeducedTemplateSpecializationType))
6285-
DeducedTemplateSpecializationType(Template, DeducedType, IsDependent,
6286-
Canon);
6287+
DeducedTemplateSpecializationType(Template, DeducedType, IsDependent);
62876288
llvm::FoldingSetNodeID TempID;
62886289
DTST->Profile(TempID);
62896290
assert(ID == TempID && "ID does not match");
@@ -6292,20 +6293,6 @@ QualType ASTContext::getDeducedTemplateSpecializationTypeInternal(
62926293
return QualType(DTST, 0);
62936294
}
62946295

6295-
/// Return the uniqued reference to the deduced template specialization type
6296-
/// which has been deduced to the given type, or to the canonical undeduced
6297-
/// such type, or the canonical deduced-but-dependent such type.
6298-
QualType ASTContext::getDeducedTemplateSpecializationType(
6299-
TemplateName Template, QualType DeducedType, bool IsDependent) const {
6300-
QualType Canon = DeducedType.isNull()
6301-
? getDeducedTemplateSpecializationTypeInternal(
6302-
getCanonicalTemplateName(Template), QualType(),
6303-
IsDependent, QualType())
6304-
: DeducedType.getCanonicalType();
6305-
return getDeducedTemplateSpecializationTypeInternal(Template, DeducedType,
6306-
IsDependent, Canon);
6307-
}
6308-
63096296
/// getAtomicType - Return the uniqued reference to the atomic type for
63106297
/// the given value type.
63116298
QualType ASTContext::getAtomicType(QualType T) const {

clang/lib/AST/TemplateName.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,15 @@ bool TemplateName::containsUnexpandedParameterPack() const {
264264
return getDependence() & TemplateNameDependence::UnexpandedPack;
265265
}
266266

267+
void TemplateName::Profile(llvm::FoldingSetNodeID &ID) {
268+
if (const auto* USD = getAsUsingShadowDecl())
269+
ID.AddPointer(USD->getCanonicalDecl());
270+
else if (const auto *TD = getAsTemplateDecl())
271+
ID.AddPointer(TD->getCanonicalDecl());
272+
else
273+
ID.AddPointer(Storage.getOpaqueValue());
274+
}
275+
267276
void TemplateName::print(raw_ostream &OS, const PrintingPolicy &Policy,
268277
Qualified Qual) const {
269278
auto handleAnonymousTTP = [](TemplateDecl *TD, raw_ostream &OS) {

clang/unittests/AST/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ add_clang_unittest(ASTTests
3131
EvaluateAsRValueTest.cpp
3232
ExternalASTSourceTest.cpp
3333
NamedDeclPrinterTest.cpp
34-
ProfilingTest.cpp
3534
RandstructTest.cpp
3635
RecursiveASTVisitorTest.cpp
3736
SizelessTypesTest.cpp

clang/unittests/AST/ProfilingTest.cpp

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)