-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AST] Dump argument types for TypeTraitExpr. #89370
Conversation
The argument types are not modeled as children of TypeTraitExpr, therefore they are not dumped with the default implementation. Dumping them is really useful for ad-hoc debugging.
@llvm/pr-subscribers-clang Author: Haojian Wu (hokein) ChangesThe argument types are not modeled as children of TypeTraitExpr, therefore they are not dumped with the default implementation. Dumping them is really useful for ad-hoc debugging, context #89358 Full diff: https://github.com/llvm/llvm-project/pull/89370.diff 3 Files Affected:
diff --git a/clang/include/clang/AST/ASTNodeTraverser.h b/clang/include/clang/AST/ASTNodeTraverser.h
index f5c47d8a7c2113..216dc9eef08b62 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -851,6 +851,12 @@ class ASTNodeTraverser
Visit(R);
}
+ void VisitTypeTraitExpr(const TypeTraitExpr *E) {
+ // Argument types are not children of the TypeTraitExpr.
+ for (auto *A : E->getArgs())
+ Visit(A->getType());
+ }
+
void VisitLambdaExpr(const LambdaExpr *Node) {
if (Traversal == TK_IgnoreUnlessSpelledInSource) {
for (unsigned I = 0, N = Node->capture_size(); I != N; ++I) {
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 8c03b58abb0edb..cf740516db6f4b 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
@@ -2725,7 +2725,25 @@ int main()
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "bool"
// CHECK-NEXT: },
-// CHECK-NEXT: "valueCategory": "prvalue"
+// CHECK-NEXT: "valueCategory": "prvalue",
+// 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: }
@@ -3003,7 +3021,25 @@ int main()
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "bool"
// CHECK-NEXT: },
-// CHECK-NEXT: "valueCategory": "prvalue"
+// CHECK-NEXT: "valueCategory": "prvalue",
+// 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: }
diff --git a/clang/test/AST/ast-dump-traits.cpp b/clang/test/AST/ast-dump-traits.cpp
index 99ad50f528eb79..3085e5883fd2e2 100644
--- a/clang/test/AST/ast-dump-traits.cpp
+++ b/clang/test/AST/ast-dump-traits.cpp
@@ -40,10 +40,19 @@ void test_unary_expr_or_type_trait() {
// CHECK-NEXT: | | `-EnumDecl {{.*}} <col:3, col:11> col:8{{( imported)?}} referenced E
// CHECK-NEXT: | |-CStyleCastExpr {{.*}} <line:13:3, col:21> 'void' <ToVoid>
// CHECK-NEXT: | | `-TypeTraitExpr {{.*}} <col:10, col:21> 'bool' __is_enum
+// CHECK-NEXT: | | `-ElaboratedType {{.*}} 'E' sugar
+// CHECK-NEXT: | | `-EnumType {{.*}} 'E'
+// CHECK-NEXT: | | `-Enum {{.*}} 'E'
// CHECK-NEXT: | |-CStyleCastExpr {{.*}} <line:15:3, col:30> 'void' <ToVoid>
// CHECK-NEXT: | | `-TypeTraitExpr {{.*}} <col:10, col:30> 'bool' __is_same
+// CHECK-NEXT: | | |-BuiltinType {{.*}} 'int'
+// CHECK-NEXT: | | `-BuiltinType {{.*}} 'float'
// CHECK-NEXT: | `-CStyleCastExpr {{.*}} <line:17:3, col:47> 'void' <ToVoid>
// CHECK-NEXT: | `-TypeTraitExpr {{.*}} <col:10, col:47> 'bool' __is_constructible
+// CHECK-NEXT: |-BuiltinType {{.*}} 'int'
+// CHECK-NEXT: |-BuiltinType {{.*}} 'int'
+// CHECK-NEXT: |-BuiltinType {{.*}} 'int'
+// CHECK-NEXT: `-BuiltinType {{.*}} 'int'
// CHECK-NEXT: |-FunctionDecl {{.*}} <line:20:1, line:23:1> line:20:6{{( imported)?}} test_array_type_trait 'void ()'
// CHECK-NEXT: | `-CompoundStmt {{.*}} <col:30, line:23:1>
// CHECK-NEXT: | `-CStyleCastExpr {{.*}} <line:22:3, col:34> 'void' <ToVoid>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that exposing these as children is the better option here, right? That way it would better model a CallExpr or template type-trait, and would work in our StmtProfiler et-al.
Agree that exposing them as children is better. However, we encounter an implementation limitation. For |
The argument types are not modeled as children of TypeTraitExpr, therefore they are not dumped with the default implementation.
Dumping them is really useful for ad-hoc debugging, context #89358