[clang] [CIR][ABI] Handle callee-destructed params for trivial_abi (PR #191257)

via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 14 13:51:46 PDT 2026


================
@@ -1311,13 +1311,26 @@ void CIRGenFunction::emitCallArg(CallArgList &args, const clang::Expr *e,
 
   bool hasAggregateEvalKind = hasAggregateEvaluationKind(argType);
 
-  // In the Microsoft C++ ABI, aggregate arguments are destructed by the callee.
-  // However, we still have to push an EH-only cleanup in case we unwind before
-  // we make it to the call.
+  // For callee-destructed parameters (trivial_abi, MS ABI), create an
+  // aggregate temp and let the callee destroy it.
   if (argType->isRecordType() &&
       argType->castAsRecordDecl()->isParamDestroyedInCallee()) {
-    assert(!cir::MissingFeatures::msabi());
-    cgm.errorNYI(e->getSourceRange(), "emitCallArg: msabi is NYI");
+    AggValueSlot slot = createAggTemp(argType, getLoc(e->getSourceRange()),
+                                      getCounterAggTmpAsString());
+
+    bool destroyedInCallee = true;
+    if (const auto *rd = argType->getAsCXXRecordDecl())
+      destroyedInCallee = rd->hasNonTrivialDestructor();
+
+    if (destroyedInCallee)
+      slot.setExternallyDestructed();
+
+    emitAggExpr(e, slot);
+    RValue rv = slot.asRValue();
+    args.add(rv, argType);
+
+    assert(!cir::MissingFeatures::ehCleanupScope());
----------------
adams381 wrote:

Done -- replaced the assert with `errorNYI` guarded on `getLangOpts().Exceptions` (line 1332).  Also removed `-fcxx-exceptions -fexceptions` from the RUN lines since the test verifies the non-EH path.

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


More information about the cfe-commits mailing list