Skip to content

Commit a8f317a

Browse files
committed
[clang][Interp] complex binary operators aren't always initializing
The added test case would trigger the removed assertion.
1 parent fdd98e5 commit a8f317a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,14 @@ bool ByteCodeExprGen<Emitter>::VisitLogicalBinOp(const BinaryOperator *E) {
651651

652652
template <class Emitter>
653653
bool ByteCodeExprGen<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
654-
assert(Initializing);
654+
// Prepare storage for result.
655+
if (!Initializing) {
656+
std::optional<unsigned> LocalIndex = allocateLocal(E, /*IsExtended=*/false);
657+
if (!LocalIndex)
658+
return false;
659+
if (!this->emitGetPtrLocal(*LocalIndex, E))
660+
return false;
661+
}
655662

656663
const Expr *LHS = E->getLHS();
657664
const Expr *RHS = E->getRHS();

clang/test/AST/Interp/complex.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ static_assert(__imag(I3) == 0, "");
9393
/// FIXME: This should work in the new interpreter as well.
9494
// constexpr _Complex _BitInt(8) A = 0;// = {4};
9595

96+
97+
void func(void) {
98+
__complex__ int arr;
99+
_Complex int result;
100+
int ii = 0;
101+
int bb = 0;
102+
/// The following line will call into the constant interpreter.
103+
result = arr * ii;
104+
}
105+
96106
namespace CastToBool {
97107
constexpr _Complex int F = {0, 1};
98108
static_assert(F, "");

0 commit comments

Comments
 (0)