<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 16, 2015 at 3:27 PM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: dexonsmith<br>
Date: Thu Apr 16 17:27:54 2015<br>
New Revision: 235140<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=235140&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=235140&view=rev</a><br>
Log:<br>
DebugInfo: Fix UserValue::match() in LiveDebugVariables after r235050<br>
<br>
r235050 dropped the inlined-at field from `MDLocalVariable`, deferring<br>
to the `!dbg` attachments.  Fix `UserValue` to take the `!dbg` into<br>
account when differentiating between variables.<br>
<br>
Added:<br>
    llvm/trunk/test/DebugInfo/X86/inlined-formal-parameter.ll<br>
Modified:<br>
    llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp<br>
<br>
Modified: llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp?rev=235140&r1=235139&r2=235140&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp?rev=235140&r1=235139&r2=235140&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp Thu Apr 16 17:27:54 2015<br>
@@ -158,10 +158,10 @@ public:<br>
   UserValue *getNext() const { return next; }<br>
<br>
   /// match - Does this UserValue match the parameters?<br>
-  bool match(const MDNode *Var, const MDNode *Expr, unsigned Offset,<br>
-             bool indirect) const {<br>
-    return Var == Variable && Expr == Expression && Offset == offset &&<br>
-           indirect == IsIndirect;<br>
+  bool match(const MDNode *Var, const MDNode *Expr, const MDLocation *IA,<br>
+             unsigned Offset, bool indirect) const {<br>
+    return Var == Variable && Expr == Expression && dl->getInlinedAt() == IA &&<br>
+           Offset == offset && indirect == IsIndirect;<br>
   }<br>
<br>
   /// merge - Merge equivalence classes.<br>
@@ -464,7 +464,7 @@ UserValue *LDVImpl::getUserValue(const M<br>
     UserValue *UV = Leader->getLeader();<br>
     Leader = UV;<br>
     for (; UV; UV = UV->getNext())<br>
-      if (UV->match(Var, Expr, Offset, IsIndirect))<br>
+      if (UV->match(Var, Expr, DL->getInlinedAt(), Offset, IsIndirect))<br>
         return UV;<br>
   }<br>
<br>
<br>
Added: llvm/trunk/test/DebugInfo/X86/inlined-formal-parameter.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/inlined-formal-parameter.ll?rev=235140&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/inlined-formal-parameter.ll?rev=235140&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/DebugInfo/X86/inlined-formal-parameter.ll (added)<br>
+++ llvm/trunk/test/DebugInfo/X86/inlined-formal-parameter.ll Thu Apr 16 17:27:54 2015<br>
@@ -0,0 +1,105 @@<br>
+; RUN: llc -filetype=obj -o %t.o %s<br>
+; RUN: llvm-dwarfdump -debug-dump=info %t.o | FileCheck %s<br>
+<br>
+; Testcase generated using 'clang -O2 -S -emit-llvm' from the following:<br></blockquote><div><br>Reckon it might be worth making sure both the function calls don't get optimized away? (maybe you can replace g and l with a call to some external function - then they can't get collapsed together or otherwise optimized away - but I'm not sure if that'll preserve the bug?) Just so this test case doesn't get confused with other behavior?<br> <br>Yep, this is a bit simpler & doesn't tickle the optimized-away case:<br><br><div>void sink();</div><div><br></div><div>static __attribute__((always_inline)) void f(int a) {</div><div>  sink();</div><div>}</div><div><br></div><div>void call() {</div><div>  f(0);</div><div>  f(0);</div><div>}<br></div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+;; int *g;<br>
+;;<br>
+;; static __attribute__((always_inline)) int f(int a) {<br>
+;;   int l;<br>
+;;   g = &l;<br>
+;;   return a;<br>
+;; }<br>
+;;<br>
+;; int main(void) {<br>
+;;   f(0);<br>
+;;   f(0);<br>
+;;   return 0;<br>
+;; }<br>
+<br>
+; Check that we the first call to f(0) has no inlined subroutine (since the<br>
+; function is optimized out), and the second call correctly describes the<br>
+; formal parameter 'a'.<br>
+<br>
+; CHECK:       DW_TAG_inlined_subroutine<br>
+; CHECK-NOT:   DW_TAG_inlined_subroutine<br>
+; CHECK:         DW_AT_low_pc<br>
+; CHECK-NEXT:    DW_AT_high_pc<br>
+; CHECK-NOT:   DW_TAG_inlined_subroutine<br>
+; CHECK:         DW_TAG_formal_parameter<br>
+; CHECK-NEXT:      DW_AT_const_value<br>
+; CHECK-NEXT:      DW_AT_abstract_origin {{.*}} "a"<br>
+; CHECK-NOT:   DW_TAG_inlined_subroutine<br>
+; CHECK:         DW_TAG_variable<br>
+; CHECK-NEXT:      DW_AT_location<br>
+; CHECK-NEXT:      DW_AT_abstract_origin {{.*}} "l"<br>
+<br>
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64-apple-darwin"<br>
+<br>
+@g = common global i32* null, align 8<br>
+<br>
+; Function Attrs: nounwind ssp uwtable<br>
+define i32 @main() #0 {<br>
+entry:<br>
+  %l.i2 = alloca i32, align 4<br>
+  tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !12, metadata !21), !dbg !22<br>
+  %0 = bitcast i32* %l.i2 to i8*, !dbg !24<br>
+  call void @llvm.lifetime.start(i64 4, i8* %0), !dbg !24<br>
+  tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !12, metadata !21), !dbg !24<br>
+  tail call void @llvm.dbg.value(metadata i32* %l.i2, i64 0, metadata !13, metadata !21), !dbg !26<br>
+  store i32* %l.i2, i32** @g, align 8, !dbg !27, !tbaa !28<br>
+  call void @llvm.lifetime.end(i64 4, i8* %0), !dbg !32<br>
+  ret i32 0, !dbg !33<br>
+}<br>
+<br>
+; Function Attrs: nounwind readnone<br>
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1<br>
+<br>
+; Function Attrs: nounwind<br>
+declare void @llvm.lifetime.start(i64, i8* nocapture) #2<br>
+<br>
+; Function Attrs: nounwind<br>
+declare void @llvm.lifetime.end(i64, i8* nocapture) #2<br>
+<br>
+attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="core2" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
+attributes #1 = { nounwind readnone }<br>
+attributes #2 = { nounwind }<br>
+<br>
+!<a href="http://llvm.dbg.cu" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
+!llvm.module.flags = !{!17, !18, !19}<br>
+!llvm.ident = !{!20}<br>
+<br>
+!0 = !MDCompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.7.0 (trunk 235110) (llvm/trunk 235108)", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !14, imports: !2)<br>
+!1 = !MDFile(filename: "t.c", directory: "/path/to/dir")<br>
+!2 = !{}<br>
+!3 = !{!4, !8}<br>
+!4 = !MDSubprogram(name: "main", scope: !1, file: !1, line: 9, type: !5, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: true, function: i32 ()* @main, variables: !2)<br>
+!5 = !MDSubroutineType(types: !6)<br>
+!6 = !{!7}<br>
+!7 = !MDBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)<br>
+!8 = !MDSubprogram(name: "f", scope: !1, file: !1, line: 3, type: !9, isLocal: true, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, variables: !11)<br>
+!9 = !MDSubroutineType(types: !10)<br>
+!10 = !{!7, !7}<br>
+!11 = !{!12, !13}<br>
+!12 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "a", arg: 1, scope: !8, file: !1, line: 3, type: !7)<br>
+!13 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "l", scope: !8, file: !1, line: 4, type: !7)<br>
+!14 = !{!15}<br>
+!15 = !MDGlobalVariable(name: "g", scope: !0, file: !1, line: 1, type: !16, isLocal: false, isDefinition: true, variable: i32** @g)<br>
+!16 = !MDDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, align: 64)<br>
+!17 = !{i32 2, !"Dwarf Version", i32 2}<br>
+!18 = !{i32 2, !"Debug Info Version", i32 3}<br>
+!19 = !{i32 1, !"PIC Level", i32 2}<br>
+!20 = !{!"clang version 3.7.0 (trunk 235110) (llvm/trunk 235108)"}<br>
+!21 = !MDExpression()<br>
+!22 = !MDLocation(line: 3, column: 49, scope: !8, inlinedAt: !23)<br>
+!23 = distinct !MDLocation(line: 10, column: 3, scope: !4)<br>
+!24 = !MDLocation(line: 3, column: 49, scope: !8, inlinedAt: !25)<br>
+!25 = distinct !MDLocation(line: 11, column: 3, scope: !4)<br>
+!26 = !MDLocation(line: 4, column: 7, scope: !8, inlinedAt: !25)<br>
+!27 = !MDLocation(line: 5, column: 5, scope: !8, inlinedAt: !25)<br>
+!28 = !{!29, !29, i64 0}<br>
+!29 = !{!"any pointer", !30, i64 0}<br>
+!30 = !{!"omnipotent char", !31, i64 0}<br>
+!31 = !{!"Simple C/C++ TBAA"}<br>
+!32 = !MDLocation(line: 11, column: 3, scope: !4)<br>
+!33 = !MDLocation(line: 12, column: 3, scope: !4)<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>