Skip to content

Commit

Permalink
[clang][Interp] Fix _Complex comma operators
Browse files Browse the repository at this point in the history
Handle them before shelling out to visitComplexBinOp().
  • Loading branch information
tbaederr committed Mar 18, 2024
1 parent 0c21377 commit d56110f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
21 changes: 11 additions & 10 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,17 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
const Expr *LHS = BO->getLHS();
const Expr *RHS = BO->getRHS();

// Handle comma operators. Just discard the LHS
// and delegate to RHS.
if (BO->isCommaOp()) {
if (!this->discard(LHS))
return false;
if (RHS->getType()->isVoidType())
return this->discard(RHS);

return this->delegate(RHS);
}

if (BO->getType()->isAnyComplexType())
return this->VisitComplexBinOp(BO);
if ((LHS->getType()->isAnyComplexType() ||
Expand All @@ -416,16 +427,6 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
std::optional<PrimType> RT = classify(RHS->getType());
std::optional<PrimType> T = classify(BO->getType());

// Deal with operations which have composite or void types.
if (BO->isCommaOp()) {
if (!this->discard(LHS))
return false;
if (RHS->getType()->isVoidType())
return this->discard(RHS);

return this->delegate(RHS);
}

// Special case for C++'s three-way/spaceship operator <=>, which
// returns a std::{strong,weak,partial}_ordering (which is a class, so doesn't
// have a PrimType).
Expand Down
3 changes: 3 additions & 0 deletions clang/test/AST/Interp/complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ static_assert(&__imag z1 == &__real z1 + 1, "");
static_assert((*(&__imag z1)) == __imag z1, "");
static_assert((*(&__real z1)) == __real z1, "");

constexpr _Complex int Comma1 = {1, 2};
constexpr _Complex int Comma2 = (0, Comma1);
static_assert(Comma1 == Comma1, "");

constexpr double setter() {
_Complex float d = {1.0, 2.0};
Expand Down

0 comments on commit d56110f

Please sign in to comment.