[clang] -ast-dump-decl-types crashes on codes involving concepts #94928 (PR #108142)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 18 05:55:08 PDT 2024
https://github.com/ofAlpaca updated https://github.com/llvm/llvm-project/pull/108142
>From efcf875af403831bbd4d472a9a3a9fbff4438753 Mon Sep 17 00:00:00 2001
From: ofAlpaca <frank70199 at gmail.com>
Date: Wed, 11 Sep 2024 11:24:55 +0800
Subject: [PATCH 1/3] [clang] Fix TemplatedDecl being nullptr and cause crash
---
clang/lib/Frontend/ASTConsumers.cpp | 3 ++-
clang/test/AST/ast-dump-concepts.cpp | 19 ++++++++++++++++---
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/clang/lib/Frontend/ASTConsumers.cpp b/clang/lib/Frontend/ASTConsumers.cpp
index 7b58eaa04df95a..8a2e3b032ace28 100644
--- a/clang/lib/Frontend/ASTConsumers.cpp
+++ b/clang/lib/Frontend/ASTConsumers.cpp
@@ -101,7 +101,8 @@ namespace {
if (DumpDeclTypes) {
Decl *InnerD = D;
if (auto *TD = dyn_cast<TemplateDecl>(D))
- InnerD = TD->getTemplatedDecl();
+ if (TD->getTemplatedDecl())
+ InnerD = TD->getTemplatedDecl();
// FIXME: Support OutputFormat in type dumping.
// FIXME: Support combining -ast-dump-decl-types with -ast-dump-lookups.
diff --git a/clang/test/AST/ast-dump-concepts.cpp b/clang/test/AST/ast-dump-concepts.cpp
index a5e0673c241ef4..84d981d2ab8dec 100644
--- a/clang/test/AST/ast-dump-concepts.cpp
+++ b/clang/test/AST/ast-dump-concepts.cpp
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++2a -ast-dump -ast-dump-filter Foo %s | FileCheck -strict-whitespace %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++2a -ast-dump -ast-dump-decl-types -ast-dump-filter Foo %s | FileCheck -strict-whitespace %s
// Test with serialization:
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown -emit-pch -o %t %s
// RUN: %clang_cc1 -x c++ -std=c++20 -triple x86_64-unknown-unknown -include-pch %t \
-// RUN: -ast-dump-all -ast-dump-filter Foo /dev/null \
+// RUN: -ast-dump-all -ast-dump-decl-types -ast-dump-filter Foo /dev/null \
// RUN: | FileCheck --strict-whitespace %s
template <typename T>
@@ -56,6 +56,9 @@ struct Foo {
// CHECK: CXXFoldExpr {{.*}} <col:13, col:34>
template <variadic_concept<int>... Ts>
Foo();
+
+ // CHECK:InjectedClassNameType
+ // CHECK-NEXT: CXXRecord {{.*}} 'Foo'
};
namespace GH82628 {
@@ -75,20 +78,28 @@ template <typename T>
concept Foo = C<T>;
// CHECK: TemplateTypeParmDecl {{.*}} Concept {{.*}} 'C' (UsingShadow {{.*}} 'C')
+// CHECK: QualType
+// CHECK-NEXT: `-BuiltinType {{.*}} 'bool'
template <C T>
constexpr bool FooVar = false;
// CHECK: ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C'
+// CHECK: QualType
+// CHECK-NEXT: `-BuiltinType {{.*}} 'bool'
template <typename T> requires C<T>
constexpr bool FooVar2 = true;
// CHECK: SimpleRequirement
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C'
+// CHECK: QualType
+// CHECK-NEXT: `-BuiltinType {{.*}} 'bool'
template <typename T> requires requires (T) { C<T>; }
constexpr bool FooVar3 = true;
// CHECK: NonTypeTemplateParmDecl
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C'
+// CHECK: QualType
+// CHECK-NEXT: `-BuiltinType {{.*}} 'bool'
template <C auto T>
constexpr bool FooVar4 = bool(T());
@@ -97,7 +108,9 @@ constexpr bool FooVar4 = bool(T());
// CHECK: NonTypeTemplateParmDecl {{.*}} depth 0 index 1 U
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C'
// CHECK: |-TemplateTypeParmDecl {{.*}} Concept {{.*}} 'C' (UsingShadow {{.*}} 'C') depth 0 index 2 V:auto
-
+// CHECK: FunctionProtoType
+// CHECK: `-Concept {{.*}} 'C'
+// CHECK: `-TemplateTypeParm {{.*}} 'V:auto'
template <C... T, C auto U>
auto FooFunc(C auto V) -> C decltype(auto) {
// FIXME: TypeLocs inside of the function body cannot be dumped via -ast-dump for now.
>From 7fa2d8ef4d4d8caeeefb99f7781c068b70358ac4 Mon Sep 17 00:00:00 2001
From: ofAlpaca <frank70199 at gmail.com>
Date: Wed, 18 Sep 2024 14:00:46 +0800
Subject: [PATCH 2/3] Update clang/lib/Frontend/ASTConsumers.cpp
Co-authored-by: Aaron Ballman <aaron at aaronballman.com>
---
clang/lib/Frontend/ASTConsumers.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Frontend/ASTConsumers.cpp b/clang/lib/Frontend/ASTConsumers.cpp
index 8a2e3b032ace28..a6e35452b4fbe6 100644
--- a/clang/lib/Frontend/ASTConsumers.cpp
+++ b/clang/lib/Frontend/ASTConsumers.cpp
@@ -101,8 +101,8 @@ namespace {
if (DumpDeclTypes) {
Decl *InnerD = D;
if (auto *TD = dyn_cast<TemplateDecl>(D))
- if (TD->getTemplatedDecl())
- InnerD = TD->getTemplatedDecl();
+ if (Decl *TempD = TD->getTemplatedDecl())
+ InnerD = TempD;
// FIXME: Support OutputFormat in type dumping.
// FIXME: Support combining -ast-dump-decl-types with -ast-dump-lookups.
>From 5f64229cef2a72bfe8f3e7d6f430cba0e307e97e Mon Sep 17 00:00:00 2001
From: ofAlpaca <frank70199 at gmail.com>
Date: Wed, 18 Sep 2024 20:54:58 +0800
Subject: [PATCH 3/3] Update ReleaseNotes.rst
---
clang/docs/ReleaseNotes.rst | 2 ++
1 file changed, 2 insertions(+)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7b612e3c65f494..421fa00bac7ec5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -426,6 +426,8 @@ Miscellaneous Clang Crashes Fixed
- Fixed a crash when function has more than 65536 parameters.
Now a diagnostic is emitted. (#GH35741)
+- Fixed ``-ast-dump`` crashes on codes involving ``concept`` with ``-ast-dump-decl-types``. (#GH94928)
+
OpenACC Specific Changes
------------------------
More information about the cfe-commits
mailing list