summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2024-01-31 14:17:00 +0100
committerTimm Bäder <tbaeder@redhat.com>2024-02-01 07:09:43 +0100
commita8f317aeaccaa052c9c4cfa4660c40554fbbf223 (patch)
treea361327b4f151921f99c9a962651a66c3c98d2b1
parentfdd98e506d77514d8cbd5099e8fc98130244f6ff (diff)
[clang][Interp] complex binary operators aren't always initializing
The added test case would trigger the removed assertion.
-rw-r--r--clang/lib/AST/Interp/ByteCodeExprGen.cpp9
-rw-r--r--clang/test/AST/Interp/complex.cpp10
2 files changed, 18 insertions, 1 deletions
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d2d47e60b2c4..d307739c301e 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -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();
diff --git a/clang/test/AST/Interp/complex.cpp b/clang/test/AST/Interp/complex.cpp
index 8c57df7d9a3e..bb230c2ebe64 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -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, "");