From e6c980c41d68fe4251c79479d6111c910e88c87f Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sat, 3 May 2014 09:16:57 +0000 Subject: [leaks] Re-shuffle code such that we don't create a basic block for initializing an array unless we need it. Specifically, position the creation of a new basic block after we've checked all of the cases that bypass the need for it. Fixes another leak in test/CodeGen* found by LSan. llvm-svn: 207900 --- clang/lib/CodeGen/CGExprCXX.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'clang/lib') diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp index f71a3debe2a..3a116062b82 100644 --- a/clang/lib/CodeGen/CGExprCXX.cpp +++ b/clang/lib/CodeGen/CGExprCXX.cpp @@ -814,20 +814,22 @@ CodeGenFunction::EmitNewArrayInitializer(const CXXNewExpr *E, explicitPtr = Builder.CreateBitCast(explicitPtr, beginPtr->getType()); } + llvm::ConstantInt *constNum = dyn_cast(numElements); + + // If all elements have already been initialized, skip the whole loop. + if (constNum && constNum->getZExtValue() <= initializerElements) { + // If there was a cleanup, deactivate it. + if (cleanupDominator) + DeactivateCleanupBlock(cleanup, cleanupDominator); + return; + } + // Create the continuation block. llvm::BasicBlock *contBB = createBasicBlock("new.loop.end"); // If the number of elements isn't constant, we have to now check if there is // anything left to initialize. - if (llvm::ConstantInt *constNum = dyn_cast(numElements)) { - // If all elements have already been initialized, skip the whole loop. - if (constNum->getZExtValue() <= initializerElements) { - // If there was a cleanup, deactivate it. - if (cleanupDominator) - DeactivateCleanupBlock(cleanup, cleanupDominator); - return; - } - } else { + if (!constNum) { llvm::BasicBlock *nonEmptyBB = createBasicBlock("new.loop.nonempty"); llvm::Value *isEmpty = Builder.CreateICmpEQ(explicitPtr, endPtr, "array.isempty"); -- cgit v1.2.3