Handle UsingType in GetPartiallyDesugaredType

According to https://github.com/llvm/llvm-project/commit/af27466c50,
it is used to represent types pulled in with a using declaration, for
example `using std::error_code; error_code x;`.

This fixes the build of the ROOTTMVASofie module on macOS where this
was causing `std::size_t` not be fully desugared to `unsigned long`
at first to later end up with two identical classes in a list that
must not have duplicates.
This commit is contained in:
Jonas Hahnfeld 2023-07-20 11:02:06 +02:00 committed by jenkins
parent 78f9595644
commit f636e21faa
2 changed files with 45 additions and 0 deletions

View File

@ -33,6 +33,7 @@ namespace clang {
class TemplateDecl;
class Type;
class TypedefNameDecl;
class UsingShadowDecl;
}
namespace cling {
@ -346,6 +347,19 @@ namespace utils {
const clang::TypedefNameDecl *TD,
bool FullyQualify);
///\brief Create a NestedNameSpecifier for UsingShadowDecl and its enclosing
/// scopes.
///
///\param[in] Ctx - the AST Context to be used.
///\param[in] USD - the UsingShadowDecl for which a NestedNameSpecifier is
/// requested.
///\param[in] FullyQualify - Convert all template arguments (of possible
/// parent scopes) into fully qualified names.
clang::NestedNameSpecifier*
CreateNestedNameSpecifier(const clang::ASTContext& Ctx,
const clang::UsingShadowDecl *USD,
bool FullyQualify);
} // end namespace TypeName
} // end namespace utils
} // end namespace cling

View File

@ -378,6 +378,9 @@ namespace utils {
} else if (const TypedefType* TDD = dyn_cast<TypedefType>(type)) {
return TypeName::CreateNestedNameSpecifier(Ctx, TDD->getDecl(),
true /*FullyQualified*/);
} else if (const UsingType* UT = dyn_cast<UsingType>(type)) {
return TypeName::CreateNestedNameSpecifier(Ctx, UT->getFoundDecl(),
true /*FullyQualified*/);
}
} else if (const NamespaceDecl* NS = scope->getAsNamespace()) {
return TypeName::CreateNestedNameSpecifier(Ctx, NS);
@ -558,8 +561,12 @@ namespace utils {
Decl* decl = nullptr;
const TypedefType* typedeftype =
dyn_cast_or_null<TypedefType>(&(*desugared));
const UsingType* usingtype =
dyn_cast_or_null<UsingType>(&(*desugared));
if (typedeftype) {
decl = typedeftype->getDecl();
} else if (usingtype) {
decl = usingtype->getFoundDecl();
} else {
// There are probably other cases ...
const TagType* tagdecltype = dyn_cast_or_null<TagType>(&(*desugared));
@ -734,6 +741,11 @@ namespace utils {
QT = Ty->desugar();
return true;
}
case Type::Using: {
const UsingType* Ty = llvm::cast<UsingType>(QTy);
QT = Ty->desugar();
return true;
}
case Type::TypeOf: {
const TypeOfType* Ty = llvm::cast<TypeOfType>(QTy);
QT = Ty->desugar();
@ -846,6 +858,7 @@ namespace utils {
QualType SubTy = arg.getAsType();
// Check if the type needs more desugaring and recurse.
if (isa<TypedefType>(SubTy)
|| isa<UsingType>(SubTy)
|| isa<TemplateSpecializationType>(SubTy)
|| isa<ElaboratedType>(SubTy)
|| fullyQualifyTmpltArg) {
@ -1125,8 +1138,12 @@ namespace utils {
Decl *decl = nullptr;
const TypedefType* typedeftype =
dyn_cast_or_null<TypedefType>(QT.getTypePtr());
const UsingType* usingtype =
dyn_cast_or_null<UsingType>(QT.getTypePtr());
if (typedeftype) {
decl = typedeftype->getDecl();
} else if (usingtype) {
decl = usingtype->getFoundDecl();
} else {
// There are probably other cases ...
const TagType* tagdecltype = dyn_cast_or_null<TagType>(QT.getTypePtr());
@ -1286,6 +1303,7 @@ namespace utils {
QualType SubTy = I->getAsType();
// Check if the type needs more desugaring and recurse.
if (isa<TypedefType>(SubTy)
|| isa<UsingType>(SubTy)
|| isa<TemplateSpecializationType>(SubTy)
|| isa<ElaboratedType>(SubTy)
|| fullyQualifyTmpltArg) {
@ -1357,6 +1375,7 @@ namespace utils {
QualType SubTy = templateArgs[I].getAsType();
// Check if the type needs more desugaring and recurse.
if (isa<TypedefType>(SubTy)
|| isa<UsingType>(SubTy)
|| isa<TemplateSpecializationType>(SubTy)
|| isa<ElaboratedType>(SubTy)
|| fullyQualifyTmpltArg) {
@ -1549,6 +1568,8 @@ namespace utils {
Decl *decl = nullptr;
if (const TypedefType* typedeftype = llvm::dyn_cast<TypedefType>(TypePtr)) {
decl = typedeftype->getDecl();
} else if (const UsingType* usingtype = llvm::dyn_cast<UsingType>(TypePtr)) {
decl = usingtype->getFoundDecl();
} else {
// There are probably other cases ...
if (const TagType* tagdecltype = llvm::dyn_cast_or_null<TagType>(TypePtr))
@ -1588,6 +1609,16 @@ namespace utils {
TD->getTypeForDecl());
}
NestedNameSpecifier*
TypeName::CreateNestedNameSpecifier(const ASTContext& Ctx,
const UsingShadowDecl* USD,
bool FullyQualify) {
return NestedNameSpecifier::Create(Ctx, CreateOuterNNS(Ctx, USD,
FullyQualify),
true /*Template*/,
cast<TypeDecl>(USD)->getTypeForDecl());
}
NestedNameSpecifier*
TypeName::CreateNestedNameSpecifier(const ASTContext& Ctx,
const TagDecl *TD, bool FullyQualify) {