[clang] [clang] [ASTDump] Add support for structural value template arguments in TextNodeDumper (PR #126341)

via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 7 23:04:30 PST 2025


https://github.com/sakria9 updated https://github.com/llvm/llvm-project/pull/126341

>From a382aa9de206a194397f9424150f170d35101b42 Mon Sep 17 00:00:00 2001
From: sakria9 <i at sustech.moe>
Date: Sat, 8 Feb 2025 04:00:08 +0000
Subject: [PATCH 1/8] [ASTDump] Add support for structural value template
 arguments in TextNodeDumper

---
 clang/include/clang/AST/TextNodeDumper.h | 1 +
 clang/lib/AST/TextNodeDumper.cpp         | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/clang/include/clang/AST/TextNodeDumper.h b/clang/include/clang/AST/TextNodeDumper.h
index bfd205ffb0d99ad..4b5ad2b5fa74c04 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -249,6 +249,7 @@ class TextNodeDumper
   void VisitDeclarationTemplateArgument(const TemplateArgument &TA);
   void VisitNullPtrTemplateArgument(const TemplateArgument &TA);
   void VisitIntegralTemplateArgument(const TemplateArgument &TA);
+  void VisitStructuralValueTemplateArgument(const TemplateArgument &TA);
   void VisitTemplateTemplateArgument(const TemplateArgument &TA);
   void VisitTemplateExpansionTemplateArgument(const TemplateArgument &TA);
   void VisitExpressionTemplateArgument(const TemplateArgument &TA);
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 6da1f776b4b6357..cb0c742177d2c7f 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1226,6 +1226,11 @@ void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) {
   dumpTemplateArgument(TA);
 }
 
