aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2024-03-18 14:55:29 +0100
committerTimm Bäder <tbaeder@redhat.com>2024-03-18 16:02:40 +0100
commitd56110fa025b58e57602a254c841e6e41ea46a42 (patch)
tree18a681daf34e0d51b90928f4db14d44edc682c6e
parent0c21377aeafc523bd4a8c40bd27e33498f3199f7 (diff)
downloadllvm-d56110fa025b58e57602a254c841e6e41ea46a42.zip
llvm-d56110fa025b58e57602a254c841e6e41ea46a42.tar.gz
llvm-d56110fa025b58e57602a254c841e6e41ea46a42.tar.bz2
[clang][Interp] Fix _Complex comma operators
Handle them before shelling out to visitComplexBinOp().
-rw-r--r--clang/lib/AST/Interp/ByteCodeExprGen.cpp21
-rw-r--r--clang/test/AST/Interp/complex.cpp3
2 files changed, 14 insertions, 10 deletions
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d943dcb..af214d4 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -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() ||
@@ -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).
diff --git a/clang/test/AST/Interp/complex.cpp b/clang/test/AST/Interp/complex.cpp
index d4e3d5a..09cb620 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -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};