Skip to content

Commit

Permalink
[clang][Interp] complex binary operators aren't always initializing
Browse files Browse the repository at this point in the history
The added test case would trigger the removed assertion.
  • Loading branch information
tbaederr committed Feb 1, 2024
1 parent fdd98e5 commit a8f317a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,14 @@ bool ByteCodeExprGen<Emitter>::VisitLogicalBinOp(const BinaryOperator *E) {

template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
assert(Initializing);
// Prepare storage for result.
if (!Initializing) {
std::optional<unsigned> LocalIndex = allocateLocal(E, /*IsExtended=*/false);
if (!LocalIndex)
return false;
if (!this->emitGetPtrLocal(*LocalIndex, E))
return false;
}

const Expr *LHS = E->getLHS();
const Expr *RHS = E->getRHS();
Expand Down
10 changes: 10 additions & 0 deletions clang/test/AST/Interp/complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ static_assert(__imag(I3) == 0, "");
/// FIXME: This should work in the new interpreter as well.
// constexpr _Complex _BitInt(8) A = 0;// = {4};


void func(void) {
__complex__ int arr;
_Complex int result;
int ii = 0;
int bb = 0;
/// The following line will call into the constant interpreter.
result = arr * ii;
}

namespace CastToBool {
constexpr _Complex int F = {0, 1};
static_assert(F, "");
Expand Down

0 comments on commit a8f317a

Please sign in to comment.