1 See https://reviews.llvm.org/D140075
2 See https://bugzilla.mozilla.org/show_bug.cgi?id=1795899
4 diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
5 --- a/tools/clang/include/clang-c/Index.h
6 +++ b/tools/clang/include/clang-c/Index.h
9 CXType_ExtVector = 176,
11 - CXType_BTFTagAttributed = 178
12 + CXType_BTFTagAttributed = 178,
18 diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
19 --- a/tools/clang/lib/Sema/SemaCodeComplete.cpp
20 +++ b/tools/clang/lib/Sema/SemaCodeComplete.cpp
22 return CXCursor_TranslationUnit;
25 + case Decl::UsingShadow:
26 case Decl::UnresolvedUsingValue:
27 case Decl::UnresolvedUsingTypename:
28 return CXCursor_UsingDeclaration;
29 diff --git a/clang/test/Index/print-type.cpp b/clang/test/Index/print-type.cpp
30 --- a/tools/clang/test/Index/print-type.cpp
31 +++ b/tools/clang/test/Index/print-type.cpp
35 inline namespace InlineNS {}
37 +namespace ToBeExported {
38 + typedef int ToBeExportedType;
41 +using ToBeExported::ToBeExportedType;
42 +void UseToBeExported(ToBeExportedType f);
44 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
45 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] [isPOD=0]
46 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] [isPOD=0]
48 // CHECK: EnumDecl=(unnamed enum at {{.*}}:87:3 (Definition) [type=X::(unnamed enum at {{.*}}print-type.cpp:87:3)] [typekind=Enum] [isPOD=1] [isAnon=1]
49 // CHECK: Namespace=:90:11 (Definition) [type=] [typekind=Invalid] [isPOD=0] [isAnon=1]
50 // CHECK: Namespace=InlineNS:94:18 (Definition) [type=] [typekind=Invalid] [isPOD=0] [isAnonRecDecl=0] [isInlineNamespace=1]
51 +// CHECK: UsingDeclaration=ToBeExportedType[97:15] [type=] [typekind=Invalid] [isPOD=0] [isAnonRecDecl=0]
52 +// CHECK: ParmDecl=f:101:39 (Definition) [type=ToBeExportedType] [typekind=Elaborated] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1] [isAnonRecDecl=0]
53 diff --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp
54 --- a/tools/clang/tools/libclang/CXCursor.cpp
55 +++ b/tools/clang/tools/libclang/CXCursor.cpp
56 @@ -1276,6 +1276,10 @@
57 return MakeCursorTypeRef(Tag->getDecl(), Loc, TU);
58 if (const TemplateTypeParmType *TemplP = Ty->getAs<TemplateTypeParmType>())
59 return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU);
60 + if (const UsingType *Using = Ty->getAs<UsingType>())
61 + if (const UsingShadowDecl *Shadow = Using->getFoundDecl())
62 + if (const auto *TD = dyn_cast_or_null<TypeDecl>(Shadow->getTargetDecl()))
63 + return MakeCursorTypeRef(TD, Loc, TU);
67 diff --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp
68 --- a/tools/clang/tools/libclang/CXType.cpp
69 +++ b/tools/clang/tools/libclang/CXType.cpp
75 TKCASE(ObjCInterface);
77 TKCASE(ObjCObjectPointer);
82 -CXType clang_getCursorType(CXCursor C) {
83 - using namespace cxcursor;
85 - CXTranslationUnit TU = cxcursor::getCursorTU(C);
87 - return MakeCXType(QualType(), TU);
89 - ASTContext &Context = cxtu::getASTUnit(TU)->getASTContext();
90 - if (clang_isExpression(C.kind)) {
91 - QualType T = cxcursor::getCursorExpr(C)->getType();
92 - return MakeCXType(T, TU);
95 - if (clang_isDeclaration(C.kind)) {
96 - const Decl *D = cxcursor::getCursorDecl(C);
97 +static CXType getDeclType(const Decl* D, CXTranslationUnit TU, ASTContext &Context) {
99 return MakeCXType(QualType(), TU);
101 if (const TypeDecl *TD = dyn_cast<TypeDecl>(D))
102 return MakeCXType(Context.getTypeDeclType(TD), TU);
103 if (const ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
105 return MakeCXType(PD->getType(), TU);
106 if (const FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(D))
107 return MakeCXType(FTD->getTemplatedDecl()->getType(), TU);
108 + if (const auto *UD = dyn_cast<UsingShadowDecl>(D))
109 + return getDeclType(UD->getTargetDecl(), TU, Context);
110 return MakeCXType(QualType(), TU);
113 +CXType clang_getCursorType(CXCursor C) {
114 + using namespace cxcursor;
116 + CXTranslationUnit TU = cxcursor::getCursorTU(C);
118 + return MakeCXType(QualType(), TU);
120 + ASTContext &Context = cxtu::getASTUnit(TU)->getASTContext();
121 + if (clang_isExpression(C.kind)) {
122 + QualType T = cxcursor::getCursorExpr(C)->getType();
123 + return MakeCXType(T, TU);
126 + if (clang_isDeclaration(C.kind))
127 + return getDeclType(cxcursor::getCursorDecl(C), TU, Context);
129 if (clang_isReference(C.kind)) {
131 case CXCursor_ObjCSuperClassRef: {
134 D = cast<TypedefType>(TP)->getDecl();
137 + D = cast<UsingType>(TP)->getFoundDecl();
139 case Type::ObjCObject:
140 D = cast<ObjCObjectType>(TP)->getInterface();
147 TKIND(ObjCInterface);
149 TKIND(ObjCObjectPointer);