[cfe-commits] r109569 - in /cfe/trunk: lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenFunction.h test/CodeGenCXX/eh.cpp

John McCall rjmccall at apple.com
Tue Jul 27 18:07:35 PDT 2010


Author: rjmccall
Date: Tue Jul 27 20:07:35 2010
New Revision: 109569

URL: http://llvm.org/viewvc/llvm-project?rev=109569&view=rev
Log:
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.


Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/test/CodeGenCXX/eh.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=109569&r1=109568&r2=109569&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Tue Jul 27 20:07:35 2010
@@ -1055,6 +1055,9 @@
 ///
 /// 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;
 

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=109569&r1=109568&r2=109569&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Jul 27 20:07:35 2010
@@ -575,7 +575,9 @@
   /// 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

Modified: cfe/trunk/test/CodeGenCXX/eh.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/eh.cpp?rev=109569&r1=109568&r2=109569&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/eh.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/eh.cpp Tue Jul 27 20:07:35 2010
@@ -379,3 +379,38 @@
     }
   }
 }
+
+// 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
+  }
+}





More information about the cfe-commits mailing list