<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 2, 2015 at 11:24 AM, Adrian Prantl <span dir="ltr"><<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Feb 2, 2015, at 10:39 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 2, 2015 at 10:31 AM, Adrian Prantl <span dir="ltr"><<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</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: Mon Feb  2 12:31:58 2015<br>
New Revision: 227827<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=227827&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=227827&view=rev</a><br>
Log:<br>
Debug Info: Relax assertion in isUnsignedDIType() to allow floats to be<br>
described by integer constants. This is a bit ugly, but if the source<br>
language allows arbitrary type casting, the debug info must follow suit.<br>
<br>
For example:<br>
  void foo() {<br>
    float a;<br>
    *(int *)&a = 0;<br>
  }<br>
For the curious: SROA replaces the float alloca with an i32 alloca, which<br>
is then optimized away and described via dbg.value(i32 0, ...).<br></blockquote><div><br></div><div>Not sure this is the right answer - even if the IR looks like that, it may be that we need to convert the constant back to the appropriate type before emitting the debug info?<br></div></div></div></div></div></blockquote></span><div>Sounds reasonable, but if I understand the code in DwarfUnit correctly, there would not be any difference in the output:</div><div><br></div><div><div>    } else if (DVInsn->getOperand(0).isFPImm())</div><div>      addConstantFPValue(*VariableDie, DVInsn->getOperand(0));</div><div>-></div><div><div>/// addConstantFPValue - Add constant value entry in variable DIE.</div><div>void DwarfUnit::addConstantFPValue(DIE &Die, const ConstantFP *CFP) {</div><div>  // Pass this down to addConstantValue as an unsigned bag of bits.</div><div>  addConstantValue(Die, CFP->getValueAPF().bitcastToAPInt(), true);</div><div>}</div></div><div>-></div><div>void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, bool Unsigned) {</div><div>-></div><div><div>void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, DIType Ty) {</div><div>  addConstantValue(Die, Val, isUnsignedDIType(DD, Ty));</div><div>}</div></div></div></div></div></blockquote><div><br>Ah, fair enough - it's just bits at the end (udata/sdata, not some float_data or somesuch).<br><br>The lack of canonicalization is just a bit worrying - anywhere in the compiler that can lead to differences in behavior & pain.<br><br>- David<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-- adrian    </div></font></span></div></div></div><div><div class="h5"><div><br></div><div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br>- David</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Added:<br>
    llvm/trunk/test/DebugInfo/X86/float_const.ll<br>
Modified:<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=227827&r1=227826&r2=227827&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=227827&r1=227826&r2=227827&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Mon Feb  2 12:31:58 2015<br>
@@ -606,6 +606,7 @@ static bool isUnsignedDIType(DwarfDebug<br>
           Encoding == dwarf::DW_ATE_unsigned_char ||<br>
           Encoding == dwarf::DW_ATE_signed ||<br>
           Encoding == dwarf::DW_ATE_signed_char ||<br>
+          Encoding == dwarf::DW_ATE_float ||<br>
           Encoding == dwarf::DW_ATE_UTF || Encoding == dwarf::DW_ATE_boolean ||<br>
           (Ty.getTag() == dwarf::DW_TAG_unspecified_type &&<br>
            Ty.getName() == "decltype(nullptr)")) &&<br>
<br>
Added: llvm/trunk/test/DebugInfo/X86/float_const.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/float_const.ll?rev=227827&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/float_const.ll?rev=227827&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/DebugInfo/X86/float_const.ll (added)<br>
+++ llvm/trunk/test/DebugInfo/X86/float_const.ll Mon Feb  2 12:31:58 2015<br>
@@ -0,0 +1,55 @@<br>
+; RUN: llc < %s -filetype=obj | llvm-dwarfdump -debug-dump=info - | FileCheck %s<br>
+; from (at -Os):<br>
+; void foo() {<br>
+;   float a = 3.14;<br>
+;   *(int *)&a = 0;<br>
+; }<br>
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64-apple-macosx10.10.0"<br>
+<br>
+; Function Attrs: nounwind optsize readnone uwtable<br>
+define void @foo() #0 {<br>
+entry:<br>
+  tail call void @llvm.dbg.declare(metadata float* undef, metadata !13, metadata !19), !dbg !20<br>
+  tail call void @llvm.dbg.value(metadata i32 1078523331, i64 0, metadata !13, metadata !19), !dbg !20<br>
+  tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !13, metadata !19), !dbg !20<br>
+; CHECK:  DW_AT_const_value [DW_FORM_sdata]    (0)<br>
+; CHECK-NEXT: DW_AT_name {{.*}}"a"<br>
+  ret void, !dbg !21<br>
+}<br>
+<br>
+; Function Attrs: nounwind readnone<br>
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1<br>
+<br>
+; Function Attrs: nounwind readnone<br>
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1<br>
+<br>
+attributes #0 = { nounwind optsize readnone uwtable }<br>
+attributes #1 = { nounwind readnone }<br>
+<br>
+!<a href="http://llvm.dbg.cu/" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
+!llvm.module.flags = !{!15, !16, !17}<br>
+!llvm.ident = !{!18}<br>
+<br>
+!0 = !{!"0x11\0012\00clang version 3.7.0 (trunk 227686)\001\00\000\00\001", !1, !2, !3, !6, !2, !2} ; [ DW_TAG_compile_unit ] [foo.c] [DW_LANG_C99]<br>
+!1 = !{!"foo.c", !""}<br>
+!2 = !{}<br>
+!3 = !{!4}<br>
+!4 = !{!"0xf\00\000\0064\0064\000\000", null, null, !5} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from int]<br>
+!5 = !{!"0x24\00int\000\0032\0032\000\000\005", null, null} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]<br>
+!6 = !{!7}<br>
+!7 = !{!"0x2e\00foo\00foo\00\001\000\001\000\000\000\001\001", !8, !9, !10, null, void ()* @foo, null, null, !12} ; [ DW_TAG_subprogram ] [line 1] [def] [foo]<br>
+!8 = !{!"foo.c", !""}<br>
+!9 = !{!"0x29", !8}                               ; [ DW_TAG_file_type ]<br>
+!10 = !{!"0x15\00\000\000\000\000\000\000", null, null, null, !11, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]<br>
+!11 = !{null}<br>
+!12 = !{!13}<br>
+!13 = !{!"0x100\00a\002\000", !7, !9, !14}        ; [ DW_TAG_auto_variable ] [a] [line 2]<br>
+!14 = !{!"0x24\00float\000\0032\0032\000\000\004", null, null} ; [ DW_TAG_base_type ] [float] [line 0, size 32, align 32, offset 0, enc DW_ATE_float]<br>
+!15 = !{i32 2, !"Dwarf Version", i32 2}<br>
+!16 = !{i32 2, !"Debug Info Version", i32 2}<br>
+!17 = !{i32 1, !"PIC Level", i32 2}<br>
+!18 = !{!"clang version 3.7.0 (trunk 227686)"}<br>
+!19 = !{!"0x102"}                                 ; [ DW_TAG_expression ]<br>
+!20 = !MDLocation(line: 2, column: 9, scope: !7)<br>
+!21 = !MDLocation(line: 4, column: 1, scope: !7)<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">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>
</div></blockquote></div><br></div></div></div></blockquote></div><br></div></div>