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

URL: 
https://github.com/llvm/llvm-project/commit/903e530bb8980a3c30ea5eb98d2ec1cd61d94b57
DIFF: 
https://github.com/llvm/llvm-project/commit/903e530bb8980a3c30ea5eb98d2ec1cd61d94b57.diff

LOG: [clang] Add cleanup_function field to CleanupAttr json AST dump

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

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 c465137187cba4..c86dbf4d9e5558 100644
--- a/clang/include/clang/AST/JSONNodeDumper.h
+++ b/clang/include/clang/AST/JSONNodeDumper.h
@@ -209,6 +209,7 @@ class JSONNodeDumper
   void Visit(const APValue &Value, QualType Ty);
 
   void VisitAliasAttr(const AliasAttr *AA);
+  void VisitCleanupAttr(const CleanupAttr *CA);
 
   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 318e7d22db4567..a7ca34623d6089 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -534,6 +534,10 @@ void JSONNodeDumper::VisitAliasAttr(const AliasAttr *AA) {
   JOS.attribute("aliasee", AA->getAliasee());
 }
 
+void JSONNodeDumper::VisitCleanupAttr(const CleanupAttr *CA) {
+  JOS.attribute("cleanup_function", createBareDeclRef(CA->getFunctionDecl()));
+}
+
 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 40a49e0cab9490..adac50af0890a0 100644
--- a/clang/test/AST/ast-dump-attr-json.cpp
+++ b/clang/test/AST/ast-dump-attr-json.cpp
@@ -3,6 +3,11 @@
 int global_decl;
 extern __attribute__((alias("global_decl"))) int global_alias;
 
+void cleanup_function(int*);
+void some() {
+  __attribute__((cleanup(cleanup_function))) int var;
+}
+
 // NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
 // using --filters=VarDecl
 
@@ -78,7 +83,59 @@ extern __attribute__((alias("global_decl"))) int 
global_alias;
 // CHECK-NEXT:      "tokLen": 1
 // CHECK-NEXT:     }
 // CHECK-NEXT:    },
-// CHECK-NEXT:    "decl": "global_decl"
+// CHECK-NEXT:    "aliasee": "global_decl"
+// CHECK-NEXT:   }
+// CHECK-NEXT:  ]
+// CHECK-NEXT: }
+
+
+// CHECK-NOT: {{^}}Dumping
+// CHECK:  "kind": "VarDecl",
+// CHECK-NEXT:  "loc": {
+// CHECK-NEXT:   "offset": 242,
+// CHECK-NEXT:   "col": 50,
+// CHECK-NEXT:   "tokLen": 3
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:    "offset": 195,
+// CHECK-NEXT:    "col": 3,
+// CHECK-NEXT:    "tokLen": 13
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:    "offset": 242,
+// CHECK-NEXT:    "col": 50,
+// CHECK-NEXT:    "tokLen": 3
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "name": "var",
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "int"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "inner": [
+// CHECK-NEXT:   {
+// CHECK-NEXT:    "id": "0x{{.*}}",
+// CHECK-NEXT:    "kind": "CleanupAttr",
+// CHECK-NEXT:    "range": {
+// CHECK-NEXT:     "begin": {
+// CHECK-NEXT:      "offset": 210,
+// CHECK-NEXT:      "col": 18,
+// CHECK-NEXT:      "tokLen": 7
+// CHECK-NEXT:     },
+// CHECK-NEXT:     "end": {
+// CHECK-NEXT:      "offset": 234,
+// CHECK-NEXT:      "col": 42,
+// CHECK-NEXT:      "tokLen": 1
+// CHECK-NEXT:     }
+// CHECK-NEXT:    },
+// CHECK-NEXT:    "cleanup_function": {
+// CHECK-NEXT:     "id": "0x{{.*}}",
+// CHECK-NEXT:     "kind": "FunctionDecl",
+// CHECK-NEXT:     "name": "cleanup_function",
+// CHECK-NEXT:     "type": {
+// CHECK-NEXT:      "qualType": "void (int *)"
+// CHECK-NEXT:     }
+// CHECK-NEXT:    }
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to