[clang] 4cf7666 - [clang] Add missing field to SectionAttr json AST dump

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 14 14:00:14 PDT 2023


Author: serge-sans-paille
Date: 2023-08-14T22:59:45+02:00
New Revision: 4cf7666b8f0962a21ab06769254391f633f07d1d

URL: https://github.com/llvm/llvm-project/commit/4cf7666b8f0962a21ab06769254391f633f07d1d
DIFF: https://github.com/llvm/llvm-project/commit/4cf7666b8f0962a21ab06769254391f633f07d1d.diff

LOG: [clang] Add missing field to SectionAttr json AST dump

Differential Revision: https://reviews.llvm.org/D157795

Added: 
    

Modified: 
    clang/include/clang/AST/JSONNodeDumper.h
    clang/lib/AST/JSONNodeDumper.cpp
    clang/test/AST/ast-dump-attr-json.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/JSONNodeDumper.h b/clang/include/clang/AST/JSONNodeDumper.h
index 99ec1c3bc96668..089c0e97a90472 100644
--- a/clang/include/clang/AST/JSONNodeDumper.h
+++ b/clang/include/clang/AST/JSONNodeDumper.h
@@ -212,6 +212,7 @@ class JSONNodeDumper
   void VisitCleanupAttr(const CleanupAttr *CA);
   void VisitDeprecatedAttr(const DeprecatedAttr *DA);
   void VisitUnavailableAttr(const UnavailableAttr *UA);
+  void VisitSectionAttr(const SectionAttr *SA);
 
   void VisitTypedefType(const TypedefType *TT);
   void VisitUsingType(const UsingType *TT);

diff  --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index 28f9b3163db9d4..ec5661d1d6944d 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -550,6 +550,10 @@ void JSONNodeDumper::VisitUnavailableAttr(const UnavailableAttr *UA) {
     JOS.attribute("message", UA->getMessage());
 }
 
+void JSONNodeDumper::VisitSectionAttr(const SectionAttr *SA) {
+  JOS.attribute("section_name", SA->getName());
+}
+
 void JSONNodeDumper::VisitTypedefType(const TypedefType *TT) {
   JOS.attribute("decl", createBareDeclRef(TT->getDecl()));
   if (!TT->typeMatchesDecl())

diff  --git a/clang/test/AST/ast-dump-attr-json.cpp b/clang/test/AST/ast-dump-attr-json.cpp
index 845dd72c5431b9..a9679695e954f1 100644
--- a/clang/test/AST/ast-dump-attr-json.cpp
+++ b/clang/test/AST/ast-dump-attr-json.cpp
@@ -15,6 +15,8 @@ __attribute__((deprecated("reason", "replacement"))) int deprecated_var2;
 __attribute__((unavailable)) int unavailable_var0;
 __attribute__((unavailable("reason"))) int unavailable_var1;
 
+__attribute__ ((section ("SECTION_NAME"))) int section_var;
+
 // NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
 // using --filters=VarDecl
 
@@ -380,3 +382,50 @@ __attribute__((unavailable("reason"))) int unavailable_var1;
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
+
+
+// CHECK-NOT: {{^}}Dumping
+// CHECK:  "kind": "VarDecl",
+// CHECK-NEXT:  "loc": {
+// CHECK-NEXT:   "offset": 593,
+// CHECK-NEXT:   "line": 18,
+// CHECK-NEXT:   "col": 48,
+// CHECK-NEXT:   "tokLen": 11
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:    "offset": 546,
+// CHECK-NEXT:    "col": 1,
+// CHECK-NEXT:    "tokLen": 13
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:    "offset": 593,
+// CHECK-NEXT:    "col": 48,
+// CHECK-NEXT:    "tokLen": 11
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "name": "section_var",
+// CHECK-NEXT:  "mangledName": "section_var",
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "int"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "inner": [
+// CHECK-NEXT:   {
+// CHECK-NEXT:    "id": "0x{{.*}}",
+// CHECK-NEXT:    "kind": "SectionAttr",
+// CHECK-NEXT:    "range": {
+// CHECK-NEXT:     "begin": {
+// CHECK-NEXT:      "offset": 562,
+// CHECK-NEXT:      "col": 17,
+// CHECK-NEXT:      "tokLen": 7
+// CHECK-NEXT:     },
+// CHECK-NEXT:     "end": {
+// CHECK-NEXT:      "offset": 585,
+// CHECK-NEXT:      "col": 40,
+// CHECK-NEXT:      "tokLen": 1
+// CHECK-NEXT:     }
+// CHECK-NEXT:    },
+// CHECK-NEXT:    "section_name": "SECTION_NAME"
+// CHECK-NEXT:   }
+// CHECK-NEXT:  ]
+// CHECK-NEXT: }


        


More information about the cfe-commits mailing list