llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: cor3ntin (cor3ntin) <details> <summary>Changes</summary> Fix a crash caused by incorrect assumptions Reported here https://github.com/llvm/llvm-project/pull/72644#discussion_r1469525524 --- Full diff: https://github.com/llvm/llvm-project/pull/80439.diff 2 Files Affected: - (modified) clang/lib/AST/TypePrinter.cpp (+3-3) - (added) clang/test/AST/ast-dump-pack-indexing-crash.cpp (+24) ``````````diff diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index 63e56a8296db3..281f529ee1f75 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...{{.*}}' + +} `````````` </details> https://github.com/llvm/llvm-project/pull/80439 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits