diff options
author | John McCall <rjmccall@apple.com> | 2011-01-26 19:15:39 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-01-26 19:15:39 +0000 |
commit | 4bbcbda302cba8b1b0d88c20d735d09b483bd005 (patch) | |
tree | c34aff62be9783d6c1ab505f5aa1972132207593 /lib/CodeGen | |
parent | 192e7f7e7f0493f7cdfda1d752e6de340d4e3ffe (diff) |
Fix some obvious bugs in the conditional-cleanup code and then make the
dtor cleanup use it.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124309 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGException.cpp | 3 | ||||
-rw-r--r-- | lib/CodeGen/CGTemporaries.cpp | 58 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.h | 10 |
3 files changed, 15 insertions, 56 deletions
diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp index 5845f1ec02..58af36a56d 100644 --- a/lib/CodeGen/CGException.cpp +++ b/lib/CodeGen/CGException.cpp @@ -179,8 +179,7 @@ llvm::Value *CodeGenFunction::initFullExprCleanup() { // Initialize it to false at a site that's guaranteed to be run // before each evaluation. llvm::BasicBlock *block = OutermostConditional->getStartingBlock(); - new llvm::StoreInst(Builder.getFalse(), run, - block->getFirstNonPHIOrDbg()); + new llvm::StoreInst(Builder.getFalse(), run, &block->back()); // Initialize it to true at the current location. Builder.CreateStore(Builder.getTrue(), run); diff --git a/lib/CodeGen/CGTemporaries.cpp b/lib/CodeGen/CGTemporaries.cpp index cfbd2af990..3b4c50910b 100644 --- a/lib/CodeGen/CGTemporaries.cpp +++ b/lib/CodeGen/CGTemporaries.cpp @@ -16,39 +16,11 @@ using namespace clang; using namespace CodeGen; namespace { - struct DestroyTemporary : EHScopeStack::Cleanup { - const CXXTemporary *Temporary; - llvm::Value *Addr; - llvm::Value *CondPtr; - - DestroyTemporary(const CXXTemporary *Temporary, llvm::Value *Addr, - llvm::Value *CondPtr) - : Temporary(Temporary), Addr(Addr), CondPtr(CondPtr) {} - - void Emit(CodeGenFunction &CGF, bool IsForEH) { - llvm::BasicBlock *CondEnd = 0; - - // If this is a conditional temporary, we need to check the condition - // boolean and only call the destructor if it's true. - if (CondPtr) { - llvm::BasicBlock *CondBlock = - CGF.createBasicBlock("temp.cond-dtor.call"); - CondEnd = CGF.createBasicBlock("temp.cond-dtor.cont"); - - llvm::Value *Cond = CGF.Builder.CreateLoad(CondPtr); - CGF.Builder.CreateCondBr(Cond, CondBlock, CondEnd); - CGF.EmitBlock(CondBlock); - } - - CGF.EmitCXXDestructorCall(Temporary->getDestructor(), - Dtor_Complete, /*ForVirtualBase=*/false, - Addr); - - if (CondPtr) { - // Reset the condition to false. - CGF.Builder.CreateStore(CGF.Builder.getFalse(), CondPtr); - CGF.EmitBlock(CondEnd); - } + struct DestroyTemporary { + static void Emit(CodeGenFunction &CGF, bool forEH, + const CXXDestructorDecl *dtor, llvm::Value *addr) { + CGF.EmitCXXDestructorCall(dtor, Dtor_Complete, /*ForVirtualBase=*/false, + addr); } }; } @@ -56,23 +28,9 @@ namespace { /// Emits all the code to cause the given temporary to be cleaned up. void CodeGenFunction::EmitCXXTemporary(const CXXTemporary *Temporary, llvm::Value *Ptr) { - llvm::AllocaInst *CondPtr = 0; - - // Check if temporaries need to be conditional. If so, we'll create a - // condition boolean, initialize it to 0 and - if (isInConditionalBranch()) { - CondPtr = CreateTempAlloca(llvm::Type::getInt1Ty(VMContext), "cond"); - - // Initialize it to false. This initialization takes place right after - // the alloca insert point. - InitTempAlloca(CondPtr, llvm::ConstantInt::getFalse(VMContext)); - - // Now set it to true. - Builder.CreateStore(Builder.getTrue(), CondPtr); - } - - EHStack.pushCleanup<DestroyTemporary>(NormalAndEHCleanup, - Temporary, Ptr, CondPtr); + pushFullExprCleanup<DestroyTemporary>(NormalAndEHCleanup, + Temporary->getDestructor(), + Ptr); } RValue diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index ea362d3bf1..dcd6173763 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -214,6 +214,7 @@ public: template <class T, class A0, class A1> class UnconditionalCleanup2 : public Cleanup { A0 a0; A1 a1; + public: UnconditionalCleanup2(A0 a0, A1 a1) : a0(a0), a1(a1) {} void Emit(CodeGenFunction &CGF, bool IsForEHCleanup) { T::Emit(CGF, IsForEHCleanup, a0, a1); @@ -226,17 +227,18 @@ public: class ConditionalCleanup2 : public ConditionalCleanup { typedef typename SavedValueInCond<A0>::saved_type A0_saved; typedef typename SavedValueInCond<A1>::saved_type A1_saved; - A0_saved a0; A1_saved a1; + A0_saved a0_saved; + A1_saved a1_saved; void EmitImpl(CodeGenFunction &CGF, bool IsForEHCleanup) { - A0 a0 = SavedValueInCond<A0>::restore(CGF, a0); - A1 a1 = SavedValueInCond<A1>::restore(CGF, a1); + A0 a0 = SavedValueInCond<A0>::restore(CGF, a0_saved); + A1 a1 = SavedValueInCond<A1>::restore(CGF, a1_saved); T::Emit(CGF, IsForEHCleanup, a0, a1); } public: ConditionalCleanup2(llvm::Value *cond, A0_saved a0, A1_saved a1) - : ConditionalCleanup(cond), a0(a0), a1(a1) {} + : ConditionalCleanup(cond), a0_saved(a0), a1_saved(a1) {} }; private: |