[clang] [clang-tools-extra] [codegen] Emit missing cleanups when an expression contains a branch (PR #80698)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 12 15:29:49 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,
----------------
efriedma-quic wrote:
Any thoughts on pushing a cleanup for each array element, vs. using a single cleanup which iterates over the elements, like we do for exceptions?
Is there any chance an ArrayFiller needs a branch cleanup? Off the top of my head, I don't think it's possible because branches exits can only happen in code explicitly written in the current function, but that's a subtle invariant.
https://github.com/llvm/llvm-project/pull/80698
More information about the cfe-commits
mailing list