diff options
| author | Chandler Carruth <chandlerc@gmail.com> | 2014-05-03 09:16:57 +0000 |
|---|---|---|
| committer | Chandler Carruth <chandlerc@gmail.com> | 2014-05-03 09:16:57 +0000 |
| commit | 5baeb1d06e5d0f15c9e529838aa98e46f1e23efa (patch) | |
| tree | 6d043bd6be8bf74838994a31e6222eadadd0eb95 /lib/CodeGen/CGExprCXX.cpp | |
| parent | 589e7ecc89ab442e83703fa572ef046946c01df1 (diff) | |
| download | clang-5baeb1d06e5d0f15c9e529838aa98e46f1e23efa.tar.gz clang-5baeb1d06e5d0f15c9e529838aa98e46f1e23efa.tar.bz2 clang-5baeb1d06e5d0f15c9e529838aa98e46f1e23efa.tar.xz | |
[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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207900 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprCXX.cpp')
| -rw-r--r-- | lib/CodeGen/CGExprCXX.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp index f71a3debe2..3a116062b8 100644 --- a/lib/CodeGen/CGExprCXX.cpp +++ b/lib/CodeGen/CGExprCXX.cpp @@ -814,20 +814,22 @@ CodeGenFunction::EmitNewArrayInitializer(const CXXNewExpr *E, explicitPtr = Builder.CreateBitCast(explicitPtr, beginPtr->getType()); } + llvm::ConstantInt *constNum = dyn_cast<llvm::ConstantInt>(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<llvm::ConstantInt>(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"); |
