Before inserting llvm.dbg.declare intrinsic at the end of a basic block, check...
authorDevang Patel <dpatel@apple.com>
Fri, 29 Jan 2010 18:30:57 +0000 (18:30 +0000)
committerDevang Patel <dpatel@apple.com>
Fri, 29 Jan 2010 18:30:57 +0000 (18:30 +0000)
This API is used by clang and the test case is test/CodeGen/debug-info-crash.c in clang module.

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

lib/Analysis/DebugInfo.cpp

index bff193d52edd704395883bba89761da93e2915c8..d692ad7fd83e7443d8bea80438b1b83ccc100615 100644 (file)
@@ -1055,8 +1055,13 @@ Instruction *DIFactory::InsertDeclare(Value *Storage, DIVariable D,
 
   Value *Args[] = { MDNode::get(Storage->getContext(), &Storage, 1),
                     D.getNode() };
-  return CallInst::Create(DeclareFn, Args, Args+2, "", InsertAtEnd);
-}
+
+  // If this block already has a terminator then insert this intrinsic
+  // before the terminator.
+  if (TerminatorInst *T = InsertAtEnd->getTerminator()) 
+    return CallInst::Create(DeclareFn, Args, Args+2, "", T);
+  else
+    return CallInst::Create(DeclareFn, Args, Args+2, "", InsertAtEnd);}
 
 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
 Instruction *DIFactory::InsertDbgValueIntrinsic(Value *V, uint64_t Offset,