[clang] [clang-tools-extra] [codegen] Emit missing cleanups when an expression contains a branch (PR #80698)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 19 12:59:09 PST 2024


================
@@ -592,10 +590,14 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
       // observed to be unnecessary.
       if (endOfInit.isValid()) Builder.CreateStore(element, endOfInit);
     }
-
-    LValue elementLV = CGF.MakeAddrLValue(
-        Address(element, llvmElementType, elementAlign), elementType);
+    Address address = Address(element, llvmElementType, elementAlign);
+    LValue elementLV = CGF.MakeAddrLValue(address, elementType);
     EmitInitializationToLValue(Args[i], elementLV);
+    // Schedule to emit element cleanup if we see a branch in the array
+    // initialisation expression.
+    if (CGF.needsBranchCleanup(dtorKind))
+      CGF.pushDestroy(BranchInExprCleanup, address, elementType,
----------------
usx95 wrote:

Can you please tell me how to verify that mem2reg will clear these stores.
If we can use this cleanup as-is, then we should be able to reuse the EHCleanups without introducing another cleanup stack (as also pointed out by @jyknight).

It is important that we do not introduce these stores with exceptions disabled. But from the looks of it, it should be a easy optimisation pass as the store would never be read in normal circumstances.

This is the only blocker in the reusing EH-only cleanups which . 

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


More information about the cfe-commits mailing list