Skip to content

Commit c7b678d

Browse files
cor3ntinpradt2
authored andcommitted
Revert "[clang] fix broken canonicalization of DeducedTemplateSpecializationType (llvm#95202)"
This reverts commit 2e1ad93. Reverting llvm#95202 in the 19.x branch Fixes llvm#106182 The change in llvm#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 llvm#95202 in the 19x branch, fixing the regression and preserving the 18.x behavior (which is GCC's behavior) llvm#106335 (comment)
1 parent d59a51e commit c7b678d

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
@@ -1888,13 +1888,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
18881888
QualType DeducedType,
18891889
bool IsDependent) const;
18901890

1891-
private:
1892-
QualType getDeducedTemplateSpecializationTypeInternal(TemplateName Template,
1893-
QualType DeducedType,
1894-
bool IsDependent,
1895-
QualType Canon) const;
1896-
1897-
public:
18981891
/// Return the unique reference to the type for the specified TagDecl
18991892
/// (struct/union/class/enum) decl.
19001893
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
@@ -380,9 +380,7 @@ class TemplateName {
380380
/// error.
381381
void dump() const;
382382

383-
void Profile(llvm::FoldingSetNodeID &ID) {
384-
ID.AddPointer(Storage.getOpaqueValue());
385-
}
383+
void Profile(llvm::FoldingSetNodeID &ID);
386384

387385
/// Retrieve the template name as a void pointer.
388386
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
@@ -6615,27 +6615,30 @@ class DeducedTemplateSpecializationType : public DeducedType,
66156615

66166616
DeducedTemplateSpecializationType(TemplateName Template,
66176617
QualType DeducedAsType,
6618-
bool IsDeducedAsDependent, QualType Canon)
6618+
bool IsDeducedAsDependent)
66196619
: DeducedType(DeducedTemplateSpecialization, DeducedAsType,
66206620
toTypeDependence(Template.getDependence()) |
66216621
(IsDeducedAsDependent
66226622
? TypeDependence::DependentInstantiation
66236623
: TypeDependence::None),
6624-
Canon),
6624+
DeducedAsType.isNull() ? QualType(this, 0)
6625+
: DeducedAsType.getCanonicalType()),
66256626
Template(Template) {}
66266627

66276628
public:
66286629
/// Retrieve the name of the template that we are deducing.
66296630
TemplateName getTemplateName() const { return Template;}
66306631

6631-
void Profile(llvm::FoldingSetNodeID &ID) const {
6632+
void Profile(llvm::FoldingSetNodeID &ID) {
66326633
Profile(ID, getTemplateName(), getDeducedType(), isDependentType());
66336634
}
66346635

66356636
static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template,
66366637
QualType Deduced, bool IsDependent) {
66376638
Template.Profile(ID);
6638-
Deduced.Profile(ID);
6639+
QualType CanonicalType =
6640+
Deduced.isNull() ? Deduced : Deduced.getCanonicalType();
6641+
ID.AddPointer(CanonicalType.getAsOpaquePtr());
66396642
ID.AddBoolean(IsDependent || Template.isDependent());
66406643
}
66416644

clang/lib/AST/ASTContext.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6509,9 +6509,11 @@ QualType ASTContext::getUnconstrainedType(QualType T) const {
65096509
return T;
65106510
}
65116511

6512-
QualType ASTContext::getDeducedTemplateSpecializationTypeInternal(
6513-
TemplateName Template, QualType DeducedType, bool IsDependent,
6514-
QualType Canon) const {
6512+
/// Return the uniqued reference to the deduced template specialization type
6513+
/// which has been deduced to the given type, or to the canonical undeduced
6514+
/// such type, or the canonical deduced-but-dependent such type.
6515+
QualType ASTContext::getDeducedTemplateSpecializationType(
6516+
TemplateName Template, QualType DeducedType, bool IsDependent) const {
65156517
// Look in the folding set for an existing type.
65166518
void *InsertPos = nullptr;
65176519
llvm::FoldingSetNodeID ID;
@@ -6522,8 +6524,7 @@ QualType ASTContext::getDeducedTemplateSpecializationTypeInternal(
65226524
return QualType(DTST, 0);
65236525

65246526
auto *DTST = new (*this, alignof(DeducedTemplateSpecializationType))
6525-
DeducedTemplateSpecializationType(Template, DeducedType, IsDependent,
6526-
Canon);
6527+
DeducedTemplateSpecializationType(Template, DeducedType, IsDependent);
65276528
llvm::FoldingSetNodeID TempID;
65286529
DTST->Profile(TempID);
65296530
assert(ID == TempID && "ID does not match");
@@ -6532,20 +6533,6 @@ QualType ASTContext::getDeducedTemplateSpecializationTypeInternal(
65326533
return QualType(DTST, 0);
65336534
}
65346535

6535-
/// Return the uniqued reference to the deduced template specialization type
6536-
/// which has been deduced to the given type, or to the canonical undeduced
6537-
/// such type, or the canonical deduced-but-dependent such type.
6538-
QualType ASTContext::getDeducedTemplateSpecializationType(
6539-
TemplateName Template, QualType DeducedType, bool IsDependent) const {
6540-
QualType Canon = DeducedType.isNull()
6541-
? getDeducedTemplateSpecializationTypeInternal(
6542-
getCanonicalTemplateName(Template), QualType(),
6543-
IsDependent, QualType())
6544-
: DeducedType.getCanonicalType();
6545-
return getDeducedTemplateSpecializationTypeInternal(Template, DeducedType,
6546-
IsDependent, Canon);
6547-
}
6548-
65496536
/// getAtomicType - Return the uniqued reference to the atomic type for
65506537
/// the given value type.
65516538
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
@@ -350,6 +350,15 @@ bool TemplateName::containsUnexpandedParameterPack() const {
350350
return getDependence() & TemplateNameDependence::UnexpandedPack;
351351
}
352352

353+
void TemplateName::Profile(llvm::FoldingSetNodeID &ID) {
354+
if (const auto* USD = getAsUsingShadowDecl())
355+
ID.AddPointer(USD->getCanonicalDecl());
356+
else if (const auto *TD = getAsTemplateDecl())
357+
ID.AddPointer(TD->getCanonicalDecl());
358+
else
359+
ID.AddPointer(Storage.getOpaqueValue());
360+
}
361+
353362
void TemplateName::print(raw_ostream &OS, const PrintingPolicy &Policy,
354363
Qualified Qual) const {
355364
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
@@ -32,7 +32,6 @@ add_clang_unittest(ASTTests
3232
EvaluateAsRValueTest.cpp
3333
ExternalASTSourceTest.cpp
3434
NamedDeclPrinterTest.cpp
35-
ProfilingTest.cpp
3635
RandstructTest.cpp
3736
RawCommentForDeclTest.cpp
3837
RecursiveASTVisitorTest.cpp

clang/unittests/AST/ProfilingTest.cpp

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

0 commit comments

Comments
 (0)