Skip to content

Commit

Permalink
[clang] implement common sugared type of inst-dependent DecltypeType (#…
Browse files Browse the repository at this point in the history
…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 #67603
  • Loading branch information
mizvekov committed Sep 29, 2023
1 parent 3686a0b commit 06721bb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ Bug Fixes in This Version
(`#64836 <https://github.com/llvm/llvm-project/issues/64836>`_)
- Clang now allows an ``_Atomic`` qualified integer in a switch statement. Fixes
(`#65557 <https://github.com/llvm/llvm-project/issues/65557>`_)
- Fixes crash when trying to obtain the common sugared type of
`decltype(instantiation-dependent-expr)`.
Fixes (`#67603 <https://github.com/llvm/llvm-project/issues/67603>`_)

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
9 changes: 8 additions & 1 deletion clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12705,7 +12705,6 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,

#define SUGAR_FREE_TYPE(Class) UNEXPECTED_TYPE(Class, "sugar-free")
SUGAR_FREE_TYPE(Builtin)
SUGAR_FREE_TYPE(Decltype)
SUGAR_FREE_TYPE(DeducedTemplateSpecialization)
SUGAR_FREE_TYPE(DependentBitInt)
SUGAR_FREE_TYPE(Enum)
Expand Down Expand Up @@ -12935,6 +12934,14 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,
TY->getTemplateName()),
As, X->getCanonicalTypeInternal());
}
case Type::Decltype: {
const auto *DX = cast<DecltypeType>(X), *DY = cast<DecltypeType>(Y);
assert(DX->isDependentType());
assert(DY->isDependentType());
assert(Ctx.hasSameExpr(DX->getUnderlyingExpr(), DY->getUnderlyingExpr()));
// As Decltype is not uniqued, building a common type would be wasteful.
return QualType(DX, 0);
}
case Type::DependentName: {
const auto *NX = cast<DependentNameType>(X),
*NY = cast<DependentNameType>(Y);
Expand Down
11 changes: 11 additions & 0 deletions clang/test/SemaCXX/sugar-common-types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,14 @@ namespace PR61419 {
extern const pair<id, id> p;
id t = false ? p.first : p.second;
} // namespace PR61419

namespace GH67603 {
template <class> using A = long;
template <class B> void h() {
using C = B;
using D = B;
N t = 0 ? A<decltype(C())>() : A<decltype(D())>();
// expected-error@-1 {{rvalue of type 'A<decltype(C())>' (aka 'long')}}
}
template void h<int>();
} // namespace GH67603

0 comments on commit 06721bb

Please sign in to comment.