-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang] Fix a crash when dumping a pack indexing type. #80439
Conversation
@llvm/pr-subscribers-clang Author: cor3ntin (cor3ntin) ChangesFix a crash caused by incorrect assumptions Full diff: https://github.com/llvm/llvm-project/pull/80439.diff 2 Files Affected:
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...{{.*}}'
+
+}
|
Fix a crash caused by incorrect assumptions Reported here llvm#72644 (comment)
} | ||
|
||
// CHECK: -FunctionDecl {{.*}} not_pack 'void ()' | ||
// CHECK: |-DeclStmt {{.*}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of testing the spaces/-
and |-
character, just use 'CHECK-NEXT`. Else this can get fraigle due to WS. Else the test looks fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the fragility is from checking the -
and the |-
and the `| `` characters. I'd suggest removing those entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM other than generalizing the test a bit.
5999b51
to
0bbf2c3
Compare
Seems like this didn't really solve the problem reported by @bevin-hansson (at least not completely).
Well. I don't know that much about this. Just noticed that our downstream bots started to fail on this new test case. Maybe we need to look at it on Monday to give more context, I don't have more info right now at least. |
@bjope thanks for letting me know. A reproduction would really help, as upstream bots do not exhibit this behavior at all. |
@cor3ntin , our downstream code is doing some extra semantic checks using code like this in Sema::CheckVariableDeclarationType:
That is hitting the infinite recursion. So we protect the type size calculation by checking if the type is incomplete, dependent, etc. I must say that I don't know that much about this to say what is correct. Maybe out downstream semantic checks should be protected in some more way to avoid this problem. |
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}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you change this to an array, such as
NotAPack...[0] a[2];
then I think you hit the same kind of infinite recursion as we see downstream even without the array nodtation.
Fix a crash caused by incorrect assumptions Reported here llvm#72644 (comment)
Fix a crash caused by incorrect assumptions
Reported here #72644 (comment)