[clang] 9bec1ef - [clang][Interp] assignments aren't always lvalues in C
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 20 03:27:47 PST 2024
Author: Timm Bäder
Date: 2024-02-20T12:26:15+01:00
New Revision: 9bec1ef5f97b1f3cf2b994dced73268ebb312972
URL: https://github.com/llvm/llvm-project/commit/9bec1ef5f97b1f3cf2b994dced73268ebb312972
DIFF: https://github.com/llvm/llvm-project/commit/9bec1ef5f97b1f3cf2b994dced73268ebb312972.diff
LOG: [clang][Interp] assignments aren't always lvalues in C
If they aren't we need to load from the pointer the Store op
leaves on the stack.
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 d4b285941d46d1..70e2bca2ebf16d 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -505,8 +505,18 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
if (DiscardResult)
return LHS->refersToBitField() ? this->emitStoreBitFieldPop(*T, BO)
: this->emitStorePop(*T, BO);
- return LHS->refersToBitField() ? this->emitStoreBitField(*T, BO)
- : this->emitStore(*T, BO);
+ if (LHS->refersToBitField()) {
+ if (!this->emitStoreBitField(*T, BO))
+ return false;
+ } else {
+ if (!this->emitStore(*T, BO))
+ return false;
+ }
+ // Assignments aren't necessarily lvalues in C.
+ // Load from them in that case.
+ if (!BO->isLValue())
+ return this->emitLoadPop(*T, BO);
+ return true;
case BO_And:
return Discard(this->emitBitAnd(*T, BO));
case BO_Or:
diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 168b56988d065f..b67fe93417058e 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -171,3 +171,9 @@ const _Bool CTB3 = (_Complex double){0.0, 1.0}; // pedantic-ref-warning {{extens
_Static_assert(CTB3, ""); // pedantic-ref-warning {{GNU extension}} \
// pedantic-expected-warning {{GNU extension}}
+
+int t1 = sizeof(int);
+void test4(void) {
+ t1 = sizeof(int);
+}
+
More information about the cfe-commits
mailing list