Author: Timm Bäder
Date: 2024-02-01T07:09:43+01:00
New Revision: a8f317aeaccaa052c9c4cfa4660c40554fbbf223

URL: 
https://github.com/llvm/llvm-project/commit/a8f317aeaccaa052c9c4cfa4660c40554fbbf223
DIFF: 
https://github.com/llvm/llvm-project/commit/a8f317aeaccaa052c9c4cfa4660c40554fbbf223.diff

LOG: [clang][Interp] complex binary operators aren't always initializing

The added test case would trigger the removed assertion.

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 d2d47e60b2c4d..d307739c301ef 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 8c57df7d9a3ed..bb230c2ebe64d 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, "");


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to