diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-05-15 17:55:51 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-05-15 17:55:51 +0000 |
commit | bfcc823a5c53dabab8cfc842bfea70e2b69cdee0 (patch) | |
tree | b3daea2b733e9d363aca8ea272dacf787d9af732 /lib/CodeGen/CGDeclCXX.cpp | |
parent | 72bf425fab902f5fd6114b630b8dc3dc0e1de1a8 (diff) |
When initializing thread-safe statics, put the call to
__cxa_guard_abort along the exceptional edge into (in effect) a nested
"try" that rethrows after aborting. Fixes PR7144 and the remaining
Boost.ProgramOptions failures.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103880 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGDeclCXX.cpp')
-rw-r--r-- | lib/CodeGen/CGDeclCXX.cpp | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/lib/CodeGen/CGDeclCXX.cpp b/lib/CodeGen/CGDeclCXX.cpp index 036be92885..cbee247238 100644 --- a/lib/CodeGen/CGDeclCXX.cpp +++ b/lib/CodeGen/CGDeclCXX.cpp @@ -321,7 +321,11 @@ CodeGenFunction::EmitStaticCXXBlockVarDeclInit(const VarDecl &D, EmitBlock(InitCheckBlock); - if (ThreadsafeStatics) { + // Variables used when coping with thread-safe statics and exceptions. + llvm::BasicBlock *SavedLandingPad = 0; + llvm::BasicBlock *Abort = 0; + + if (ThreadsafeStatics) { // Call __cxa_guard_acquire. V = Builder.CreateCall(getGuardAcquireFn(*this), GuardVariable); @@ -330,14 +334,13 @@ CodeGenFunction::EmitStaticCXXBlockVarDeclInit(const VarDecl &D, Builder.CreateCondBr(Builder.CreateIsNotNull(V, "tobool"), InitBlock, EndBlock); - EmitBlock(InitBlock); - if (Exceptions) { - EHCleanupBlock Cleanup(*this); - - // Call __cxa_guard_abort. - Builder.CreateCall(getGuardAbortFn(*this), GuardVariable); + SavedLandingPad = getInvokeDest(); + Abort = createBasicBlock("guard.abort"); + setInvokeDest(Abort); } + + EmitBlock(InitBlock); } if (D.getType()->isReferenceType()) { @@ -353,7 +356,7 @@ CodeGenFunction::EmitStaticCXXBlockVarDeclInit(const VarDecl &D, if (ThreadsafeStatics) { // Call __cxa_guard_release. - Builder.CreateCall(getGuardReleaseFn(*this), GuardVariable); + Builder.CreateCall(getGuardReleaseFn(*this), GuardVariable); } else { llvm::Value *One = llvm::ConstantInt::get(llvm::Type::getInt8Ty(VMContext), 1); @@ -364,5 +367,20 @@ CodeGenFunction::EmitStaticCXXBlockVarDeclInit(const VarDecl &D, if (!D.getType()->isReferenceType()) EmitDeclDestroy(*this, D, GV); + if (ThreadsafeStatics && Exceptions) { + // If an exception is thrown during initialization, call __cxa_guard_abort + // along the exceptional edge. + EmitBranch(EndBlock); + + EmitBlock(Abort); + + // Call __cxa_guard_abort along the exceptional edge. + Builder.CreateCall(getGuardAbortFn(*this), GuardVariable); + setInvokeDest(SavedLandingPad); + + // Rethrow the current exception. + EmitRethrow(); + } + EmitBlock(EndBlock); } |