[clang] d56110f - [clang][Interp] Fix _Complex comma operators
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 18 08:02:52 PDT 2024
Author: Timm Bäder
Date: 2024-03-18T16:02:40+01:00
New Revision: d56110fa025b58e57602a254c841e6e41ea46a42
URL: https://github.com/llvm/llvm-project/commit/d56110fa025b58e57602a254c841e6e41ea46a42
DIFF: https://github.com/llvm/llvm-project/commit/d56110fa025b58e57602a254c841e6e41ea46a42.diff
LOG: [clang][Interp] Fix _Complex comma operators
Handle them before shelling out to visitComplexBinOp().
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/complex.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d943dcbe06507b..af214d4a8577c6 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 d4e3d5a46a64fb..09cb620d7b7c39 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};
More information about the cfe-commits
mailing list