<div dir="ltr">Thanks for the fix - sorry for the noise.<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Oct 4, 2013 at 8:03 AM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This was failing for me. Both Linux and Darwin. I changed the test in<br>
r191958. Please check that that was the correct change.<br>
<div class="HOEnZb"><div class="h5"><br>
On 3 October 2013 21:39, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
> Author: dblaikie<br>
> Date: Thu Oct  3 20:39:59 2013<br>
> New Revision: 191939<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=191939&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=191939&view=rev</a><br>
> Log:<br>
> DebugInfo: Fix ordering of members after r191928<br>
><br>
> In the case (shown in the attached test) where a member function<br>
> definition was emitted into debug info the following could occur:<br>
><br>
> 1) build the debug info for the member function definition<br>
> 2) in (1), build the debug info for the member function declaration<br>
> 3) construct and add the member function declaration DIE<br>
> 4) add it to its context<br>
> 5) build its context (the type it is a member of)<br>
> 6) construct the members and add them to the type<br>
> 7) except don't add member functions because "getOrCreateSubprogram"<br>
> adds the function to its parent anyway<br>
> 8) except we're only partway through building this subprogram<br>
> declaration so it hasn't been added yet - but we returned the partially<br>
> constructed DIE (since it's already in the MDNode->DIE mapping to avoid<br>
> infinitely recursing trying to create the member function DIE)<br>
> 9) once the type is constructed, add the member function to it<br>
> 10) now the members are out of order (the member function being defined<br>
> is listed as the last member, even though it was declared as the first)<br>
><br>
> To avoid this, construct the context of the subprogram DIE before we<br>
> query to see if it exists. That way we never end up creating it before<br>
> creating its context and ending up in this situation.<br>
><br>
> Alternatively, the type construction that visits/builds all the members<br>
> could call something like getOrCreateSubprogram, but that doesn't ever<br>
> do the "add to context" step. Then the type building code would always<br>
> be responsible for adding members (and the subprogram "addToContextDIE"<br>
> would no-op because the context building would have added the subprogram<br>
> declaration to the type/context DIE already).<br>
><br>
> (the test cases updated were overly-sensitive to offsets or abbreviation<br>
> numbers. We don't have a nice way to make these tests more robust as yet<br>
> - multiline FileCheck matches would be required)<br>
><br>
> Added:<br>
>     llvm/trunk/test/DebugInfo/member-order.ll<br>
> Modified:<br>
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp<br>
>     llvm/trunk/test/DebugInfo/X86/DW_AT_specification.ll<br>
>     llvm/trunk/test/DebugInfo/X86/concrete_out_of_line.ll<br>
>     llvm/trunk/test/DebugInfo/X86/pr11300.ll<br>
><br>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=191939&r1=191938&r2=191939&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=191939&r1=191938&r2=191939&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)<br>
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Thu Oct  3 20:39:59 2013<br>
> @@ -1311,6 +1311,13 @@ DIE *CompileUnit::getOrCreateNameSpace(D<br>
><br>
>  /// getOrCreateSubprogramDIE - Create new DIE using SP.<br>
>  DIE *CompileUnit::getOrCreateSubprogramDIE(DISubprogram SP) {<br>
> +  // Construct the context before querying for the existence of the DIE in case<br>
> +  // such construction creates the DIE (as is the case for member function<br>
> +  // declarations).<br>
> +  DIE *ContextDIE = getOrCreateContextDIE(SP.getContext());<br>
> +  if (!ContextDIE)<br>
> +    ContextDIE = CUDie.get();<br>
> +<br>
>    DIE *SPDie = DD->getSPDIE(SP);<br>
>    if (SPDie)<br>
>      return SPDie;<br>
> @@ -1327,7 +1334,7 @@ DIE *CompileUnit::getOrCreateSubprogramD<br>
>    }<br>
><br>
>    // Add to context owner.<br>
> -  addToContextOwner(SPDie, SP.getContext());<br>
> +  ContextDIE->addChild(SPDie);<br>
><br>
>    // Add function template parameters.<br>
>    addTemplateParams(*SPDie, SP.getTemplateParams());<br>
><br>
> Modified: llvm/trunk/test/DebugInfo/X86/DW_AT_specification.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/DW_AT_specification.ll?rev=191939&r1=191938&r2=191939&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/DW_AT_specification.ll?rev=191939&r1=191938&r2=191939&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/test/DebugInfo/X86/DW_AT_specification.ll (original)<br>
> +++ llvm/trunk/test/DebugInfo/X86/DW_AT_specification.ll Thu Oct  3 20:39:59 2013<br>
> @@ -3,8 +3,8 @@<br>
><br>
>  ; test that the DW_AT_specification is a back edge in the file.<br>
><br>
> -; CHECK: 0x0000003a: DW_TAG_subprogram [5] *<br>
> -; CHECK: DW_AT_specification [DW_FORM_ref4]      (cu + 0x003a => {0x0000003a})<br>
> +; CHECK: 0x0000[[OFFSET:[0-9a-f]*]]: DW_TAG_subprogram [5] *<br>
> +; CHECK: DW_AT_specification [DW_FORM_ref4]      (cu + 0x[[OFFSET]] => {0x0000[[OFFSET]]})<br>
><br>
><br>
>  @_ZZN3foo3barEvE1x = constant i32 0, align 4<br>
><br>
> Modified: llvm/trunk/test/DebugInfo/X86/concrete_out_of_line.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/concrete_out_of_line.ll?rev=191939&r1=191938&r2=191939&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/concrete_out_of_line.ll?rev=191939&r1=191938&r2=191939&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/test/DebugInfo/X86/concrete_out_of_line.ll (original)<br>
> +++ llvm/trunk/test/DebugInfo/X86/concrete_out_of_line.ll Thu Oct  3 20:39:59 2013<br>
> @@ -7,14 +7,14 @@<br>
>  ; first check that we have a TAG_subprogram at a given offset and it has<br>
>  ; AT_inline.<br>
><br>
> -; CHECK: 0x0000011e:   DW_TAG_subprogram [18]<br>
> +; CHECK: 0x0000011e:   DW_TAG_subprogram [17]<br>
>  ; CHECK-NEXT:     DW_AT_specification<br>
>  ; CHECK-NEXT:     DW_AT_inline<br>
><br>
><br>
>  ; and then that a TAG_subprogram refers to it with AT_abstract_origin.<br>
><br>
> -; CHECK: 0x0000015f:   DW_TAG_subprogram [20]<br>
> +; CHECK: 0x0000015f:   DW_TAG_subprogram [19]<br>
>  ; CHECK-NEXT: DW_AT_abstract_origin [DW_FORM_ref4]    (cu + 0x011e => {0x0000011e})<br>
><br>
>  define i32 @_ZN17nsAutoRefCnt7ReleaseEv() {<br>
><br>
> Modified: llvm/trunk/test/DebugInfo/X86/pr11300.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/pr11300.ll?rev=191939&r1=191938&r2=191939&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/pr11300.ll?rev=191939&r1=191938&r2=191939&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/test/DebugInfo/X86/pr11300.ll (original)<br>
> +++ llvm/trunk/test/DebugInfo/X86/pr11300.ll Thu Oct  3 20:39:59 2013<br>
> @@ -3,7 +3,7 @@<br>
><br>
>  ; test that the DW_AT_specification is a back edge in the file.<br>
><br>
> -; CHECK: [[BACK:0x[0-9a-f]*]]:     DW_TAG_subprogram [5]<br>
> +; CHECK: [[BACK:0x[0-9a-f]*]]:     DW_TAG_subprogram [6]<br>
>  ; CHECK:                 DW_AT_specification [DW_FORM_ref4]      (cu + {{.*}} => {[[BACK]]})<br>
><br>
>  %struct.foo = type { i8 }<br>
><br>
> Added: llvm/trunk/test/DebugInfo/member-order.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/member-order.ll?rev=191939&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/member-order.ll?rev=191939&view=auto</a><br>

> ==============================================================================<br>
> --- llvm/trunk/test/DebugInfo/member-order.ll (added)<br>
> +++ llvm/trunk/test/DebugInfo/member-order.ll Thu Oct  3 20:39:59 2013<br>
> @@ -0,0 +1,65 @@<br>
> +; REQUIRES: object-emission<br>
> +<br>
> +; RUN: llc -filetype=obj -O0 < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s<br>
> +<br>
> +; generated by clang from:<br>
> +; struct foo {<br>
> +;   void f1();<br>
> +;   void f2();<br>
> +; };<br>
> +;<br>
> +; void foo::f1() {<br>
> +; }<br>
> +<br>
> +; CHECK: DW_TAG_structure_type<br>
> +; CHECK-NEXT: DW_AT_name {{.*}} "foo"<br>
> +; CHECK-NOT: NULL<br>
> +; CHECK: DW_TAG_subprogram<br>
> +; CHECK-NOT: NULL<br>
> +; CHECK: DW_AT_name {{.*}} "f1"<br>
> +; CHECK: DW_TAG_subprogram<br>
> +; CHECK-NOT: NULL<br>
> +; CHECK: DW_AT_name {{.*}} "f2"<br>
> +<br>
> +<br>
> +%struct.foo = type { i8 }<br>
> +<br>
> +; Function Attrs: nounwind uwtable<br>
> +define void @_ZN3foo2f1Ev(%struct.foo* %this) #0 align 2 {<br>
> +entry:<br>
> +  %this.addr = alloca %struct.foo*, align 8<br>
> +  store %struct.foo* %this, %struct.foo** %this.addr, align 8<br>
> +  call void @llvm.dbg.declare(metadata !{%struct.foo** %this.addr}, metadata !16), !dbg !18<br>
> +  %this1 = load %struct.foo** %this.addr<br>
> +  ret void, !dbg !19<br>
> +}<br>
> +<br>
> +; Function Attrs: nounwind readnone<br>
> +declare void @llvm.dbg.declare(metadata, metadata) #1<br>
> +<br>
> +attributes #0 = { nounwind 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" "unsafe-fp-math"="false" "use-soft-float"="false" }<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}<br>
> +<br>
> +!0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.4 ", i1 false, metadata !"", i32 0, metadata !2, metadata !3, metadata !13, metadata !2, metadata !2, metadata !""} ; [ DW_TAG_compile_unit ] [/tmp/dbginfo/member-order.cpp] [DW_LANG_C_plus_plus]<br>

> +!1 = metadata !{metadata !"member-order.cpp", metadata !"/tmp/dbginfo"}<br>
> +!2 = metadata !{i32 0}<br>
> +!3 = metadata !{metadata !4}<br>
> +!4 = metadata !{i32 786451, metadata !1, null, metadata !"foo", i32 1, i64 8, i64 8, i32 0, i32 0, null, metadata !5, i32 0, null, null, metadata !"_ZTS3foo"} ; [ DW_TAG_structure_type ] [foo] [line 1, size 8, align 8, offset 0] [def] [from ]<br>

> +!5 = metadata !{metadata !6, metadata !11}<br>
> +!6 = metadata !{i32 786478, metadata !1, metadata !4, metadata !"f1", metadata !"f1", metadata !"_ZN3foo2f1Ev", i32 2, metadata !7, i1 false, i1 false, i32 0, i32 0, null, i32 256, i1 false, null, null, i32 0, metadata !10, i32 2} ; [ DW_TAG_subprogram ] [line 2] [f1]<br>

> +!7 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !8, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]<br>

