https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/80439
>From 4a726e2685a866539bbe6120fb93c5ad1a3bd1d2 Mon Sep 17 00:00:00 2001 From: Corentin Jabot <corentinja...@gmail.com> Date: Fri, 2 Feb 2024 15:45:02 +0100 Subject: [PATCH 1/3] [Clang] Fix a crash when dumping a pack indexing type. Fix a crash caused by incorrect assumptions Reported here https://github.com/llvm/llvm-project/pull/72644#discussion_r1469525524 --- clang/lib/AST/TypePrinter.cpp | 6 ++--- .../test/AST/ast-dump-pack-indexing-crash.cpp | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 clang/test/AST/ast-dump-pack-indexing-crash.cpp diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index 4363280757714..c2ebe2c500174 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -1195,10 +1195,10 @@ void TypePrinter::printDecltypeBefore(const DecltypeType *T, raw_ostream &OS) { void TypePrinter::printPackIndexingBefore(const PackIndexingType *T, raw_ostream &OS) { - if (T->isInstantiationDependentType()) - OS << T->getPattern() << "...[" << T->getIndexExpr() << "]"; - else + if (T->hasSelectedType()) OS << T->getSelectedType(); + else + OS << T->getPattern() << "...[" << T->getIndexExpr() << "]"; spaceBeforePlaceHolder(OS); } diff --git a/clang/test/AST/ast-dump-pack-indexing-crash.cpp b/clang/test/AST/ast-dump-pack-indexing-crash.cpp new file mode 100644 index 0000000000000..1e4e38e2f7378 --- /dev/null +++ b/clang/test/AST/ast-dump-pack-indexing-crash.cpp @@ -0,0 +1,24 @@ +// RUN: not %clang_cc1 -std=c++2c -ast-dump %s | FileCheck %s + +namespace InvalidPacksShouldNotCrash { + +struct NotAPack; +template <typename T, auto V, template<typename> typename Tp> +void not_pack() { + int i = 0; + i...[0]; // expected-error {{i does not refer to the name of a parameter pack}} + V...[0]; // expected-error {{V does not refer to the name of a parameter pack}} + NotAPack...[0] a; // expected-error{{'NotAPack' does not refer to the name of a parameter pack}} + T...[0] b; // expected-error{{'T' does not refer to the name of a parameter pack}} + Tp...[0] c; // expected-error{{'Tp' does not refer to the name of a parameter pack}} +} + +// CHECK: -FunctionDecl {{.*}} not_pack 'void ()' +// CHECK: |-DeclStmt {{.*}} +// CHECK: | `-VarDecl {{.*}} a 'NotAPack...{{.*}}' +// CHECK: |-DeclStmt {{.*}} +// CHECK: | `-VarDecl {{.*}} 'T...{{.*}}' +// CHECK: `-DeclStmt {{.*}} +// CHECK: `-VarDecl {{.*}} c 'Tp...{{.*}}' + +} >From 0bbf2c304b8fd59c96d35bb96bddea7c590919de Mon Sep 17 00:00:00 2001 From: Corentin Jabot <corentinja...@gmail.com> Date: Fri, 2 Feb 2024 19:13:19 +0100 Subject: [PATCH 2/3] generalize the test --- clang/test/AST/ast-dump-pack-indexing-crash.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/clang/test/AST/ast-dump-pack-indexing-crash.cpp b/clang/test/AST/ast-dump-pack-indexing-crash.cpp index 1e4e38e2f7378..2bfc1bdd9e0f2 100644 --- a/clang/test/AST/ast-dump-pack-indexing-crash.cpp +++ b/clang/test/AST/ast-dump-pack-indexing-crash.cpp @@ -15,10 +15,11 @@ void not_pack() { // CHECK: -FunctionDecl {{.*}} not_pack 'void ()' // CHECK: |-DeclStmt {{.*}} -// CHECK: | `-VarDecl {{.*}} a 'NotAPack...{{.*}}' // CHECK: |-DeclStmt {{.*}} -// CHECK: | `-VarDecl {{.*}} 'T...{{.*}}' -// CHECK: `-DeclStmt {{.*}} -// CHECK: `-VarDecl {{.*}} c 'Tp...{{.*}}' +// CHECK-NEXT: | `-VarDecl {{.*}} a 'NotAPack...{{.*}}' +// CHECK-NEXT: |-DeclStmt {{.*}} +// CHECK-NEXT: | `-VarDecl {{.*}} 'T...{{.*}}' +// CHECK-NEXT: `-DeclStmt {{.*}} +// CHECK-NEXT: `-VarDecl {{.*}} c 'Tp...{{.*}}' } >From e9f4ec9a845c39c9206f93e85b995c2b377b92f0 Mon Sep 17 00:00:00 2001 From: Corentin Jabot <corentinja...@gmail.com> Date: Fri, 2 Feb 2024 19:27:34 +0100 Subject: [PATCH 3/3] generalize the test harder --- clang/test/AST/ast-dump-pack-indexing-crash.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/clang/test/AST/ast-dump-pack-indexing-crash.cpp b/clang/test/AST/ast-dump-pack-indexing-crash.cpp index 2bfc1bdd9e0f2..0b0c0b572b5e6 100644 --- a/clang/test/AST/ast-dump-pack-indexing-crash.cpp +++ b/clang/test/AST/ast-dump-pack-indexing-crash.cpp @@ -13,13 +13,13 @@ void not_pack() { Tp...[0] c; // expected-error{{'Tp' does not refer to the name of a parameter pack}} } -// CHECK: -FunctionDecl {{.*}} not_pack 'void ()' -// CHECK: |-DeclStmt {{.*}} -// CHECK: |-DeclStmt {{.*}} -// CHECK-NEXT: | `-VarDecl {{.*}} a 'NotAPack...{{.*}}' -// CHECK-NEXT: |-DeclStmt {{.*}} -// CHECK-NEXT: | `-VarDecl {{.*}} 'T...{{.*}}' -// CHECK-NEXT: `-DeclStmt {{.*}} -// CHECK-NEXT: `-VarDecl {{.*}} c 'Tp...{{.*}}' +// CHECK: FunctionDecl {{.*}} not_pack 'void ()' +// CHECK: DeclStmt {{.*}} +// CHECK: DeclStmt {{.*}} +// CHECK-NEXT: VarDecl {{.*}} a 'NotAPack...{{.*}}' +// CHECK-NEXT: DeclStmt {{.*}} +// CHECK-NEXT: VarDecl {{.*}} 'T...{{.*}}' +// CHECK-NEXT: DeclStmt {{.*}} +// CHECK-NEXT: VarDecl {{.*}} c 'Tp...{{.*}}' } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits