-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][Interp] Bail out on missing ComparisonCategoryInfo #80131
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
Conversation
Instead of asserting. This can happen in real-world code.
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesInstead of asserting. This can happen in real-world code. Full diff: https://github.com/llvm/llvm-project/pull/80131.diff 2 Files Affected:
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 8188d6f7f5c24..a1c458a09e5ae 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -379,7 +379,8 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
return true;
const ComparisonCategoryInfo *CmpInfo =
Ctx.getASTContext().CompCategories.lookupInfoForType(BO->getType());
- assert(CmpInfo);
+ if (!CmpInfo)
+ return false;
// We need a temporary variable holding our return value.
if (!Initializing) {
diff --git a/clang/test/Sema/struct-cast.c b/clang/test/Sema/struct-cast.c
index 74d00c42c295e..05e5fa4f92ca7 100644
--- a/clang/test/Sema/struct-cast.c
+++ b/clang/test/Sema/struct-cast.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only %s -verify
+// RUN: %clang_cc1 -fsyntax-only %s -fexperimental-new-constant-interpreter -verify
// expected-no-diagnostics
struct S {
|
Ping |
@@ -1,4 +1,5 @@ | |||
// RUN: %clang_cc1 -fsyntax-only %s -verify | |||
// RUN: %clang_cc1 -fsyntax-only %s -fexperimental-new-constant-interpreter -verify |
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.
I'm really confused what this test has to do with the changes above. The changes relate to three-way comparison operators but this test is a C test file and has no comparison operators involved. Why would this test hit that assertion?
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.
The AST we trip up on is
BinaryOperator 0x52100006ed08 'struct S' '='
|-DeclRefExpr 0x52100006eba0 'struct S' lvalue Var 0x52100006e998 'tmp' 'struct S'
`-CStyleCastExpr 0x52100006ecd8 'struct S' <NoOp>
`-CallExpr 0x52100006ec88 'struct S'
`-ImplicitCastExpr 0x52100006ec68 'const struct S (*)(void)' <FunctionToPointerDecay>
`-DeclRefExpr 0x52100006ebc8 'const struct S (void)' Function 0x52100006e870 'foo' 'const struct S (void)'
IIUC this should be rejected since the assignment doesn't work, but we're asserting that we found CmpInfo
. We could of course also add more assertions that we're even in C++ mode when looking for the spaceship operator stuff.
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.
Why should this assignment not work? (The code looks valid to me). Oh, wait, you mean this assignment shouldn't be a constant expression? (If so, I agree.)
That said, I see now why we're hitting the assertion on an assignment operator in C; the call to lookupInfoForType()
will return nullptr
in that case and we need to handle that.
I don't think we want to look for the spaceship operator stuff outside of C++ mode, but that can be done in a follow-up as this is fixing a failing assertion.
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.
Yes, what I mean is, the constant interpreter should return false
for this assignment in C.
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.
Excellent, thank you!
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!
@@ -1,4 +1,5 @@ | |||
// RUN: %clang_cc1 -fsyntax-only %s -verify | |||
// RUN: %clang_cc1 -fsyntax-only %s -fexperimental-new-constant-interpreter -verify |
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.
Excellent, thank you!
Instead of asserting. This can happen in real-world code.