]> granicus.if.org Git - clang/commitdiff
Don't enter cleanups for unreachable variables. It's impossible to
authorJohn McCall <rjmccall@apple.com>
Fri, 13 Apr 2012 18:44:05 +0000 (18:44 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 13 Apr 2012 18:44:05 +0000 (18:44 +0000)
jump into these scopes, and the cleanup-entering code sometimes wants
to do some operations first (e.g. a GEP), which can leave us with
unparented IR.

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

lib/CodeGen/CGBlocks.cpp
lib/CodeGen/CGDecl.cpp
test/CodeGenCXX/block-byref-cxx-objc.cpp

index 27bb4ef5d1af6d5b6745e72bc6f57bd0174262ec..f8c7bcd4d7bcac1e2354350dd65b5fef92b46bf7 100644 (file)
@@ -491,6 +491,8 @@ static void computeBlockInfo(CodeGenModule &CGM, CodeGenFunction *CGF,
 /// a full-expression so that the block's cleanups are pushed at the
 /// right place in the stack.
 static void enterBlockScope(CodeGenFunction &CGF, BlockDecl *block) {
+  assert(CGF.HaveInsertPoint());
+
   // Allocate the block info and place it at the head of the list.
   CGBlockInfo &blockInfo =
     *new CGBlockInfo(block, CGF.CurFn->getName());
index 8c154f0708452b8f776712bf60033c1fd7181c81..644777963b21d5bd3e909003cf0018228f523d7a 100644 (file)
@@ -1171,6 +1171,10 @@ void CodeGenFunction::EmitAutoVarCleanups(const AutoVarEmission &emission) {
   // If this was emitted as a global constant, we're done.
   if (emission.wasEmittedAsGlobal()) return;
 
+  // If we don't have an insertion point, we're done.  Sema prevents
+  // us from jumping into any of these scopes anyway.
+  if (!HaveInsertPoint()) return;
+
   const VarDecl &D = *emission.Variable;
 
   // Check the type for a cleanup.
index 135e0c7551942bbb5c023ce560a22295aed5fc1a..30f1f074b9b36c59d52473e8a3154c7cc2f85491 100644 (file)
@@ -23,3 +23,13 @@ int main()
 // CHECK: call void @_Block_object_assign
 // CHECK: define internal void @__destroy_helper_block_
 // CHECK: call void @_Block_object_dispose
+
+// rdar://problem/11135650
+namespace test1 {
+  struct A { int x; A(); ~A(); };
+
+  void test() {
+    return;
+    __block A a;
+  }
+}