Skip to content

Commit 7091ca1

Browse files
[clang] Add missing LinkageSpec case to getCursorKindForDecl (llvm#72401)
The LinkageSpec case was omitted, and there is a declared CXCursor_Kind for it. Adapt the testsuite drivers to print mangled names for declarations with extern linkage. Also update the test baseline for the recursive-cxx-member-calls.cpp test. Co-authored-by: Matthieu Eyraud <[email protected]>
1 parent e9fdb96 commit 7091ca1

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,8 @@ libclang
938938
--------
939939

940940
- Exposed arguments of ``clang::annotate``.
941+
- ``clang::getCursorKindForDecl`` now recognizes linkage specifications such as
942+
``extern "C"`` and reports them as ``CXCursor_LinkageSpec``.
941943

942944
Static Analyzer
943945
---------------

clang/lib/Sema/SemaCodeComplete.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4165,6 +4165,9 @@ CXCursorKind clang::getCursorKindForDecl(const Decl *D) {
41654165
case Decl::Concept:
41664166
return CXCursor_ConceptDecl;
41674167

4168+
case Decl::LinkageSpec:
4169+
return CXCursor_LinkageSpec;
4170+
41684171
default:
41694172
if (const auto *TD = dyn_cast<TagDecl>(D)) {
41704173
switch (TD->getTagKind()) {

clang/test/Index/recursive-cxx-member-calls.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
216216
// CHECK-tokens: Punctuation: "}" [4:63 - 4:64] ClassTemplate=pair:4:44 (Definition)
217217
// CHECK-tokens: Punctuation: ";" [4:64 - 4:65] Namespace=std:3:11 (Definition)
218218
// CHECK-tokens: Punctuation: "}" [5:1 - 5:2] Namespace=std:3:11 (Definition)
219-
// CHECK-tokens: Keyword: "extern" [6:1 - 6:7]
220-
// CHECK-tokens: Literal: ""C"" [6:8 - 6:11] UnexposedDecl=:6:8 (Definition)
221-
// CHECK-tokens: Punctuation: "{" [6:12 - 6:13] UnexposedDecl=:6:8 (Definition)
219+
// CHECK-tokens: Keyword: "extern" [6:1 - 6:7] LinkageSpec=:6:8 (Definition)
220+
// CHECK-tokens: Literal: ""C"" [6:8 - 6:11] LinkageSpec=:6:8 (Definition)
221+
// CHECK-tokens: Punctuation: "{" [6:12 - 6:13] LinkageSpec=:6:8 (Definition)
222222
// CHECK-tokens: Keyword: "int" [7:3 - 7:6] FunctionDecl=memcmp:7:7
223223
// CHECK-tokens: Identifier: "memcmp" [7:7 - 7:13] FunctionDecl=memcmp:7:7
224224
// CHECK-tokens: Punctuation: "(" [7:13 - 7:14] FunctionDecl=memcmp:7:7
@@ -232,7 +232,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
232232
// CHECK-tokens: Punctuation: "," [7:40 - 7:41] FunctionDecl=memcmp:7:7
233233
// CHECK-tokens: Identifier: "size_t" [7:42 - 7:48] TypeRef=size_t:2:25
234234
// CHECK-tokens: Punctuation: ")" [7:48 - 7:49] FunctionDecl=memcmp:7:7
235-
// CHECK-tokens: Punctuation: ";" [7:49 - 7:50] UnexposedDecl=:6:8 (Definition)
235+
// CHECK-tokens: Punctuation: ";" [7:49 - 7:50] LinkageSpec=:6:8 (Definition)
236236
// CHECK-tokens: Identifier: "size_t" [8:3 - 8:9] TypeRef=size_t:2:25
237237
// CHECK-tokens: Identifier: "strlen" [8:10 - 8:16] FunctionDecl=strlen:8:10
238238
// CHECK-tokens: Punctuation: "(" [8:16 - 8:17] FunctionDecl=strlen:8:10
@@ -1532,7 +1532,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
15321532
// CHECK: 4:20: TemplateTypeParameter=_T1:4:20 (Definition) Extent=[4:14 - 4:23]
15331533
// CHECK: 4:31: TemplateTypeParameter=_T2:4:31 (Definition) Extent=[4:25 - 4:34]
15341534
// CHECK: 4:55: FieldDecl=second:4:55 (Definition) Extent=[4:51 - 4:61]
1535-
// CHECK: 6:8: UnexposedDecl=:6:8 (Definition) Extent=[6:1 - 9:2]
1535+
// CHECK: 6:8: LinkageSpec=:6:8 (Definition) Extent=[6:1 - 9:2]
15361536
// CHECK: 7:7: FunctionDecl=memcmp:7:7 Extent=[7:3 - 7:49]
15371537
// CHECK: 7:26: ParmDecl=:7:26 (Definition) Extent=[7:14 - 7:26]
15381538
// CHECK: 7:40: ParmDecl=:7:40 (Definition) Extent=[7:28 - 7:40]

clang/tools/c-index-test/c-index-test.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,8 @@ static enum CXChildVisitResult PrintMangledName(CXCursor cursor, CXCursor p,
18381838
CXString MangledName;
18391839
if (clang_isUnexposed(clang_getCursorKind(cursor)))
18401840
return CXChildVisit_Recurse;
1841+
if (clang_getCursorKind(cursor) == CXCursor_LinkageSpec)
1842+
return CXChildVisit_Recurse;
18411843
PrintCursor(cursor, NULL);
18421844
MangledName = clang_Cursor_getMangling(cursor);
18431845
printf(" [mangled=%s]\n", clang_getCString(MangledName));
@@ -1853,6 +1855,8 @@ static enum CXChildVisitResult PrintManglings(CXCursor cursor, CXCursor p,
18531855
return CXChildVisit_Recurse;
18541856
if (!clang_isDeclaration(clang_getCursorKind(cursor)))
18551857
return CXChildVisit_Recurse;
1858+
if (clang_getCursorKind(cursor) == CXCursor_LinkageSpec)
1859+
return CXChildVisit_Recurse;
18561860
if (clang_getCursorKind(cursor) == CXCursor_ParmDecl)
18571861
return CXChildVisit_Continue;
18581862
PrintCursor(cursor, NULL);

0 commit comments

Comments
 (0)