<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 24, 2016 at 3:23 PM, Adrian Prantl 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: adrian<br>
Date: Sun Apr 24 17:23:13 2016<br>
New Revision: 267370<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=267370&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=267370&view=rev</a><br>
Log:<br>
Verifier: Verify that each inlinable callsite of a debug-info-bearing function<br>
in a debug-info-bearing function has a debug location attached to it. Failure to<br>
do so causes an "!dbg attachment points at wrong subprogram for function"<br>
assertion failure when the inliner sets up inline scope info.<br></blockquote><div><br></div><div>Great to have this check - though, as an FYI: This doesn't catch all the cases of the downstream assertion. The downstream assertion can be triggered through indirect scenarios:<br><br>  void f1();<br>  inline __attribute__((alwaysinline)) void f2() { f1(); }<br>  inline __attribute__((alwaysinline)) void f3() { f2(); } // make this nodebug or equivalent<br>  void f4() { f3(); } // if f3 has no debugloc<br><br></div><div>Now you'll end up with the same problem if f2 is inlined into f3 (maybe even in the other order), producing instructions with debug locations - and then that's inlined into f4 at a callsite with no debugloc, leaving the instructions having debug locations that don't chain up to the f4 subprogram scope - but still chain up to the f2 subprogram scope.<br><br>- Dave<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
rdar://problem/25878916<br>
<br>
This reaplies r267320 without changes after fixing an issue in the OpenMP IR<br>
generator in clang.<br>
<br>
Added:<br>
    llvm/trunk/test/Verifier/callsite-dbgloc.ll<br>
Modified:<br>
    llvm/trunk/lib/IR/Verifier.cpp<br>
    llvm/trunk/test/DebugInfo/X86/arange-and-stub.ll<br>
    llvm/trunk/test/DebugInfo/X86/dbg-declare-arg.ll<br>
<br>
Modified: llvm/trunk/lib/IR/Verifier.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=267370&r1=267369&r2=267370&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=267370&r1=267369&r2=267370&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/Verifier.cpp (original)<br>
+++ llvm/trunk/lib/IR/Verifier.cpp Sun Apr 24 17:23:13 2016<br>
@@ -2579,6 +2579,15 @@ void Verifier::verifyCallSite(CallSite C<br>
     }<br>
   }<br>
<br>
+  // Verify that each inlinable callsite of a debug-info-bearing function in a<br>
+  // debug-info-bearing function has a debug location attached to it. Failure to<br>
+  // do so causes assertion failures when the inliner sets up inline scope info.<br>
+  if (I->getFunction()->getSubprogram() && CS.getCalledFunction() &&<br>
+      CS.getCalledFunction()->getSubprogram())<br>
+    Assert(I->getDebugLoc(), "inlinable function call in a function with debug "<br>
+                             "info must have a !dbg location",<br>
+           I);<br>
+<br>
   visitInstruction(*I);<br>
 }<br>
