[clang] [clang][Interp] Implement integral->complex casts (PR #75590)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 15 05:39:22 PST 2024


================
@@ -283,6 +283,28 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
   case CK_ToVoid:
     return discard(SubExpr);
 
+  case CK_IntegralRealToComplex:
+  case CK_FloatingRealToComplex: {
+    // We're creating a complex value here, so we need to
+    // allocate storage for it.
+    if (!Initializing) {
+      std::optional<unsigned> LocalIndex =
+          allocateLocal(CE, /*IsExtended=*/true);
+      if (!LocalIndex)
+        return false;
+      if (!this->emitGetPtrLocal(*LocalIndex, CE))
+        return false;
+    }
+
+    if (!this->visitArrayElemInit(0, SubExpr))
----------------
AaronBallman wrote:

Might as well add a comment as to why we zero init.

https://github.com/llvm/llvm-project/pull/75590


More information about the cfe-commits mailing list