Skip to content

Commit 72fd9e6

Browse files
mizvekovahatanaka
authored andcommitted
[clang] implement common sugared type of inst-dependent DecltypeType (llvm#67739)
While a DecltypeType node itself is not uniqued, an instantiation dependent DecltypeType will have a DependentDecltypeType as an underlying type, which is uniqued. In that case, there can be non-identical non-sugar DecltypeTypes nodes which nonetheless represent the same type. Fixes llvm#67603 (cherry picked from commit 06721bb) Conflicts: clang/docs/ReleaseNotes.rst
1 parent 99ba00a commit 72fd9e6

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,9 @@ Bug Fixes in This Version
743743
- Clang now accepts anonymous members initialized with designated initializers
744744
inside templates.
745745
Fixes (`#65143 <https://github.com/llvm/llvm-project/issues/65143>`_)
746+
- Fixes crash when trying to obtain the common sugared type of
747+
`decltype(instantiation-dependent-expr)`.
748+
Fixes (`#67603 <https://github.com/llvm/llvm-project/issues/67603>`_)
746749

747750
Bug Fixes to Compiler Builtins
748751
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/ASTContext.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12632,7 +12632,6 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,
1263212632

1263312633
#define SUGAR_FREE_TYPE(Class) UNEXPECTED_TYPE(Class, "sugar-free")
1263412634
SUGAR_FREE_TYPE(Builtin)
12635-
SUGAR_FREE_TYPE(Decltype)
1263612635
SUGAR_FREE_TYPE(DeducedTemplateSpecialization)
1263712636
SUGAR_FREE_TYPE(DependentBitInt)
1263812637
SUGAR_FREE_TYPE(Enum)
@@ -12862,6 +12861,14 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,
1286212861
TY->getTemplateName()),
1286312862
As, X->getCanonicalTypeInternal());
1286412863
}
12864+
case Type::Decltype: {
12865+
const auto *DX = cast<DecltypeType>(X), *DY = cast<DecltypeType>(Y);
12866+
assert(DX->isDependentType());
12867+
assert(DY->isDependentType());
12868+
assert(Ctx.hasSameExpr(DX->getUnderlyingExpr(), DY->getUnderlyingExpr()));
12869+
// As Decltype is not uniqued, building a common type would be wasteful.
12870+
return QualType(DX, 0);
12871+
}
1286512872
case Type::DependentName: {
1286612873
const auto *NX = cast<DependentNameType>(X),
1286712874
*NY = cast<DependentNameType>(Y);

clang/test/SemaCXX/sugar-common-types.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,14 @@ namespace PR61419 {
142142
extern const pair<id, id> p;
143143
id t = false ? p.first : p.second;
144144
} // namespace PR61419
145+
146+
namespace GH67603 {
147+
template <class> using A = long;
148+
template <class B> void h() {
149+
using C = B;
150+
using D = B;
151+
N t = 0 ? A<decltype(C())>() : A<decltype(D())>();
152+
// expected-error@-1 {{rvalue of type 'A<decltype(C())>' (aka 'long')}}
153+
}
154+
template void h<int>();
155+
} // namespace GH67603

0 commit comments

Comments
 (0)