aboutsummaryrefslogtreecommitdiff
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)
downloadllvm-a8f317aeaccaa052c9c4cfa4660c40554fbbf223.zip
llvm-a8f317aeaccaa052c9c4cfa4660c40554fbbf223.tar.gz
llvm-a8f317aeaccaa052c9c4cfa4660c40554fbbf223.tar.bz2
[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 d2d47e6..d307739 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 8c57df7..bb230c2 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, "");