[clang] [CIR] Implement NRVO variable cleanup (PR #170774)

Amr Hesham via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 5 11:21:23 PST 2025


================
@@ -835,7 +835,24 @@ template <class Derived> struct DestroyNRVOVariable : EHScopeStack::Cleanup {
   QualType ty;
 
   void emit(CIRGenFunction &cgf, Flags flags) override {
-    assert(!cir::MissingFeatures::cleanupDestroyNRVOVariable());
+    // Along the exceptions path we always execute the dtor.
+    bool nrvo = flags.isForNormalCleanup() && nrvoFlag;
+
+    CIRGenBuilderTy &builder = cgf.getBuilder();
+    mlir::OpBuilder::InsertionGuard guard(builder);
+    mlir::Location loc = addr.getPointer().getLoc();
----------------
AmrDeveloper wrote:

If `loc` will be used only inside the if block, should we move it inside it 🤔 

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


More information about the cfe-commits mailing list