[clang] a2da7d0 - [clang][Interp] Ignore LValueToRValue casts before doing the load
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 2 00:00:26 PST 2024
Author: Timm Bäder
Date: 2024-02-02T08:46:55+01:00
New Revision: a2da7d06c7e1ec75812ff8ced29541d4af3668c9
URL: https://github.com/llvm/llvm-project/commit/a2da7d06c7e1ec75812ff8ced29541d4af3668c9
DIFF: https://github.com/llvm/llvm-project/commit/a2da7d06c7e1ec75812ff8ced29541d4af3668c9.diff
LOG: [clang][Interp] Ignore LValueToRValue casts before doing the load
If the SubExpr results in an invalid pointer, we will otherwise
reject the constant expression.
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/c.c
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 01555b0fc7dac..3ca4f56903fda 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -78,6 +78,9 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
switch (CE->getCastKind()) {
case CK_LValueToRValue: {
+ if (DiscardResult)
+ return this->discard(SubExpr);
+
return dereference(
SubExpr, DerefKind::Read,
[](PrimType) {
@@ -86,9 +89,7 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
},
[this, CE](PrimType T) {
// Pointer on stack - dereference it.
- if (!this->emitLoadPop(T, CE))
- return false;
- return DiscardResult ? this->emitPop(T, CE) : true;
+ return this->emitLoadPop(T, CE);
});
}
diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index df3807b371dea..bf5394b701587 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -98,3 +98,15 @@ void f (int z) {
int expr;
int chooseexpr[__builtin_choose_expr(1, 1, expr)];
+
+int somefunc(int i) {
+ return (i, 65537) * 65537; // expected-warning {{left operand of comma operator has no effect}} \
+ // expected-warning {{overflow in expression; result is 131073}} \
+ // pedantic-expected-warning {{left operand of comma operator has no effect}} \
+ // pedantic-expected-warning {{overflow in expression; result is 131073}} \
+ // ref-warning {{left operand of comma operator has no effect}} \
+ // ref-warning {{overflow in expression; result is 131073}} \
+ // pedantic-ref-warning {{left operand of comma operator has no effect}} \
+ // pedantic-ref-warning {{overflow in expression; result is 131073}}
+
+}
More information about the cfe-commits
mailing list