<div dir="ltr">Following our off-line discussion with Paul I am reverting this change as it breaks debug info for code instrumented with asan+coverage. <div>r288300</div><div><br><div>We'll investigate further what and where needs to be fixed. </div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 30, 2016 at 2:49 PM, Paul Robinson via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: probinson<br>
Date: Wed Nov 30 16:49:55 2016<br>
New Revision: 288283<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=288283&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=288283&view=rev</a><br>
Log:<br>
Recommit r288212: Emit 'no line' information for interesting 'orphan' instructions.<br>
The LLDB tests are now ready for this patch.<br>
<br>
DWARF specifies that "line 0" really means "no appropriate source<br>
location" in the line table.  Use this for branch targets and some<br>
other cases that have no specified source location, to prevent<br>
inheriting unfortunate line numbers from physically preceding<br>
instructions (which might be from completely unrelated source).<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D24180" rel="noreferrer" target="_blank">http://reviews.llvm.org/D24180</a><br>
<br>
Added:<br>
    llvm/trunk/test/DebugInfo/X86/<wbr>dwarf-no-source-loc.ll<br>
Modified:<br>
    llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/DebugHandlerBase.<wbr>cpp<br>
    llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/DebugHandlerBase.h<br>
    llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/DwarfDebug.cpp<br>
    llvm/trunk/test/CodeGen/X86/<wbr>stack-protector.ll<br>
    llvm/trunk/test/DebugInfo/<wbr>AArch64/line-header.ll<br>
<br>
Modified: llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/DebugHandlerBase.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp?rev=288283&r1=288282&r2=288283&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>CodeGen/AsmPrinter/<wbr>DebugHandlerBase.cpp?rev=<wbr>288283&r1=288282&r2=288283&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/DebugHandlerBase.<wbr>cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/DebugHandlerBase.<wbr>cpp Wed Nov 30 16:49:55 2016<br>
@@ -201,8 +201,10 @@ void DebugHandlerBase::<wbr>endInstruction()<br>
   assert(CurMI != nullptr);<br>
   // Don't create a new label after DBG_VALUE instructions.<br>
   // They don't generate code.<br>
-  if (!CurMI->isDebugValue())<br>
+  if (!CurMI->isDebugValue()) {<br>
     PrevLabel = nullptr;<br>
+    PrevInstBB = CurMI->getParent();<br>
+  }<br>
<br>
   DenseMap<const MachineInstr *, MCSymbol *>::iterator I =<br>
       LabelsAfterInsn.find(CurMI);<br>
<br>
Modified: llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/DebugHandlerBase.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h?rev=288283&r1=288282&r2=288283&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>CodeGen/AsmPrinter/<wbr>DebugHandlerBase.h?rev=288283&<wbr>r1=288282&r2=288283&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/DebugHandlerBase.h (original)<br>
+++ llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/DebugHandlerBase.h Wed Nov 30 16:49:55 2016<br>
@@ -38,10 +38,12 @@ protected:<br>
   MachineModuleInfo *MMI;<br>
<br>
   /// Previous instruction's location information. This is used to<br>
-  /// determine label location to indicate scope boundries in dwarf<br>
-  /// debug info.<br>
+  /// determine label location to indicate scope boundaries in debug info.<br>
+  /// We track the previous instruction's source location (if not line 0),<br>
+  /// whether it was a label, and its parent BB.<br>
   DebugLoc PrevInstLoc;<br>
   MCSymbol *PrevLabel = nullptr;<br>
+  const MachineBasicBlock *PrevInstBB = nullptr;<br>
<br>
   /// This location indicates end of function prologue and beginning of<br>
   /// function body.<br>
