]> granicus.if.org Git - clang/commitdiff
When creating a jump destination, its scope should be the scope of the
authorJohn McCall <rjmccall@apple.com>
Wed, 28 Jul 2010 01:07:35 +0000 (01:07 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 28 Jul 2010 01:07:35 +0000 (01:07 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109569 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenFunction.cpp
lib/CodeGen/CodeGenFunction.h
test/CodeGenCXX/eh.cpp

index d6e498f453c25c0547bccffc6409e1653c8ca7a1..396ab4e6d2bf60ee4ce0fd6c9d9d598e25fedec6 100644 (file)
@@ -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;
 
index 1dfe8b68df73cc1fc7494f0b47f2d081c76b877b..787457091770c089cc36e9f5a9053f841e7343b7 100644 (file)
@@ -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
index 3a2a38632f49fc1d8037c49667a6229527442cc1..0960ec381b894b49429a52bf6c82fb859a6b17eb 100644 (file)
@@ -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
+  }
+}