[clang] [CIR] Implement Unary real & imag on scalar expr (PR #159916)

Amr Hesham via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 23 08:59:37 PDT 2025


================
@@ -2147,11 +2148,23 @@ mlir::Value ScalarExprEmitter::VisitRealImag(const UnaryOperator *e,
     return {};
   }
 
-  // __real or __imag on a scalar returns zero. Emit the subexpr to ensure side
+  if (e->getOpcode() == UO_Real) {
+    return promotionTy.isNull() ? Visit(op)
+                                : cgf.emitPromotedScalarExpr(op, promotionTy);
+  }
+
+  // __imag on a scalar returns zero. Emit the subexpr to ensure side
   // effects are evaluated, but not the actual value.
-  cgf.cgm.errorNYI(e->getSourceRange(),
-                   "VisitRealImag __real or __imag on a scalar");
-  return {};
+  if (op->isGLValue())
----------------
AmrDeveloper wrote:

Sure, I will rename them and also add one case to cover the else branch

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


More information about the cfe-commits mailing list