Skip to content

Commit d56110f

Browse files
committed
[clang][Interp] Fix _Complex comma operators
Handle them before shelling out to visitComplexBinOp().
1 parent 0c21377 commit d56110f

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,17 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
401401
const Expr *LHS = BO->getLHS();
402402
const Expr *RHS = BO->getRHS();
403403

404+
// Handle comma operators. Just discard the LHS
405+
// and delegate to RHS.
406+
if (BO->isCommaOp()) {
407+
if (!this->discard(LHS))
408+
return false;
409+
if (RHS->getType()->isVoidType())
410+
return this->discard(RHS);
411+
412+
return this->delegate(RHS);
413+
}
414+
404415
if (BO->getType()->isAnyComplexType())
405416
return this->VisitComplexBinOp(BO);
406417
if ((LHS->getType()->isAnyComplexType() ||
@@ -416,16 +427,6 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
416427
std::optional<PrimType> RT = classify(RHS->getType());
417428
std::optional<PrimType> T = classify(BO->getType());
418429

419-
// Deal with operations which have composite or void types.
420-
if (BO->isCommaOp()) {
421-
if (!this->discard(LHS))
422-
return false;
423-
if (RHS->getType()->isVoidType())
424-
return this->discard(RHS);
425-
426-
return this->delegate(RHS);
427-
}
428-
429430
// Special case for C++'s three-way/spaceship operator <=>, which
430431
// returns a std::{strong,weak,partial}_ordering (which is a class, so doesn't
431432
// have a PrimType).

clang/test/AST/Interp/complex.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ static_assert(&__imag z1 == &__real z1 + 1, "");
99
static_assert((*(&__imag z1)) == __imag z1, "");
1010
static_assert((*(&__real z1)) == __real z1, "");
1111

12+
constexpr _Complex int Comma1 = {1, 2};
13+
constexpr _Complex int Comma2 = (0, Comma1);
14+
static_assert(Comma1 == Comma1, "");
1215

1316
constexpr double setter() {
1417
_Complex float d = {1.0, 2.0};

0 commit comments

Comments
 (0)