<br>
<br>
Modified: llvm/trunk/test/DebugInfo/X86/arange-and-stub.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/arange-and-stub.ll?rev=267370&r1=267369&r2=267370&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/arange-and-stub.ll?rev=267370&r1=267369&r2=267370&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/DebugInfo/X86/arange-and-stub.ll (original)<br>
+++ llvm/trunk/test/DebugInfo/X86/arange-and-stub.ll Sun Apr 24 17:23:13 2016<br>
@@ -18,7 +18,7 @@ define void @foo() !dbg !4 {<br>
<br>
 define void @bar() personality i8* bitcast (void ()* @foo to i8*) !dbg !9 {<br>
   invoke void @foo()<br>
-          to label %invoke.cont unwind label %lpad<br>
+          to label %invoke.cont unwind label %lpad, !dbg !19<br>
<br>
 invoke.cont:                                      ; preds = %0<br>
   ret void<br>
@@ -50,3 +50,4 @@ lpad:<br>
 !16 = !DISubrange(count: 1)<br>
 !17 = !{i32 2, !"Dwarf Version", i32 4}<br>
 !18 = !{i32 2, !"Debug Info Version", i32 3}<br>
+!19 = !DILocation(line: 0, scope: !9)<br>
<br>
Modified: llvm/trunk/test/DebugInfo/X86/dbg-declare-arg.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dbg-declare-arg.ll?rev=267370&r1=267369&r2=267370&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dbg-declare-arg.ll?rev=267370&r1=267369&r2=267370&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/DebugInfo/X86/dbg-declare-arg.ll (original)<br>
+++ llvm/trunk/test/DebugInfo/X86/dbg-declare-arg.ll Sun Apr 24 17:23:13 2016<br>
@@ -54,7 +54,7 @@ entry:<br>
   store %class.A* %this, %class.A** %this.addr, align 8<br>
   call void @llvm.dbg.declare(metadata %class.A** %this.addr, metadata !43, metadata !DIExpression()), !dbg !44<br>
   %this1 = load %class.A*, %class.A** %this.addr<br>
-  call void @_ZN1AD2Ev(%class.A* %this1)<br>
+  call void @_ZN1AD2Ev(%class.A* %this1), !dbg !53<br>
   ret void, !dbg !45<br>
 }<br>
<br>
@@ -124,3 +124,4 @@ entry:<br>
 !49 = distinct !DILexicalBlock(line: 2, column: 52, file: !51, scope: !25)<br>
 !51 = !DIFile(filename: "a.cc", directory: "/private/tmp")<br>
 !52 = !{i32 1, !"Debug Info Version", i32 3}<br>
+!53 = !DILocation(line: 0, scope: !22)<br>
<br>
Added: llvm/trunk/test/Verifier/callsite-dbgloc.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Verifier/callsite-dbgloc.ll?rev=267370&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Verifier/callsite-dbgloc.ll?rev=267370&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/Verifier/callsite-dbgloc.ll (added)<br>
+++ llvm/trunk/test/Verifier/callsite-dbgloc.ll Sun Apr 24 17:23:13 2016<br>
@@ -0,0 +1,62 @@<br>
+; RUN: not llvm-as %s -o %t 2>&1 | FileCheck %s<br>
+; Created and then edited from<br></blockquote><div><br></div><div>It'd be good to describe the required edits here? (so that if someone is trying to regenerate or otherwise understand this test they know what to look for)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+;   extern void i();<br>
+;   void h() { i(); }<br>
+;   void g() { h(); }<br>
+;   void f() { g(); }<br>
+;<br>
+; Compiling this with inlining runs into the<br>
+; "!dbg attachment points at wrong subprogram for function"<br>
+; assertion.<br>
+<br>
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64-apple-macosx"<br>
+<br>
+; Function Attrs: nounwind ssp uwtable<br>
+define void @h() #0 !dbg !7 {<br>
+entry:<br>
+  call void (...) @i(), !dbg !9<br>
+  ret void, !dbg !10<br>
+}<br>
+<br>
+declare void @i(...) #1<br>
+<br>
+; Function Attrs: nounwind ssp uwtable<br>
+define void @g() #0 !dbg !11 {<br>
+entry:<br>
+; Manually removed !dbg.<br>
+; CHECK: inlinable function call in a function with debug info must have a !dbg location<br>
+  call void @h()<br>
+  ret void, !dbg !13<br>
+}<br>
+<br>
+; Function Attrs: nounwind ssp uwtable<br>
+define void @f() #0 !dbg !14 {<br>
+entry:<br>
+  call void @g(), !dbg !15<br>
+  ret void, !dbg !16<br>
+}<br>
+<br>
+attributes #0 = { nounwind ssp uwtable }<br>
+<br>
+!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
+!llvm.module.flags = !{!3, !4, !5}<br>
+!llvm.ident = !{!6}<br>
+<br>
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 267186)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)<br>
+!1 = !DIFile(filename: "test.c", directory: "/Volumes/Data/llvm")<br>
+!2 = !{}<br>
+!3 = !{i32 2, !"Dwarf Version", i32 2}<br>
+!4 = !{i32 2, !"Debug Info Version", i32 3}<br>
+!5 = !{i32 1, !"PIC Level", i32 2}<br>
+!6 = !{!"clang version 3.9.0 (trunk 267186)"}<br>
+!7 = distinct !DISubprogram(name: "h", scope: !1, file: !1, line: 2, type: !8, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, unit: !0, variables: !2)<br>
+!8 = !DISubroutineType(types: !2)<br>
+!9 = !DILocation(line: 2, column: 12, scope: !7)<br>
+!10 = !DILocation(line: 2, column: 17, scope: !7)<br>
+!11 = distinct !DISubprogram(name: "g", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: false, unit: !0, variables: !2)<br>
+!12 = !DILocation(line: 3, column: 12, scope: !11)<br>
+!13 = !DILocation(line: 3, column: 17, scope: !11)<br>
+!14 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 4, type: !8, isLocal: false, isDefinition: true, scopeLine: 4, isOptimized: false, unit: !0, variables: !2)<br>
+!15 = !DILocation(line: 4, column: 12, scope: !14)<br>
+!16 = !DILocation(line: 4, column: 17, scope: !14)<br>
<br>
<br>
_______________________________________________<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/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>