[clang] 7a94acb - [Clang] Fix a crash when dumping a pack indexing type. (#80439)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 2 15:09:11 PST 2024
Author: cor3ntin
Date: 2024-02-03T00:09:07+01:00
New Revision: 7a94acb2da5b20d12f13f3c5f4eb0f3f46e78e73
URL: https://github.com/llvm/llvm-project/commit/7a94acb2da5b20d12f13f3c5f4eb0f3f46e78e73
DIFF: https://github.com/llvm/llvm-project/commit/7a94acb2da5b20d12f13f3c5f4eb0f3f46e78e73.diff
LOG: [Clang] Fix a crash when dumping a pack indexing type. (#80439)
Fix a crash caused by incorrect assumptions
Reported here
https://github.com/llvm/llvm-project/pull/72644#discussion_r1469525524
Added:
clang/test/AST/ast-dump-pack-indexing-crash.cpp
Modified:
clang/lib/AST/TypePrinter.cpp
Removed:
################################################################################
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..0b0c0b572b5e6
--- /dev/null
+++ b/clang/test/AST/ast-dump-pack-indexing-crash.cpp
@@ -0,0 +1,25 @@
+// 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: DeclStmt {{.*}}
+// CHECK-NEXT: VarDecl {{.*}} a 'NotAPack...{{.*}}'
+// CHECK-NEXT: DeclStmt {{.*}}
+// CHECK-NEXT: VarDecl {{.*}} 'T...{{.*}}'
+// CHECK-NEXT: DeclStmt {{.*}}
+// CHECK-NEXT: VarDecl {{.*}} c 'Tp...{{.*}}'
+
+}
More information about the cfe-commits
mailing list