Avoid generation of dead code in a few more situations.
 - Emit variable declarations as "simple", we want to avoid forcing the creation
   of a dummy basic block, but still need to make the variable available for
   later use.

 - With that, we can now skip IRgen for other unreachable statements (which
   don't define a label).

 - Anders, I added two fixmes on calls to EmitVLASize, can you check them?


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76361 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index eab5814..6da8649 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -112,7 +112,6 @@
 }
 
 void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) { 
-
   llvm::Value *&DMEntry = LocalDeclMap[&D];
   assert(DMEntry == 0 && "Decl already exists in localdeclmap!");
   
@@ -124,6 +123,8 @@
   DMEntry = GV;
 
   // Make sure to evaluate VLA bounds now so that we have them for later.
+  //
+  // FIXME: Can this happen?
   if (D.getType()->isVariablyModifiedType())
     EmitVLASize(D.getType());
 
@@ -274,9 +275,12 @@
                                          ::InternalLinkage);
     }
     
+    // FIXME: Can this happen?
     if (Ty->isVariablyModifiedType())
       EmitVLASize(Ty);
   } else {
+    EnsureInsertPoint();
+
     if (!DidCallStackSave) {
       // Save the stack.
       const llvm::Type *LTy =
@@ -321,6 +325,11 @@
 
   // Emit debug info for local var declaration.
   if (CGDebugInfo *DI = getDebugInfo()) {
+    // FIXME: Remove this once debug info isn't modeled as instructions.
+    EnsureInsertPoint();
+
+    EmitStopPoint(S);
+    
     DI->setLocation(D.getLocation());
     if (Target.useGlobalsForAutomaticVariables()) {
       DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(DeclPtr), &D);
@@ -338,7 +347,18 @@
   }
 
   // If this local has an initializer, emit it now.
-  if (const Expr *Init = D.getInit()) {
+  const Expr *Init = D.getInit();
+
+  // If we are at an unreachable point, we don't need to emit the initializer
+  // unless it contains a label.
+  if (!HaveInsertPoint()) {
+    if (!ContainsLabel(Init))
+      Init = 0;
+    else
+      EnsureInsertPoint();
+  }
+
+  if (Init) {
     llvm::Value *Loc = DeclPtr;
     if (isByRef) {
       bool needsCopyDispose = BlockRequiresCopying(Ty);
@@ -357,10 +377,12 @@
       EmitAggExpr(Init, Loc, D.getType().isVolatileQualified());
     }
   }
+  
   if (isByRef) {
     const llvm::PointerType *PtrToInt8Ty
       = VMContext.getPointerTypeUnqual(llvm::Type::Int8Ty);
 
+    EnsureInsertPoint();
     llvm::Value *isa_field = Builder.CreateStructGEP(DeclPtr, 0);
     llvm::Value *forwarding_field = Builder.CreateStructGEP(DeclPtr, 1);
     llvm::Value *flags_field = Builder.CreateStructGEP(DeclPtr, 2);