> +!8 = metadata !{null, metadata !9}<br>
> +!9 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 1088, metadata !"_ZTS3foo"} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [artificial] [from _ZTS3foo]<br>

> +!10 = metadata !{i32 786468}<br>
> +!11 = metadata !{i32 786478, metadata !1, metadata !4, metadata !"f2", metadata !"f2", metadata !"_ZN3foo2f2Ev", i32 3, metadata !7, i1 false, i1 false, i32 0, i32 0, null, i32 256, i1 false, null, null, i32 0, metadata !12, i32 3} ; [ DW_TAG_subprogram ] [line 3] [f2]<br>

> +!12 = metadata !{i32 786468}<br>
> +!13 = metadata !{metadata !14}<br>
> +!14 = metadata !{i32 786478, metadata !1, null, metadata !"f1", metadata !"f1", metadata !"_ZN3foo2f1Ev", i32 6, metadata !7, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, void (%struct.foo*)* @_ZN3foo2f1Ev, null, metadata !6, metadata !2, i32 6} ; [ DW_TAG_subprogram ] [line 6] [def] [f1]<br>

> +!15 = metadata !{i32 2, metadata !"Dwarf Version", i32 4}<br>
> +!16 = metadata !{i32 786689, metadata !14, metadata !"this", null, i32 16777216, metadata !17, i32 1088, i32 0} ; [ DW_TAG_arg_variable ] [this] [line 0]<br>
> +!17 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 0, metadata !"_ZTS3foo"} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from _ZTS3foo]<br>

> +!18 = metadata !{i32 0, i32 0, metadata !14, null}<br>
> +!19 = metadata !{i32 7, i32 0, metadata !14, null}<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>
</div></div></blockquote></div><br></div></div>