diff --git a/clang/include/clang/AST/JSONNodeDumper.h b/clang/include/clang/AST/JSONNodeDumper.h --- a/clang/include/clang/AST/JSONNodeDumper.h +++ b/clang/include/clang/AST/JSONNodeDumper.h @@ -209,6 +209,7 @@ 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 --- a/clang/lib/AST/JSONNodeDumper.cpp +++ b/clang/lib/AST/JSONNodeDumper.cpp @@ -534,6 +534,10 @@ 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 --- 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 @@ // 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: }