Set debug locations for branch instructions created during inlining, even
[oota-llvm.git] / lib / Transforms / Utils / InlineFunction.cpp
index e9f0e28ad6506b900bb991909b5ceea9721d7b13..ae9300a40ad4396cdd208b574b33574462d4c9ad 100644 (file)
@@ -853,11 +853,19 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
 
 
     // Add a branch to the merge points and remove return instructions.
+    ReturnInst *RI;
     for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
-      ReturnInst *RI = Returns[i];
-      BranchInst::Create(AfterCallBB, RI);
+      RI = Returns[i];
+      BranchInst* BI = BranchInst::Create(AfterCallBB, RI);
+      BI->setDebugLoc(RI->getDebugLoc());
       RI->eraseFromParent();
     }
+    // We need to set the debug location to *somewhere* inside the
+    // inlined function. The line number may be nonsentical, but the
+    // instruction will at least be associated with the right
+    // function.
+    if (CreatedBranchToNormalDest)
+      CreatedBranchToNormalDest->setDebugLoc(RI->getDebugLoc());
   } else if (!Returns.empty()) {
     // Otherwise, if there is exactly one return value, just replace anything
     // using the return value of the call with the computed value.