<br>
Modified: llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/DwarfDebug.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=288283&r1=288282&r2=288283&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>CodeGen/AsmPrinter/DwarfDebug.<wbr>cpp?rev=288283&r1=288282&r2=<wbr>288283&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/DwarfDebug.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/DwarfDebug.cpp Wed Nov 30 16:49:55 2016<br>
@@ -1010,31 +1010,70 @@ void DwarfDebug::beginInstruction(<wbr>const<br>
   if (MI->isDebugValue())<br>
     return;<br>
   const DebugLoc &DL = MI->getDebugLoc();<br>
-  if (DL == PrevInstLoc)<br>
+  // When we emit a line-0 record, we don't update PrevInstLoc; so look at<br>
+  // the last line number actually emitted, to see if it was line 0.<br>
+  unsigned LastAsmLine =<br>
+    Asm->OutStreamer->getContext()<wbr>.getCurrentDwarfLoc().getLine(<wbr>);<br>
+<br>
+  if (DL == PrevInstLoc) {<br>
+    // If we have an ongoing unspecified location, nothing to do here.<br>
+    if (!DL)<br>
+      return;<br>
+    // We have an explicit location, same as the previous location.<br>
+    // But we might be coming back to it after a line 0 record.<br>
+    if (LastAsmLine == 0 && DL.getLine() != 0) {<br>
+      // Reinstate the source location but not marked as a statement.<br>
+      const MDNode *Scope = DL.getScope();<br>
+      recordSourceLine(DL.getLine(), DL.getCol(), Scope, /*Flags=*/0);<br>
+    }<br>
     return;<br>
+  }<br>
<br>
   if (!DL) {<br>
     // We have an unspecified location, which might want to be line 0.<br>
-    if (UnknownLocations) {<br>
-      PrevInstLoc = DL;<br>
-      recordSourceLine(0, 0, nullptr, 0);<br>
+    // If we have already emitted a line-0 record, don't repeat it.<br>
+    if (LastAsmLine == 0)<br>
+      return;<br>
+    // See if we have a reason to emit a line-0 record now.<br>
+    // Reasons to emit a line-0 record include:<br>
+    // - User asked for it (UnknownLocations).<br>
+    // - Instruction has a label, so it's referenced from somewhere else,<br>
+    //   possibly debug information; we want it to have a source location.<br>
+    // - Instruction is at the top of a block; we don't want to inherit the<br>
+    //   location from the physically previous (maybe unrelated) block.<br>
+    if (UnknownLocations || PrevLabel ||<br>
+        (PrevInstBB && PrevInstBB != MI->getParent())) {<br>
+      // Preserve the file number, if we can, to save space in the line table.<br>
+      // Do not update PrevInstLoc, it remembers the last non-0 line.<br>
+      // FIXME: Also preserve the column number, to save more space?<br>
+      const MDNode *Scope = PrevInstLoc ? PrevInstLoc.getScope() : nullptr;<br>
+      recordSourceLine(0, 0, Scope, 0);<br>
     }<br>
     return;<br>
   }<br>
<br>
-  // We have a new, explicit location.<br>
+  // We have an explicit location, different from the previous location.<br>
+  // Don't repeat a line-0 record, but otherwise emit the new location.<br>
+  // (The new location might be an explicit line 0, which we do emit.)<br>
+  if (DL.getLine() == 0 && LastAsmLine == 0)<br>
+    return;<br>
   unsigned Flags = 0;<br>
-  PrevInstLoc = DL;<br>
   if (DL == PrologEndLoc) {<br>
     Flags |= DWARF2_FLAG_PROLOGUE_END | DWARF2_FLAG_IS_STMT;<br>
     PrologEndLoc = DebugLoc();<br>
   }<br>
-  if (DL.getLine() !=<br>
-      Asm->OutStreamer->getContext()<wbr>.getCurrentDwarfLoc().getLine(<wbr>))<br>
+  // If the line changed, we call that a new statement; unless we went to<br>
+  // line 0 and came back, in which case it is not a new statement.<br>
+  unsigned OldLine = PrevInstLoc ? PrevInstLoc.getLine() : LastAsmLine;<br>
+  if (DL.getLine() && DL.getLine() != OldLine)<br>
     Flags |= DWARF2_FLAG_IS_STMT;<br>
<br>
   const MDNode *Scope = DL.getScope();<br>
   recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags);<br>
+<br>
+  // If we're not at line 0, remember this location.<br>
+  if (DL.getLine())<br>
+    PrevInstLoc = DL;<br>
 }<br>
