Skip to content

Commit 01868ea

Browse files
ofAlpacaAaronBallman
authored andcommitted
[Clang] Fix -ast-dump-decl-types crashes on concepts (llvm#108142)
Resolve llvm#94928 This PR adds `if (TD->getTemplateDecl())` to prevent `InnerD` becoming `nullptr`, suggested by @firstmoonlight. I also add `-ast-dump-decl-types` option and declare type `CHECK` to the testcase `clang/test/AST/ast-dump-concepts.cpp`. --------- Co-authored-by: Aaron Ballman <[email protected]>
1 parent e758e7c commit 01868ea

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ Miscellaneous Clang Crashes Fixed
427427
- Fixed a crash when function has more than 65536 parameters.
428428
Now a diagnostic is emitted. (#GH35741)
429429

430+
- Fixed ``-ast-dump`` crashes on codes involving ``concept`` with ``-ast-dump-decl-types``. (#GH94928)
431+
430432
OpenACC Specific Changes
431433
------------------------
432434

clang/lib/Frontend/ASTConsumers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ namespace {
101101
if (DumpDeclTypes) {
102102
Decl *InnerD = D;
103103
if (auto *TD = dyn_cast<TemplateDecl>(D))
104-
InnerD = TD->getTemplatedDecl();
104+
if (Decl *TempD = TD->getTemplatedDecl())
105+
InnerD = TempD;
105106

106107
// FIXME: Support OutputFormat in type dumping.
107108
// FIXME: Support combining -ast-dump-decl-types with -ast-dump-lookups.

clang/test/AST/ast-dump-concepts.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++2a -ast-dump -ast-dump-filter Foo %s | FileCheck -strict-whitespace %s
1+
// 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
22

33
// Test with serialization:
44
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown -emit-pch -o %t %s
55
// RUN: %clang_cc1 -x c++ -std=c++20 -triple x86_64-unknown-unknown -include-pch %t \
6-
// RUN: -ast-dump-all -ast-dump-filter Foo /dev/null \
6+
// RUN: -ast-dump-all -ast-dump-decl-types -ast-dump-filter Foo /dev/null \
77
// RUN: | FileCheck --strict-whitespace %s
88

99
template <typename T>
@@ -56,6 +56,9 @@ struct Foo {
5656
// CHECK: CXXFoldExpr {{.*}} <col:13, col:34>
5757
template <variadic_concept<int>... Ts>
5858
Foo();
59+
60+
// CHECK:InjectedClassNameType
61+
// CHECK-NEXT: CXXRecord {{.*}} 'Foo'
5962
};
6063

6164
namespace GH82628 {
@@ -75,20 +78,28 @@ template <typename T>
7578
concept Foo = C<T>;
7679

7780
// CHECK: TemplateTypeParmDecl {{.*}} Concept {{.*}} 'C' (UsingShadow {{.*}} 'C')
81+
// CHECK: QualType
82+
// CHECK-NEXT: `-BuiltinType {{.*}} 'bool'
7883
template <C T>
7984
constexpr bool FooVar = false;
8085

8186
// CHECK: ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C'
87+
// CHECK: QualType
88+
// CHECK-NEXT: `-BuiltinType {{.*}} 'bool'
8289
template <typename T> requires C<T>
8390
constexpr bool FooVar2 = true;
8491

8592
// CHECK: SimpleRequirement
8693
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C'
94+
// CHECK: QualType
95+
// CHECK-NEXT: `-BuiltinType {{.*}} 'bool'
8796
template <typename T> requires requires (T) { C<T>; }
8897
constexpr bool FooVar3 = true;
8998

9099
// CHECK: NonTypeTemplateParmDecl
91100
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C'
101+
// CHECK: QualType
102+
// CHECK-NEXT: `-BuiltinType {{.*}} 'bool'
92103
template <C auto T>
93104
constexpr bool FooVar4 = bool(T());
94105

@@ -97,7 +108,9 @@ constexpr bool FooVar4 = bool(T());
97108
// CHECK: NonTypeTemplateParmDecl {{.*}} depth 0 index 1 U
98109
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C'
99110
// CHECK: |-TemplateTypeParmDecl {{.*}} Concept {{.*}} 'C' (UsingShadow {{.*}} 'C') depth 0 index 2 V:auto
100-
111+
// CHECK: FunctionProtoType
112+
// CHECK: `-Concept {{.*}} 'C'
113+
// CHECK: `-TemplateTypeParm {{.*}} 'V:auto'
101114
template <C... T, C auto U>
102115
auto FooFunc(C auto V) -> C decltype(auto) {
103116
// FIXME: TypeLocs inside of the function body cannot be dumped via -ast-dump for now.

0 commit comments

Comments
 (0)