[clang] b6da16f - [clang][ExtractAPI] Ignore fully anonymous RecordDecls
Daniel Grumberg via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 13 03:54:08 PDT 2022
Author: Daniel Grumberg
Date: 2022-10-13T11:53:53+01:00
New Revision: b6da16ffb9d5a47c16fa377097809c6592132d34
URL: https://github.com/llvm/llvm-project/commit/b6da16ffb9d5a47c16fa377097809c6592132d34
DIFF: https://github.com/llvm/llvm-project/commit/b6da16ffb9d5a47c16fa377097809c6592132d34.diff
LOG: [clang][ExtractAPI] Ignore fully anonymous RecordDecls
ExtractAPI was emitting a separate symbol for anonymous record declaration
that define the type of a member of another record declaration. Now
ExtractAPI ignores these declarations and just records the existence of
the actual member.
Differential Revision: https://reviews.llvm.org/D135804
Added:
clang/test/ExtractAPI/anonymous_record_no_typedef.c
Modified:
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
Removed:
################################################################################
diff --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index 4a97ee9922ddd..2333f81fd3a36 100644
--- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -401,6 +401,9 @@ class ExtractAPIVisitor : public RecursiveASTVisitor<ExtractAPIVisitor> {
StringRef Name = Decl->getName();
if (Name.empty())
Name = getTypedefName(Decl);
+ if (Name.empty())
+ return true;
+
StringRef USR = API.recordUSR(Decl);
PresumedLoc Loc =
Context.getSourceManager().getPresumedLoc(Decl->getLocation());
diff --git a/clang/test/ExtractAPI/anonymous_record_no_typedef.c b/clang/test/ExtractAPI/anonymous_record_no_typedef.c
new file mode 100644
index 0000000000000..6f7156ff1decb
--- /dev/null
+++ b/clang/test/ExtractAPI/anonymous_record_no_typedef.c
@@ -0,0 +1,396 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s at INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN: -x c-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN:
diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+/// A Vehicle
+struct Vehicle {
+ /// The type of vehicle.
+ enum {
+ Bicycle,
+ Car
+ } type;
+
+ /// The information about the vehicle.
+ struct {
+ int wheels;
+ char *name;
+ } information;
+};
+// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+ "metadata": {
+ "formatVersion": {
+ "major": 0,
+ "minor": 5,
+ "patch": 3
+ },
+ "generator": "?"
+ },
+ "module": {
+ "name": "",
+ "platform": {
+ "architecture": "arm64",
+ "operatingSystem": {
+ "minimumVersion": {
+ "major": 11,
+ "minor": 0,
+ "patch": 0
+ },
+ "name": "macosx"
+ },
+ "vendor": "apple"
+ }
+ },
+ "relationships": [
+ {
+ "kind": "memberOf",
+ "source": "c:@S at Vehicle@E at input.h@64 at Bicycle",
+ "target": "c:@S at Vehicle@E at input.h@64"
+ },
+ {
+ "kind": "memberOf",
+ "source": "c:@S at Vehicle@E at input.h@64 at Car",
+ "target": "c:@S at Vehicle@E at input.h@64"
+ },
+ {
+ "kind": "memberOf",
+ "source": "c:@S at Vehicle@FI at type",
+ "target": "c:@S at Vehicle"
+ },
+ {
+ "kind": "memberOf",
+ "source": "c:@S at Vehicle@FI at information",
+ "target": "c:@S at Vehicle"
+ }
+ ],
+ "symbols": [
+ {
+ "accessLevel": "public",
+ "declarationFragments": [
+ {
+ "kind": "keyword",
+ "spelling": "enum"
+ },
+ {
+ "kind": "text",
+ "spelling": ": "
+ },
+ {
+ "kind": "typeIdentifier",
+ "preciseIdentifier": "c:i",
+ "spelling": "unsigned int"
+ }
+ ],
+ "docComment": {
+ "lines": [
+ {
+ "range": {
+ "end": {
+ "character": 29,
+ "line": 3
+ },
+ "start": {
+ "character": 9,
+ "line": 3
+ }
+ },
+ "text": "The type of vehicle."
+ }
+ ]
+ },
+ "identifier": {
+ "interfaceLanguage": "c",
+ "precise": "c:@S at Vehicle@E at input.h@64"
+ },
+ "kind": {
+ "displayName": "Enumeration",
+ "identifier": "c.enum"
+ },
+ "location": {
+ "position": {
+ "character": 5,
+ "line": 4
+ },
+ "uri": "file://INPUT_DIR/input.h"
+ },
+ "names": {
+ "navigator": [
+ {
+ "kind": "identifier",
+ "spelling": "Vehicle::(anonymous)"
+ }
+ ],
+ "title": "Vehicle::(anonymous)"
+ },
+ "pathComponents": [
+ "Vehicle::(anonymous)"
+ ]
+ },
+ {
+ "accessLevel": "public",
+ "declarationFragments": [
+ {
+ "kind": "identifier",
+ "spelling": "Bicycle"
+ }
+ ],
+ "identifier": {
+ "interfaceLanguage": "c",
+ "precise": "c:@S at Vehicle@E at input.h@64 at Bicycle"
+ },
+ "kind": {
+ "displayName": "Enumeration Case",
+ "identifier": "c.enum.case"
+ },
+ "location": {
+ "position": {
+ "character": 9,
+ "line": 5
+ },
+ "uri": "file://INPUT_DIR/input.h"
+ },
+ "names": {
+ "navigator": [
+ {
+ "kind": "identifier",
+ "spelling": "Bicycle"
+ }
+ ],
+ "subHeading": [
+ {
+ "kind": "identifier",
+ "spelling": "Bicycle"
+ }
+ ],
+ "title": "Bicycle"
+ },
+ "pathComponents": [
+ "Vehicle::(anonymous)",
+ "Bicycle"
+ ]
+ },
+ {
+ "accessLevel": "public",
+ "declarationFragments": [
+ {
+ "kind": "identifier",
+ "spelling": "Car"
+ }
+ ],
+ "identifier": {
+ "interfaceLanguage": "c",
+ "precise": "c:@S at Vehicle@E at input.h@64 at Car"
+ },
+ "kind": {
+ "displayName": "Enumeration Case",
+ "identifier": "c.enum.case"
+ },
+ "location": {
+ "position": {
+ "character": 9,
+ "line": 6
+ },
+ "uri": "file://INPUT_DIR/input.h"
+ },
+ "names": {
+ "navigator": [
+ {
+ "kind": "identifier",
+ "spelling": "Car"
+ }
+ ],
+ "subHeading": [
+ {
+ "kind": "identifier",
+ "spelling": "Car"
+ }
+ ],
+ "title": "Car"
+ },
+ "pathComponents": [
+ "Vehicle::(anonymous)",
+ "Car"
+ ]
+ },
+ {
+ "accessLevel": "public",
+ "declarationFragments": [
+ {
+ "kind": "keyword",
+ "spelling": "struct"
+ },
+ {
+ "kind": "text",
+ "spelling": " "
+ },
+ {
+ "kind": "identifier",
+ "spelling": "Vehicle"
+ }
+ ],
+ "docComment": {
+ "lines": [
+ {
+ "range": {
+ "end": {
+ "character": 14,
+ "line": 1
+ },
+ "start": {
+ "character": 5,
+ "line": 1
+ }
+ },
+ "text": "A Vehicle"
+ }
+ ]
+ },
+ "identifier": {
+ "interfaceLanguage": "c",
+ "precise": "c:@S at Vehicle"
+ },
+ "kind": {
+ "displayName": "Structure",
+ "identifier": "c.struct"
+ },
+ "location": {
+ "position": {
+ "character": 8,
+ "line": 2
+ },
+ "uri": "file://INPUT_DIR/input.h"
+ },
+ "names": {
+ "navigator": [
+ {
+ "kind": "identifier",
+ "spelling": "Vehicle"
+ }
+ ],
+ "subHeading": [
+ {
+ "kind": "identifier",
+ "spelling": "Vehicle"
+ }
+ ],
+ "title": "Vehicle"
+ },
+ "pathComponents": [
+ "Vehicle"
+ ]
+ },
+ {
+ "accessLevel": "public",
+ "declarationFragments": [
+ {
+ "kind": "keyword",
+ "spelling": "enum"
+ },
+ {
+ "kind": "text",
+ "spelling": " "
+ },
+ {
+ "kind": "identifier",
+ "spelling": "type"
+ }
+ ],
+ "identifier": {
+ "interfaceLanguage": "c",
+ "precise": "c:@S at Vehicle@FI at type"
+ },
+ "kind": {
+ "displayName": "Instance Property",
+ "identifier": "c.property"
+ },
+ "location": {
+ "position": {
+ "character": 7,
+ "line": 7
+ },
+ "uri": "file://INPUT_DIR/input.h"
+ },
+ "names": {
+ "navigator": [
+ {
+ "kind": "identifier",
+ "spelling": "type"
+ }
+ ],
+ "subHeading": [
+ {
+ "kind": "identifier",
+ "spelling": "type"
+ }
+ ],
+ "title": "type"
+ },
+ "pathComponents": [
+ "Vehicle",
+ "type"
+ ]
+ },
+ {
+ "accessLevel": "public",
+ "declarationFragments": [
+ {
+ "kind": "keyword",
+ "spelling": "struct"
+ },
+ {
+ "kind": "text",
+ "spelling": " "
+ },
+ {
+ "kind": "identifier",
+ "spelling": "information"
+ }
+ ],
+ "identifier": {
+ "interfaceLanguage": "c",
+ "precise": "c:@S at Vehicle@FI at information"
+ },
+ "kind": {
+ "displayName": "Instance Property",
+ "identifier": "c.property"
+ },
+ "location": {
+ "position": {
+ "character": 7,
+ "line": 13
+ },
+ "uri": "file://INPUT_DIR/input.h"
+ },
+ "names": {
+ "navigator": [
+ {
+ "kind": "identifier",
+ "spelling": "information"
+ }
+ ],
+ "subHeading": [
+ {
+ "kind": "identifier",
+ "spelling": "information"
+ }
+ ],
+ "title": "information"
+ },
+ "pathComponents": [
+ "Vehicle",
+ "information"
+ ]
+ }
+ ]
+}
More information about the cfe-commits
mailing list