[clang] [CIR] Support VAArgExpr in CIRGenFunction::emitLValue (PR #248350)

Henrich Lauko via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 4 03:44:16 PST 2026


================
@@ -673,20 +673,10 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
   void VisitVAArgExpr(VAArgExpr *e) {
     // emitVAArg returns an aggregate value (not a pointer) at the CIR level.
     // ABI-specific pointer handling will be done later in LoweringPrepare.
-    mlir::Value vaArgValue = cgf.emitVAArg(e);
-
-    // Create a temporary alloca to hold the aggregate value.
     mlir::Location loc = cgf.getLoc(e->getSourceRange());
-    Address tmpAddr = cgf.createMemTemp(e->getType(), loc, "vaarg.tmp");
-
-    // Store the va_arg result into the temporary.
-    cgf.emitAggregateStore(vaArgValue, tmpAddr);
-
-    // Create an LValue from the temporary address.
-    LValue tmpLValue = cgf.makeAddrLValue(tmpAddr, e->getType());
-
-    // Copy the aggregate value from temporary to destination.
-    emitFinalDestCopy(e->getType(), tmpLValue);
+    AggValueSlot slot = ensureSlot(loc, e->getType());
----------------
xlauko wrote:

When `dest` is ignored, `ensureSlot` makes an `agg.tmp.ensured` and we still copy into it. Classic `EmitAggFinalDestCopy` returns early there, so `(void)va_arg(ap, struct S);` gives no memcpy in OGCG, but an alloca plus memcpy in CIR. `cir.va_arg` has no memory-effect traits, so could we call `emitVAArg` and return before the store when `dest.isIgnored()`, to match?

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


More information about the cfe-commits mailing list