diff options
| author | John McCall <rjmccall@apple.com> | 2010-07-28 01:07:35 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2010-07-28 01:07:35 +0000 |
| commit | ba80390307e0438f6f793424727dfa518b6cf892 (patch) | |
| tree | 4e9038d881649040b808859e0335d6f67361eabc | |
| parent | cc54bd3cef954915885bc0fd6a12233585a41bc8 (diff) | |
| download | bcm5719-llvm-ba80390307e0438f6f793424727dfa518b6cf892.tar.gz bcm5719-llvm-ba80390307e0438f6f793424727dfa518b6cf892.zip | |
When creating a jump destination, its scope should be the scope of the
enclosing normal cleanup, not the top of the EH stack. I'm *really*
surprised this hasn't been causing more problems.
Fixes rdar://problem/8231514.
llvm-svn: 109569
| -rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 3 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 4 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/eh.cpp | 35 |
3 files changed, 41 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d6e498f453c..396ab4e6d2b 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1055,6 +1055,9 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) { /// /// As a side-effect, this method clears the insertion point. void CodeGenFunction::EmitBranchThroughCleanup(JumpDest Dest) { + assert(Dest.getScopeDepth().encloses(EHStack.getInnermostNormalCleanup()) + && "stale jump destination"); + if (!HaveInsertPoint()) return; diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 1dfe8b68df7..78745709177 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -575,7 +575,9 @@ public: /// target of a potentially scope-crossing jump; get a stable handle /// to which we can perform this jump later. JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target) { - return JumpDest(Target, EHStack.stable_begin(), NextCleanupDestIndex++); + return JumpDest(Target, + EHStack.getInnermostNormalCleanup(), + NextCleanupDestIndex++); } /// The given basic block lies in the current EH scope, but may be a diff --git a/clang/test/CodeGenCXX/eh.cpp b/clang/test/CodeGenCXX/eh.cpp index 3a2a38632f4..0960ec381b8 100644 --- a/clang/test/CodeGenCXX/eh.cpp +++ b/clang/test/CodeGenCXX/eh.cpp @@ -379,3 +379,38 @@ namespace test14 { } } } + +// rdar://problem/8231514 +// JumpDests shouldn't get confused by scopes that aren't normal cleanups. +namespace test15 { + struct A { ~A(); }; + + bool opaque(int); + + // CHECK: define void @_ZN6test153fooEv() + void foo() { + A a; + + try { + // CHECK: [[X:%.*]] = alloca i32 + // CHECK: store i32 10, i32* [[X]] + // CHECK-NEXT: br label + // -> while.cond + int x = 10; + + while (true) { + // CHECK: load i32* [[X]] + // CHECK-NEXT: [[COND:%.*]] = invoke zeroext i1 @_ZN6test156opaqueEi + // CHECK: br i1 [[COND]] + if (opaque(x)) + // CHECK: br label + break; + + // CHECK: br label + } + // CHECK: br label + } catch (int x) { } + + // CHECK: call void @_ZN6test151AD1Ev + } +} |