<br>
 static DebugLoc findPrologueEndLoc(const MachineFunction *MF) {<br>
<br>
Modified: llvm/trunk/test/CodeGen/X86/<wbr>stack-protector.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/stack-protector.ll?rev=288283&r1=288282&r2=288283&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>CodeGen/X86/stack-protector.<wbr>ll?rev=288283&r1=288282&r2=<wbr>288283&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/test/CodeGen/X86/<wbr>stack-protector.ll (original)<br>
+++ llvm/trunk/test/CodeGen/X86/<wbr>stack-protector.ll Wed Nov 30 16:49:55 2016<br>
@@ -3888,23 +3888,27 @@ entry:<br>
 define void @test32() #1 !dbg !7 {<br>
 entry:<br>
 ; LINUX-I386-LABEL: test32:<br>
-; LINUX-I386:       .loc 1 0 0 prologue_end<br>
+; LINUX-I386:       .loc 1 4 2 prologue_end<br>
+; LINUX-I386:       .loc 1 0 0<br>
 ; LINUX-I386-NEXT:  calll __stack_chk_fail<br>
<br>
 ; LINUX-X64-LABEL: test32:<br>
-; LINUX-X64:       .loc 1 0 0 prologue_end<br>
+; LINUX-X64:       .loc 1 4 2 prologue_end<br>
+; LINUX-X64:       .loc 1 0 0<br>
 ; LINUX-X64-NEXT:  callq __stack_chk_fail<br>
<br>
 ; LINUX-KERNEL-X64-LABEL: test32:<br>
-; LINUX-KERNEL-X64:       .loc 1 0 0 prologue_end<br>
+; LINUX-KERNEL-X64:       .loc 1 4 2 prologue_end<br>
+; LINUX-KERNEL-X64:       .loc 1 0 0<br>
 ; LINUX-KERNEL-X64-NEXT:  callq __stack_chk_fail<br>
<br>
 ; OPENBSD-AMD64-LABEL: test32:<br>
-; OPENBSD-AMD64:       .loc 1 0 0 prologue_end<br>
+; OPENBSD-AMD64:       .loc 1 4 2 prologue_end<br>
+; OPENBSD-AMD64:       .loc 1 0 0<br>
 ; OPENBSD-AMD64-NEXT:  movl<br>
 ; OPENBSD-AMD64-NEXT:  callq __stack_smash_handler<br>
   %0 = alloca [5 x i8], align 1<br>
-  ret void<br>
+  ret void, !dbg !9<br>
 }<br>
<br>
 declare double @testi_aux()<br>
@@ -3940,3 +3944,4 @@ attributes #5 = { ssp "stack-protector-b<br>
 !6 = distinct !DISubprogram(name: "__stack_chk_fail", scope: !1, type: !8, unit: !0)<br>
 !7 = distinct !DISubprogram(name: "test32", scope: !1, type: !8, unit: !0)<br>
 !8 = !DISubroutineType(types: !2)<br>
+!9 = !DILocation(line: 4, column: 2, scope: !7)<br>
<br>
Modified: llvm/trunk/test/DebugInfo/<wbr>AArch64/line-header.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/AArch64/line-header.ll?rev=288283&r1=288282&r2=288283&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>DebugInfo/AArch64/line-header.<wbr>ll?rev=288283&r1=288282&r2=<wbr>288283&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/test/DebugInfo/<wbr>AArch64/line-header.ll (original)<br>
+++ llvm/trunk/test/DebugInfo/<wbr>AArch64/line-header.ll Wed Nov 30 16:49:55 2016<br>
@@ -3,4 +3,4 @@<br>
<br>
 ; check line table length is correctly calculated for both big and little endian<br>
 CHECK-LABEL: .debug_line contents:<br>
