diff options
author | NagaChaitanya Vellanki <pnagato@protonmail.com> | 2023-03-23 14:38:37 -0700 |
---|---|---|
committer | NagaChaitanya Vellanki <pnagato@protonmail.com> | 2023-03-23 15:10:27 -0700 |
commit | c13ccf1fbabede34ff28461b29d2d14aceb293fd (patch) | |
tree | db737e720dcf41c6197eb1f88e61b0e9186b9320 /clang/lib/ExtractAPI/DeclarationFragments.cpp | |
parent | 397486566e995a019c249784b1d07c53b6ac670d (diff) | |
download | llvm-c13ccf1fbabede34ff28461b29d2d14aceb293fd.zip llvm-c13ccf1fbabede34ff28461b29d2d14aceb293fd.tar.gz llvm-c13ccf1fbabede34ff28461b29d2d14aceb293fd.tar.bz2 |
[clang][ExtractAPI]Fix Declaration fragments for instancetype in the type position degrade to id
Fixes https://github.com/llvm/llvm-project/issues/61481
Reviewed By: dang
Differential Revision: https://reviews.llvm.org/D146671
Diffstat (limited to 'clang/lib/ExtractAPI/DeclarationFragments.cpp')
-rw-r--r-- | clang/lib/ExtractAPI/DeclarationFragments.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp b/clang/lib/ExtractAPI/DeclarationFragments.cpp index b8de127..c42a1de 100644 --- a/clang/lib/ExtractAPI/DeclarationFragments.cpp +++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp @@ -243,26 +243,30 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType( return Fragments.append(getFragmentsForType(ET->desugar(), Context, After)); } - // Everything we care about has been handled now, reduce to the canonical - // unqualified base type. - QualType Base = T->getCanonicalTypeUnqualified(); - - // Render Objective-C `id`/`instancetype` as keywords. - if (T->isObjCIdType()) - return Fragments.append(Base.getAsString(), - DeclarationFragments::FragmentKind::Keyword); - // If the type is a typedefed type, get the underlying TypedefNameDecl for a // direct reference to the typedef instead of the wrapped type. + + // 'id' type is a typedef for an ObjCObjectPointerType + // we treat it as a typedef if (const TypedefType *TypedefTy = dyn_cast<TypedefType>(T)) { const TypedefNameDecl *Decl = TypedefTy->getDecl(); TypedefUnderlyingTypeResolver TypedefResolver(Context); std::string USR = TypedefResolver.getUSRForType(QualType(T, 0)); + + if (T->isObjCIdType()) { + return Fragments.append(Decl->getName(), + DeclarationFragments::FragmentKind::Keyword); + } + return Fragments.append( Decl->getName(), DeclarationFragments::FragmentKind::TypeIdentifier, USR, TypedefResolver.getUnderlyingTypeDecl(QualType(T, 0))); } + // Everything we care about has been handled now, reduce to the canonical + // unqualified base type. + QualType Base = T->getCanonicalTypeUnqualified(); + // If the base type is a TagType (struct/interface/union/class/enum), let's // get the underlying Decl for better names and USRs. if (const TagType *TagTy = dyn_cast<TagType>(Base)) { |