[clang] [AST] Dump explicit template arguments for UnreslovedLookupExpr. (PR #90466)
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 29 06:43:21 PDT 2024
https://github.com/hokein updated https://github.com/llvm/llvm-project/pull/90466
>From b584fab7f2283535d4a04bc55efec6ff508870de Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Mon, 29 Apr 2024 15:04:01 +0200
Subject: [PATCH 1/2] [AST] Dump explicit template arguments for
UnreslovedLookupExpr.
Having them dump is useful for ad-hoc debugging.
---
clang/include/clang/AST/ASTNodeTraverser.h | 6 ++
clang/test/AST/ast-dump-concepts.cpp | 14 +++
...dump-template-json-win32-mangler-crash.cpp | 88 +++++++++++++++++++
3 files changed, 108 insertions(+)
diff --git a/clang/include/clang/AST/ASTNodeTraverser.h b/clang/include/clang/AST/ASTNodeTraverser.h
index 216dc9eef08b62..cf7493ac37852b 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -844,6 +844,12 @@ class ASTNodeTraverser
}
}
+ void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr* E) {
+ if (E->hasExplicitTemplateArgs())
+ for (auto Arg : E->template_arguments())
+ Visit(Arg.getArgument());
+ }
+
void VisitRequiresExpr(const RequiresExpr *E) {
for (auto *D : E->getLocalParameters())
Visit(D);
diff --git a/clang/test/AST/ast-dump-concepts.cpp b/clang/test/AST/ast-dump-concepts.cpp
index 5bb174e3548ed2..01064b76f6d462 100644
--- a/clang/test/AST/ast-dump-concepts.cpp
+++ b/clang/test/AST/ast-dump-concepts.cpp
@@ -107,3 +107,17 @@ auto FooFunc(C auto V) -> C decltype(auto) {
}
}
+
+namespace dump_unreslove_lookup_arguments {
+template <class D>
+constexpr bool C = true;
+
+template <typename T>
+requires(C<T>)
+// CHECK: ParenExpr {{.*}} '<dependent type>' lvalue
+// CHECK-NEXT: `-UnresolvedLookupExpr {{.*}} '<dependent type>' lvalue (no ADL) = 'C'
+// CHECK-NEXT: `-TemplateArgument type 'T'
+// CHECK-NEXT: `-TemplateTypeParmType {{.*}} 'T'
+// CHECK-NEXT: `-TemplateTypeParm {{.*}} 'T'
+struct Foo {};
+}
diff --git a/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp b/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
index cf740516db6f4b..5ac55d269dce48 100644
--- a/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
+++ b/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
@@ -1846,6 +1846,42 @@ int main()
// CHECK-NEXT: "kind": "VarTemplateDecl",
// CHECK-NEXT: "name": "is_const_v"
// CHECK-NEXT: }
+// CHECK-NEXT: ],
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "kind": "TemplateArgument",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "const _Ty"
+// CHECK-NEXT: },
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "QualType",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "const _Ty"
+// CHECK-NEXT: },
+// CHECK-NEXT: "qualifiers": "const",
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "TemplateTypeParmType",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "_Ty"
+// CHECK-NEXT: },
+// CHECK-NEXT: "isDependent": true,
+// CHECK-NEXT: "isInstantiationDependent": true,
+// CHECK-NEXT: "depth": 0,
+// CHECK-NEXT: "index": 0,
+// CHECK-NEXT: "decl": {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "TemplateTypeParmDecl",
+// CHECK-NEXT: "name": "_Ty"
+// CHECK-NEXT: }
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: ]
@@ -1900,6 +1936,32 @@ int main()
// CHECK-NEXT: "kind": "VarTemplateDecl",
// CHECK-NEXT: "name": "is_reference_v"
// CHECK-NEXT: }
+// CHECK-NEXT: ],
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "kind": "TemplateArgument",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "_Ty"
+// CHECK-NEXT: },
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "TemplateTypeParmType",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "_Ty"
+// CHECK-NEXT: },
+// CHECK-NEXT: "isDependent": true,
+// CHECK-NEXT: "isInstantiationDependent": true,
+// CHECK-NEXT: "depth": 0,
+// CHECK-NEXT: "index": 0,
+// CHECK-NEXT: "decl": {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "TemplateTypeParmDecl",
+// CHECK-NEXT: "name": "_Ty"
+// CHECK-NEXT: }
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: ]
@@ -2565,6 +2627,32 @@ int main()
// CHECK-NEXT: "kind": "VarTemplateDecl",
// CHECK-NEXT: "name": "is_function_v"
// CHECK-NEXT: }
+// CHECK-NEXT: ],
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "kind": "TemplateArgument",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "_Ty1"
+// CHECK-NEXT: },
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "TemplateTypeParmType",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "_Ty1"
+// CHECK-NEXT: },
+// CHECK-NEXT: "isDependent": true,
+// CHECK-NEXT: "isInstantiationDependent": true,
+// CHECK-NEXT: "depth": 0,
+// CHECK-NEXT: "index": 0,
+// CHECK-NEXT: "decl": {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "TemplateTypeParmDecl",
+// CHECK-NEXT: "name": "_Ty1"
+// CHECK-NEXT: }
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: ]
>From b7b2cda28eefa4ffe05f8693edbeef0e4ae06269 Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Mon, 29 Apr 2024 15:41:39 +0200
Subject: [PATCH 2/2] Move the lit test to ast-dump-templates.cpp
---
clang/include/clang/AST/ASTNodeTraverser.h | 2 +-
clang/test/AST/ast-dump-concepts.cpp | 14 --------------
clang/test/AST/ast-dump-templates.cpp | 14 ++++++++++++++
3 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/clang/include/clang/AST/ASTNodeTraverser.h b/clang/include/clang/AST/ASTNodeTraverser.h
index cf7493ac37852b..bf7c204e4ad73a 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -844,7 +844,7 @@ class ASTNodeTraverser
}
}
- void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr* E) {
+ void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *E) {
if (E->hasExplicitTemplateArgs())
for (auto Arg : E->template_arguments())
Visit(Arg.getArgument());
diff --git a/clang/test/AST/ast-dump-concepts.cpp b/clang/test/AST/ast-dump-concepts.cpp
index 01064b76f6d462..5bb174e3548ed2 100644
--- a/clang/test/AST/ast-dump-concepts.cpp
+++ b/clang/test/AST/ast-dump-concepts.cpp
@@ -107,17 +107,3 @@ auto FooFunc(C auto V) -> C decltype(auto) {
}
}
-
-namespace dump_unreslove_lookup_arguments {
-template <class D>
-constexpr bool C = true;
-
-template <typename T>
-requires(C<T>)
-// CHECK: ParenExpr {{.*}} '<dependent type>' lvalue
-// CHECK-NEXT: `-UnresolvedLookupExpr {{.*}} '<dependent type>' lvalue (no ADL) = 'C'
-// CHECK-NEXT: `-TemplateArgument type 'T'
-// CHECK-NEXT: `-TemplateTypeParmType {{.*}} 'T'
-// CHECK-NEXT: `-TemplateTypeParm {{.*}} 'T'
-struct Foo {};
-}
diff --git a/clang/test/AST/ast-dump-templates.cpp b/clang/test/AST/ast-dump-templates.cpp
index d25ef36dd4d32c..9fcafbcbcc46b6 100644
--- a/clang/test/AST/ast-dump-templates.cpp
+++ b/clang/test/AST/ast-dump-templates.cpp
@@ -104,3 +104,17 @@ void (*q)() = f<>;
// CHECK1: template<> void f<0L>()
// CHECK1: template<> void f<0U>()
}
+
+namespace test6 {
+template <class D>
+constexpr bool C = true;
+
+template <class Key>
+void func() {
+ C<Key>;
+// DUMP: UnresolvedLookupExpr {{.*}} '<dependent type>' lvalue (no ADL) = 'C'
+// DUMP-NEXT: `-TemplateArgument type 'Key'
+// DUMP-NEXT: `-TemplateTypeParmType {{.*}} 'Key' dependent depth 0 index 0
+// DUMP-NEXT: `-TemplateTypeParm {{.*}} 'Key'
+}
+}
More information about the cfe-commits
mailing list