+void TextNodeDumper::VisitStructuralValueTemplateArgument(const TemplateArgument &TA) {
+  OS << " structural value";
+  dumpTemplateArgument(TA);
+}
+
 void TextNodeDumper::dumpTemplateName(TemplateName TN, StringRef Label) {
   AddChild(Label, [=] {
     {

>From 5e9bfa7141a1b0eda2fe41d2727c66a1e4c19e5d Mon Sep 17 00:00:00 2001
From: sakria9 <i at sustech.moe>
Date: Sat, 8 Feb 2025 04:11:05 +0000
Subject: [PATCH 2/8] format

---
 clang/lib/AST/TextNodeDumper.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index cb0c742177d2c7f..08efcda46b8f9a4 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1226,7 +1226,8 @@ void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) {
   dumpTemplateArgument(TA);
 }
 
-void TextNodeDumper::VisitStructuralValueTemplateArgument(const TemplateArgument &TA) {
+void TextNodeDumper::VisitStructuralValueTemplateArgument(
+    const TemplateArgument &TA) {
   OS << " structural value";
   dumpTemplateArgument(TA);
 }

>From f930983e7286e4d1e46fbd2081996fd18ebdddfc Mon Sep 17 00:00:00 2001
From: sakria9 <i at sustech.moe>
Date: Sat, 8 Feb 2025 05:50:35 +0000
Subject: [PATCH 3/8] add test

---
 .../ast-dump-template-argument-structural-value.cpp  | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 clang/test/AST/ast-dump-template-argument-structural-value.cpp

diff --git a/clang/test/AST/ast-dump-template-argument-structural-value.cpp b/clang/test/AST/ast-dump-template-argument-structural-value.cpp
new file mode 100644
index 000000000000000..61d4a9ef82db439
--- /dev/null
+++ b/clang/test/AST/ast-dump-template-argument-structural-value.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++20 -ast-dump -ast-dump-filter=pr126341 %s | FileCheck %s
+
+template<_Complex int x>
+struct pr126341;
+template<>
+struct pr126341<{1, 2}>;
+
+// CHECK: Dumping pr126341:
+// CHECK-NEXT: ClassTemplateDecl
+// CHECK: Dumping pr126341:
+// CHECK-NEXT: ClassTemplateSpecializationDecl
+// CHECK-NEXT: `-TemplateArgument structural value '1+2i'
\ No newline at end of file

>From b80626ff56adc6db71298eea7fd824b9463056e8 Mon Sep 17 00:00:00 2001
From: sakria9 <i at sustech.moe>
Date: Sat, 8 Feb 2025 05:55:15 +0000
Subject: [PATCH 4/8] add newline

---
 clang/test/AST/ast-dump-template-argument-structural-value.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/AST/ast-dump-template-argument-structural-value.cpp b/clang/test/AST/ast-dump-template-argument-structural-value.cpp
index 61d4a9ef82db439..7f5a3d4508f1cfd 100644
--- a/clang/test/AST/ast-dump-template-argument-structural-value.cpp
+++ b/clang/test/AST/ast-dump-template-argument-structural-value.cpp
@@ -9,4 +9,4 @@ struct pr126341<{1, 2}>;
 // CHECK-NEXT: ClassTemplateDecl
 // CHECK: Dumping pr126341:
 // CHECK-NEXT: ClassTemplateSpecializationDecl
-// CHECK-NEXT: `-TemplateArgument structural value '1+2i'
\ No newline at end of file
+// CHECK-NEXT: `-TemplateArgument structural value '1+2i'

>From 5678ce0a8910bb9800e182ca7755a14e446f0f72 Mon Sep 17 00:00:00 2001
From: sakria9 <i at sustech.moe>
Date: Sat, 8 Feb 2025 05:58:39 +0000
Subject: [PATCH 5/8] add release note

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 92f63c15030898f..89cb0f7e9d57db3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -54,6 +54,8 @@ ABI Changes in This Version
 AST Dumping Potentially Breaking Changes
 ----------------------------------------
 
+- Added support for dumping structural value template arguments in AST dumps. (#GH126341)
+
 Clang Frontend Potentially Breaking Changes
 -------------------------------------------
 

>From 4af5be26ffc56345ac7a423eb28b58743c45b837 Mon Sep 17 00:00:00 2001
From: sakria9 <102365810+sakria9 at users.noreply.github.com>
Date: Sat, 8 Feb 2025 14:16:19 +0800
Subject: [PATCH 6/8] Update clang/docs/ReleaseNotes.rst

Co-authored-by: Younan Zhang <zyn7109 at gmail.com>
---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 89cb0f7e9d57db3..e4cf9ae82a7a9a1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -54,7 +54,7 @@ ABI Changes in This Version
 AST Dumping Potentially Breaking Changes
 ----------------------------------------
 
-- Added support for dumping structural value template arguments in AST dumps. (#GH126341)
+- Added support for dumping template arguments of structural value kinds.
 
 Clang Frontend Potentially Breaking Changes
 -------------------------------------------

>From 50b2be30564ad1d8caf2a38e726a5422d85a3b81 Mon Sep 17 00:00:00 2001
From: sakria9 <i at sustech.moe>
Date: Sat, 8 Feb 2025 07:02:32 +0000
Subject: [PATCH 7/8] Add VisitStructuralValueTemplateArgument method to
 JSONNodeDumper

---
 clang/include/clang/AST/JSONNodeDumper.h | 1 +
 clang/lib/AST/JSONNodeDumper.cpp         | 4 ++++
 2 files changed, 5 insertions(+)

diff --git a/clang/include/clang/AST/JSONNodeDumper.h b/clang/include/clang/AST/JSONNodeDumper.h
index 9422c8fceccfbd1..660a05435003d8d 100644
--- a/clang/include/clang/AST/JSONNodeDumper.h
+++ b/clang/include/clang/AST/JSONNodeDumper.h
@@ -345,6 +345,7 @@ class JSONNodeDumper
   void VisitDeclarationTemplateArgument(const TemplateArgument &TA);
   void VisitNullPtrTemplateArgument(const TemplateArgument &TA);
   void VisitIntegralTemplateArgument(const TemplateArgument &TA);
+  void VisitStructuralValueTemplateArgument(const TemplateArgument &TA);
   void VisitTemplateTemplateArgument(const TemplateArgument &TA);
   void VisitTemplateExpansionTemplateArgument(const TemplateArgument &TA);
   void VisitExpressionTemplateArgument(const TemplateArgument &TA);
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index 169e3ee94c221bc..27fd214dcee3bb6 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -1705,6 +1705,10 @@ void JSONNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &TA) {
 void JSONNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) {
   JOS.attribute("value", TA.getAsIntegral().getSExtValue());
 }
+void JSONNodeDumper::VisitStructuralValueTemplateArgument(
+    const TemplateArgument &TA) {
+  Visit(TA.getAsStructuralValue(), TA.getStructuralValueType());
+}
 void JSONNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument &TA) {
   // FIXME: cannot just call dump() on the argument, as that doesn't specify
   // the output format.

>From 5059718c4e24e1e19ad294d13c02e971734c22ee Mon Sep 17 00:00:00 2001
From: sakria9 <i at sustech.moe>
Date: Sat, 8 Feb 2025 07:03:54 +0000
Subject: [PATCH 8/8] move test to ast-dump-templates.cpp

---
 ...ump-template-argument-structural-value.cpp |  12 --
 clang/test/AST/ast-dump-templates.cpp         | 168 +++++++++++++++++-
 2 files changed, 163 insertions(+), 17 deletions(-)
 delete mode 100644 clang/test/AST/ast-dump-template-argument-structural-value.cpp

diff --git a/clang/test/AST/ast-dump-template-argument-structural-value.cpp b/clang/test/AST/ast-dump-template-argument-structural-value.cpp
deleted file mode 100644
index 7f5a3d4508f1cfd..000000000000000
--- a/clang/test/AST/ast-dump-template-argument-structural-value.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-// RUN: %clang_cc1 -std=c++20 -ast-dump -ast-dump-filter=pr126341 %s | FileCheck %s
-
-template<_Complex int x>
-struct pr126341;
-template<>
-struct pr126341<{1, 2}>;
-
-// CHECK: Dumping pr126341:
-// CHECK-NEXT: ClassTemplateDecl
-// CHECK: Dumping pr126341:
-// CHECK-NEXT: ClassTemplateSpecializationDecl
-// CHECK-NEXT: `-TemplateArgument structural value '1+2i'
diff --git a/clang/test/AST/ast-dump-templates.cpp b/clang/test/AST/ast-dump-templates.cpp
index 86af8c50f3174eb..2728dc151c3c558 100644
--- a/clang/test/AST/ast-dump-templates.cpp
+++ b/clang/test/AST/ast-dump-templates.cpp
@@ -1,12 +1,12 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++17 -ast-dump=json %s | FileCheck --check-prefix=JSON %s
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++17 -ast-print %s > %t
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++20 -ast-dump=json %s | FileCheck --check-prefix=JSON %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++20 -ast-print %s > %t
 // RUN: FileCheck < %t %s -check-prefix=CHECK1
 // RUN: FileCheck < %t %s -check-prefix=CHECK2
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++17 -ast-dump %s | FileCheck --check-prefix=DUMP %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++20 -ast-dump %s | FileCheck --check-prefix=DUMP %s
 
 // Test with serialization:
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++17 -emit-pch -o %t %s
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -x c++ -std=c++17 -include-pch %t \
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++20 -emit-pch -o %t %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -x c++ -std=c++20 -include-pch %t \
 // RUN: -ast-dump-all /dev/null \
 // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
 // RUN: | FileCheck --strict-whitespace --check-prefix=DUMP %s
@@ -135,6 +135,17 @@ namespace test7 {
 // DUMP:       ClassTemplateSpecializationDecl {{.*}} struct A definition explicit_instantiation_definition strict-pack-match{{$}}
 } // namespce test7
 
+namespace test8 {
+template<_Complex int x>
+struct pr126341;
+template<>
+struct pr126341<{1, 2}>;
+// DUMP-LABEL: NamespaceDecl {{.*}} test8{{$}}
+// DUMP-NEXT:  |-ClassTemplateDecl {{.*}} pr126341
+// DUMP:       `-ClassTemplateSpecializationDecl {{.*}} pr126341
+// DUMP:         `-TemplateArgument structural value '1+2i'
+} // namespace test8
+
 // NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
 
 
@@ -486,6 +497,7 @@ namespace test7 {
 // JSON-NEXT:        "trivial": true
 // JSON-NEXT:       },
 // JSON-NEXT:       "defaultCtor": {
+// JSON-NEXT:        "defaultedIsConstexpr": true,
 // JSON-NEXT:        "exists": true,
 // JSON-NEXT:        "nonTrivial": true,
 // JSON-NEXT:        "userProvided": true
@@ -819,6 +831,7 @@ namespace test7 {
 // JSON-NEXT:        "trivial": true
 // JSON-NEXT:       },
 // JSON-NEXT:       "defaultCtor": {
+// JSON-NEXT:        "defaultedIsConstexpr": true,
 // JSON-NEXT:        "exists": true,
 // JSON-NEXT:        "nonTrivial": true,
 // JSON-NEXT:        "userProvided": true
@@ -1408,6 +1421,7 @@ namespace test7 {
 // JSON-NEXT:         "qualType": "void () noexcept"
 // JSON-NEXT:        },
 // JSON-NEXT:        "inline": true,
+// JSON-NEXT:        "constexpr": true,
 // JSON-NEXT:        "explicitlyDefaulted": "default"
 // JSON-NEXT:       }
 // JSON-NEXT:      ]
@@ -1454,6 +1468,7 @@ namespace test7 {
 // JSON-NEXT:        "trivial": true
 // JSON-NEXT:       },
 // JSON-NEXT:       "defaultCtor": {
+// JSON-NEXT:        "defaultedIsConstexpr": true,
 // JSON-NEXT:        "exists": true,
 // JSON-NEXT:        "nonTrivial": true,
 // JSON-NEXT:        "userProvided": true
@@ -2067,6 +2082,7 @@ namespace test7 {
 // JSON-NEXT:         "qualType": "void () noexcept"
 // JSON-NEXT:        },
 // JSON-NEXT:        "inline": true,
+// JSON-NEXT:        "constexpr": true,
 // JSON-NEXT:        "explicitlyDefaulted": "default"
 // JSON-NEXT:       }
 // JSON-NEXT:      ]
@@ -6158,6 +6174,148 @@ namespace test7 {
 // JSON-NEXT:      ]
 // JSON-NEXT:     }
 // JSON-NEXT:    ]
+// JSON-NEXT:   },
+// JSON-NEXT:   {
+// JSON-NEXT:    "id": "0x{{.*}}",
+// JSON-NEXT:    "kind": "NamespaceDecl",
+// JSON-NEXT:    "loc": {
+// JSON-NEXT:     "offset": 4339,
+// JSON-NEXT:     "line": 138,
+// JSON-NEXT:     "col": 11,
+// JSON-NEXT:     "tokLen": 5
+// JSON-NEXT:    },
+// JSON-NEXT:    "range": {
+// JSON-NEXT:     "begin": {
+// JSON-NEXT:      "offset": 4329,
+// JSON-NEXT:      "col": 1,
+// JSON-NEXT:      "tokLen": 9
+// JSON-NEXT:     },
+// JSON-NEXT:     "end": {
+// JSON-NEXT:      "offset": 4648,
+// JSON-NEXT:      "line": 147,
+// JSON-NEXT:      "col": 1,
+// JSON-NEXT:      "tokLen": 1
+// JSON-NEXT:     }
+// JSON-NEXT:    },
+// JSON-NEXT:    "name": "test8",
+// JSON-NEXT:    "inner": [
+// JSON-NEXT:     {
+// JSON-NEXT:      "id": "0x{{.*}}",
+// JSON-NEXT:      "kind": "ClassTemplateDecl",
+// JSON-NEXT:      "loc": {
+// JSON-NEXT:       "offset": 4379,
+// JSON-NEXT:       "line": 140,
+// JSON-NEXT:       "col": 8,
+// JSON-NEXT:       "tokLen": 8
+// JSON-NEXT:      },
+// JSON-NEXT:      "range": {
+// JSON-NEXT:       "begin": {
+// JSON-NEXT:        "offset": 4347,
+// JSON-NEXT:        "line": 139,
+// JSON-NEXT:        "col": 1,
+// JSON-NEXT:        "tokLen": 8
+// JSON-NEXT:       },
+// JSON-NEXT:       "end": {
+// JSON-NEXT:        "offset": 4379,
+// JSON-NEXT:        "line": 140,
+// JSON-NEXT:        "col": 8,
+// JSON-NEXT:        "tokLen": 8
+// JSON-NEXT:       }
+// JSON-NEXT:      },
+// JSON-NEXT:      "name": "pr126341",
+// JSON-NEXT:      "inner": [
+// JSON-NEXT:       {
+// JSON-NEXT:        "id": "0x{{.*}}",
+// JSON-NEXT:        "kind": "NonTypeTemplateParmDecl",
+// JSON-NEXT:        "loc": {
+// JSON-NEXT:         "offset": 4369,
+// JSON-NEXT:         "line": 139,
+// JSON-NEXT:         "col": 23,
+// JSON-NEXT:         "tokLen": 1
+// JSON-NEXT:        },
+// JSON-NEXT:        "range": {
+// JSON-NEXT:         "begin": {
+// JSON-NEXT:          "offset": 4356,
+// JSON-NEXT:          "col": 10,
+// JSON-NEXT:          "tokLen": 8
+// JSON-NEXT:         },
+// JSON-NEXT:         "end": {
+// JSON-NEXT:          "offset": 4369,
+// JSON-NEXT:          "col": 23,
+// JSON-NEXT:          "tokLen": 1
+// JSON-NEXT:         }
+// JSON-NEXT:        },
+// JSON-NEXT:        "name": "x",
+// JSON-NEXT:        "type": {
+// JSON-NEXT:         "qualType": "_Complex int"
+// JSON-NEXT:        },
+// JSON-NEXT:        "depth": 0,
+// JSON-NEXT:        "index": 0
+// JSON-NEXT:       },
+// JSON-NEXT:       {
+// JSON-NEXT:        "id": "0x{{.*}}",
+// JSON-NEXT:        "kind": "CXXRecordDecl",
+// JSON-NEXT:        "loc": {
+// JSON-NEXT:         "offset": 4379,
+// JSON-NEXT:         "line": 140,
+// JSON-NEXT:         "col": 8,
+// JSON-NEXT:         "tokLen": 8
+// JSON-NEXT:        },
+// JSON-NEXT:        "range": {
+// JSON-NEXT:         "begin": {
+// JSON-NEXT:          "offset": 4372,
+// JSON-NEXT:          "col": 1,
+// JSON-NEXT:          "tokLen": 6
+// JSON-NEXT:         },
+// JSON-NEXT:         "end": {
+// JSON-NEXT:          "offset": 4379,
+// JSON-NEXT:          "col": 8,
+// JSON-NEXT:          "tokLen": 8
+// JSON-NEXT:         }
+// JSON-NEXT:        },
+// JSON-NEXT:        "name": "pr126341",
+// JSON-NEXT:        "tagUsed": "struct"
+// JSON-NEXT:       },
+// JSON-NEXT:       {
+// JSON-NEXT:        "id": "0x{{.*}}",
+// JSON-NEXT:        "kind": "ClassTemplateSpecializationDecl",
+// JSON-NEXT:        "name": "pr126341"
+// JSON-NEXT:       }
+// JSON-NEXT:      ]
+// JSON-NEXT:     },
+// JSON-NEXT:     {
+// JSON-NEXT:      "id": "0x{{.*}}",
+// JSON-NEXT:      "kind": "ClassTemplateSpecializationDecl",
+// JSON-NEXT:      "loc": {
+// JSON-NEXT:       "offset": 4407,
+// JSON-NEXT:       "line": 142,
+// JSON-NEXT:       "col": 8,
+// JSON-NEXT:       "tokLen": 8
+// JSON-NEXT:      },
+// JSON-NEXT:      "range": {
+// JSON-NEXT:       "begin": {
+// JSON-NEXT:        "offset": 4389,
+// JSON-NEXT:        "line": 141,
+// JSON-NEXT:        "col": 1,
+// JSON-NEXT:        "tokLen": 8
+// JSON-NEXT:       },
+// JSON-NEXT:       "end": {
+// JSON-NEXT:        "offset": 4422,
+// JSON-NEXT:        "line": 142,
+// JSON-NEXT:        "col": 23,
+// JSON-NEXT:        "tokLen": 1
+// JSON-NEXT:       }
+// JSON-NEXT:      },
+// JSON-NEXT:      "name": "pr126341",
+// JSON-NEXT:      "tagUsed": "struct",
+// JSON-NEXT:      "inner": [
+// JSON-NEXT:       {
+// JSON-NEXT:        "kind": "TemplateArgument",
+// JSON-NEXT:        "value": "1+2i"
+// JSON-NEXT:       }
+// JSON-NEXT:      ]
+// JSON-NEXT:     }
+// JSON-NEXT:    ]
 // JSON-NEXT:   }
 // JSON-NEXT:  ]
 // JSON-NEXT: }



More information about the cfe-commits mailing list