Do not record line number to implicitly mark start of function if function has arguments. Extra line number entries trip gdb in some cases.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83563 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 5b3f3ce..1ea148e 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1782,17 +1782,23 @@
 }
 
 /// CollectVariableInfo - Populate DbgScope entries with variables' info.
-void DwarfDebug::CollectVariableInfo() {
-  if (!MMI) return;
+bool DwarfDebug::CollectVariableInfo() {
+  if (!MMI) return false;
+  bool ArgsCollected = false;
   MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo();
   for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(),
          VE = VMap.end(); VI != VE; ++VI) {
     MDNode *Var = VI->first;
+    DIVariable DV (Var);
+    if (DV.isNull()) continue;
+    if (DV.getTag() == dwarf::DW_TAG_arg_variable)
+      ArgsCollected = true;
     DILocation VLoc(VI->second.first);
     unsigned VSlot = VI->second.second;
     DbgScope *Scope = getDbgScope(VLoc.getScope().getNode(), NULL);
-    Scope->AddVariable(new DbgVariable(DIVariable(Var), VSlot, false));
+    Scope->AddVariable(new DbgVariable(DV, VSlot, false));
   }
+  return ArgsCollected;
 }
 
 /// SetDbgScopeBeginLabels - Update DbgScope begin labels for the scopes that
@@ -1903,7 +1909,7 @@
 #ifdef ATTACH_DEBUG_INFO_TO_AN_INSN
   if (!ExtractScopeInformation(MF))
     return;
-  CollectVariableInfo();
+  bool ArgsCollected = CollectVariableInfo();
 #endif
 
   // Begin accumulating function debug information.
@@ -1914,14 +1920,19 @@
 
   // Emit label for the implicitly defined dbg.stoppoint at the start of the
   // function.
-  DebugLoc FDL = MF->getDefaultDebugLoc();
-  if (!FDL.isUnknown()) {
-    DebugLocTuple DLT = MF->getDebugLocTuple(FDL);
-    unsigned LabelID = RecordSourceLine(DLT.Line, DLT.Col, DLT.CompileUnit);
-    Asm->printLabel(LabelID);
-    O << '\n';
+#ifdef ATTACH_DEBUG_INFO_TO_AN_INSN
+  if (!ArgsCollected) {
+#else
+  if (1) {
+#endif
+    DebugLoc FDL = MF->getDefaultDebugLoc();
+    if (!FDL.isUnknown()) {
+      DebugLocTuple DLT = MF->getDebugLocTuple(FDL);
+      unsigned LabelID = RecordSourceLine(DLT.Line, DLT.Col, DLT.CompileUnit);
+      Asm->printLabel(LabelID);
+      O << '\n';
+    }
   }
-
   if (TimePassesIsEnabled)
     DebugTimer->stopTimer();
 }