-CHECK: total_length: 0x0000003c<br>
+CHECK: total_length: 0x0000003e<br>
<br>
Added: llvm/trunk/test/DebugInfo/X86/<wbr>dwarf-no-source-loc.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dwarf-no-source-loc.ll?rev=288283&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>DebugInfo/X86/dwarf-no-source-<wbr>loc.ll?rev=288283&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/test/DebugInfo/X86/<wbr>dwarf-no-source-loc.ll (added)<br>
+++ llvm/trunk/test/DebugInfo/X86/<wbr>dwarf-no-source-loc.ll Wed Nov 30 16:49:55 2016<br>
@@ -0,0 +1,74 @@<br>
+; Verify "no source location" directives appear in appropriate places.<br>
+; RUN: llc %s -o - | FileCheck %s<br>
+<br>
+; Generated from this .cpp targeting linux using -g<br>
+; and then removed function attributes as clutter.<br>
+;<br>
+; void bar(int *);<br>
+; void baz(int *);<br>
+; # 5 "no-source-loc.cpp"<br>
+; void foo(int x) {<br>
+;   int z;<br>
+;   if (x)<br>
+; # 20 "include.h"<br>
+;     bar(&z);<br>
+; # 10 "no-source-loc.cpp"<br>
+;   baz(&z);<br>
+; }<br>
+<br>
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:<wbr>32:64-S128"<br>
+target triple = "x86_64-unknown-linux-gnu"<br>
+<br>
+; Function Attrs: uwtable<br>
+define void @_Z3fooi(i32 %x) !dbg !6 {<br>
+entry:<br>
+  %x.addr = alloca i32, align 4<br>
+  %z = alloca i32, align 4<br>
+  store i32 %x, i32* %x.addr, align 4<br>
+  %0 = load i32, i32* %x.addr, align 4, !dbg !8<br>
+  %tobool = icmp ne i32 %0, 0, !dbg !8<br>
+  br i1 %tobool, label %if.then, label %if.end, !dbg !8<br>
+<br>
+if.then:                                          ; preds = %entry<br>
+  call void @_Z3barPi(i32* %z), !dbg !9<br>
+  br label %if.end, !dbg !9<br>
+<br>
+if.end:                                           ; preds = %if.then, %entry<br>
+  call void @_Z3bazPi(i32* %z), !dbg !12<br>
+  ret void, !dbg !14<br>
+}<br>
+<br>
+; CHECK:      .loc 1 7 7<br>
+; CHECK-NOT:  .loc<br>
+; CHECK:      .loc 1 0 0 is_stmt 0<br>
+; CHECK-NOT:  .loc<br>
+; CHECK:      .loc 2 20 5 is_stmt 1<br>
+; CHECK:      .LBB0_2:<br>
+; CHECK-NEXT: .loc 2 0 0 is_stmt 0<br>
+; CHECK-NOT:  .loc<br>
+; CHECK:      .loc 1 10 3 is_stmt 1<br>
+<br>
+<br>
+declare void @_Z3barPi(i32*)<br>
+<br>
+declare void @_Z3bazPi(i32*)<br>
+<br>
+!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
+!llvm.module.flags = !{!3, !4}<br>
+!llvm.ident = !{!5}<br>
+<br>
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 4.0.0 (trunk 278782)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)<br>
+!1 = !DIFile(filename: "no-source-loc.cpp", directory: "/tests")<br>
+!2 = !{}<br>
+!3 = !{i32 2, !"Dwarf Version", i32 4}<br>
+!4 = !{i32 2, !"Debug Info Version", i32 3}<br>
+!5 = !{!"clang version 4.0.0 (trunk 278782)"}<br>
+!6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 5, type: !7, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)<br>
+!7 = !DISubroutineType(types: !2)<br>
+!8 = !DILocation(line: 7, column: 7, scope: !6)<br>
+!9 = !DILocation(line: 20, column: 5, scope: !10)<br>
+!10 = !DILexicalBlockFile(scope: !6, file: !11, discriminator: 0)<br>
+!11 = !DIFile(filename: "include.h", directory: "/tests")<br>
+!12 = !DILocation(line: 10, column: 3, scope: !13)<br>
+!13 = !DILexicalBlockFile(scope: !6, file: !1, discriminator: 0)<br>
+!14 = !DILocation(line: 11, column: 1, scope: !13)<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>