Obsolete golang-120
[oi-userland.git] / components / developer / clang-18 / patches / Bug-D140075-expose-using-shadow-types-and-declarations-in-libclang.patch
blobd49338550ffe876986cae0da9e1485f8c10ed89e
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
7 @@ -2795,7 +2795,9 @@
9 CXType_ExtVector = 176,
10 CXType_Atomic = 177,
11 - CXType_BTFTagAttributed = 178
12 + CXType_BTFTagAttributed = 178,
14 + CXType_Using = 179
17 /**
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
21 @@ -4062,6 +4062,7 @@
22 return CXCursor_TranslationUnit;
24 case Decl::Using:
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
32 @@ -92,6 +92,14 @@
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]
47 @@ -207,3 +215,5 @@
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);
65 return cursor;
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
70 @@ -100,6 +100,7 @@
71 TKCASE(Record);
72 TKCASE(Enum);
73 TKCASE(Typedef);
74 + TKCASE(Using);
75 TKCASE(ObjCInterface);
76 TKCASE(ObjCObject);
77 TKCASE(ObjCObjectPointer);
78 @@ -221,24 +222,9 @@
79 return std::nullopt;
82 -CXType clang_getCursorType(CXCursor C) {
83 - using namespace cxcursor;
85 - CXTranslationUnit TU = cxcursor::getCursorTU(C);
86 - if (!TU)
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);
93 - }
95 - if (clang_isDeclaration(C.kind)) {
96 - const Decl *D = cxcursor::getCursorDecl(C);
97 +static CXType getDeclType(const Decl* D, CXTranslationUnit TU, ASTContext &Context) {
98 if (!D)
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))
104 @@ -251,9 +237,27 @@
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);
117 + if (!TU)
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)) {
130 switch (C.kind) {
131 case CXCursor_ObjCSuperClassRef: {
132 @@ -503,6 +507,9 @@
133 case Type::Typedef:
134 D = cast<TypedefType>(TP)->getDecl();
135 break;
136 + case Type::Using:
137 + D = cast<UsingType>(TP)->getFoundDecl();
138 + break;
139 case Type::ObjCObject:
140 D = cast<ObjCObjectType>(TP)->getInterface();
141 break;
142 @@ -600,6 +607,7 @@
143 TKIND(Record);
144 TKIND(Enum);
145 TKIND(Typedef);
146 + TKIND(Using);
147 TKIND(ObjCInterface);
148 TKIND(ObjCObject);
149 TKIND(ObjCObjectPointer);