Skip to content

Commit 9bec1ef

Browse files
committed
[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.
1 parent b3e4686 commit 9bec1ef

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,18 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
505505
if (DiscardResult)
506506
return LHS->refersToBitField() ? this->emitStoreBitFieldPop(*T, BO)
507507
: this->emitStorePop(*T, BO);
508-
return LHS->refersToBitField() ? this->emitStoreBitField(*T, BO)
509-
: this->emitStore(*T, BO);
508+
if (LHS->refersToBitField()) {
509+
if (!this->emitStoreBitField(*T, BO))
510+
return false;
511+
} else {
512+
if (!this->emitStore(*T, BO))
513+
return false;
514+
}
515+
// Assignments aren't necessarily lvalues in C.
516+
// Load from them in that case.
517+
if (!BO->isLValue())
518+
return this->emitLoadPop(*T, BO);
519+
return true;
510520
case BO_And:
511521
return Discard(this->emitBitAnd(*T, BO));
512522
case BO_Or:

clang/test/AST/Interp/c.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,9 @@ const _Bool CTB3 = (_Complex double){0.0, 1.0}; // pedantic-ref-warning {{extens
171171
_Static_assert(CTB3, ""); // pedantic-ref-warning {{GNU extension}} \
172172
// pedantic-expected-warning {{GNU extension}}
173173

174+
175+
int t1 = sizeof(int);
176+
void test4(void) {
177+
t1 = sizeof(int);
178+
}
179+

0 commit comments

Comments
 (0)