<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 24, 2016 at 10:55 AM, Reid Kleckner 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: rnk<br>
Date: Fri Jun 24 12:55:40 2016<br>
New Revision: 273696<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=273696&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=273696&view=rev</a><br>
Log:<br>
[codeview] Emit parameter variables in the right order<br>
<br>
Clang emits them in reverse order to conform to the ABI, which requires<br>
left-to-right destruction. As a result, the order doesn't fall out<br>
naturally, and we have to sort things out in the backend.<br>
<br>
Fixes PR28213<br>
<br>
Added:<br>
llvm/trunk/test/DebugInfo/COFF/parameter-order.ll<br>
Modified:<br>
llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp<br>
llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h<br>
llvm/trunk/test/DebugInfo/COFF/types-basic.ll<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=273696&r1=273695&r2=273696&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=273696&r1=273695&r2=273696&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Fri Jun 24 12:55:40 2016<br>
@@ -504,8 +504,7 @@ void CodeViewDebug::emitInlinedCallSite(<br>
<br>
OS.EmitLabel(InlineEnd);<br>
<br>
- for (const LocalVariable &Var : Site.InlinedLocals)<br>
- emitLocalVariable(Var);<br>
+ emitLocalVariableList(Site.InlinedLocals);<br>
<br>
// Recurse on child inlined call sites before closing the scope.<br>
for (const DILocation *ChildSite : Site.ChildSites) {<br>
@@ -608,8 +607,7 @@ void CodeViewDebug::emitDebugInfoForFunc<br>
emitNullTerminatedSymbolName(OS, FuncName);<br>
OS.EmitLabel(ProcRecordEnd);<br>
<br>
- for (const LocalVariable &Var : FI.Locals)<br>
- emitLocalVariable(Var);<br>
+ emitLocalVariableList(FI.Locals);<br>
<br>
// Emit inlined call site information. Only emit functions inlined directly<br>
// into the parent function. We'll emit the other sites recursively as part<br>
@@ -1680,6 +1678,25 @@ void CodeViewDebug::emitDeferredComplete<br>
}<br>
}<br>
<br>
+void CodeViewDebug::emitLocalVariableList(ArrayRef<LocalVariable> Locals) {<br>
+ // Get the sorted list of parameters and emit them first.<br>
+ SmallVector<const LocalVariable *, 6> Params;<br>
+ for (const LocalVariable &L : Locals)<br>
+ if (L.DIVar->isParameter())<br>
+ Params.push_back(&L);<br>
+ std::sort(Params.begin(), Params.end(),<br>
+ [](const LocalVariable *L, const LocalVariable *R) {<br>
+ return L->DIVar->getArg() < R->DIVar->getArg();<br>
+ });<br></blockquote><div><br></div><div>Rather than sorting, could you insert the args in the index specified by 'getArg'? (I think it's zero or one indexed for arguments - so you'd know exactly where to put them)<br><br>[but it may be that that leaves holes due to bugs/missing debug info - looks like the DWARF side (DwarfFile::addScopeVariable) we just insert in order, but not indexing - more an insertion sort kind of thing.]</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ for (const LocalVariable *L : Params)<br>
+ emitLocalVariable(*L);<br>
+<br>
+ // Next emit all non-parameters in the order that we found them.<br>
+ for (const LocalVariable &L : Locals)<br>
+ if (!L.DIVar->isParameter())<br>
+ emitLocalVariable(L);<br>
+}<br>
+<br>
void CodeViewDebug::emitLocalVariable(const LocalVariable &Var) {<br>
// LocalSym record, see SymbolRecord.h for more info.<br>
MCSymbol *LocalBegin = MMI->getContext().createTempSymbol(),<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h?rev=273696&r1=273695&r2=273696&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h?rev=273696&r1=273695&r2=273696&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h Fri Jun 24 12:55:40 2016<br>
@@ -220,6 +220,10 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDe<br>
/// particular, locals from inlined code live inside the inlining site.<br>
void recordLocalVariable(LocalVariable &&Var, const DILocation *Loc);<br>
<br>
+ /// Emits local variables in the appropriate order.<br>
+ void emitLocalVariableList(ArrayRef<LocalVariable> Locals);<br>
+<br>
+ /// Emits an S_LOCAL record and its associated defined ranges.<br>
void emitLocalVariable(const LocalVariable &Var);<br>
<br>
/// Translates the DIType to codeview if necessary and returns a type index<br>
<br>
Added: llvm/trunk/test/DebugInfo/COFF/parameter-order.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/parameter-order.ll?rev=273696&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/parameter-order.ll?rev=273696&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/DebugInfo/COFF/parameter-order.ll (added)<br>
+++ llvm/trunk/test/DebugInfo/COFF/parameter-order.ll Fri Jun 24 12:55:40 2016<br>
@@ -0,0 +1,122 @@<br>
+; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s --check-prefix=ASM<br>
+<br>
+; Make sure variables come out in the right order. windbg builds the prototype<br>
+; from the order of these records.<br>
+<br>
+; C++ source to regenerate:<br>
+; $ cat t.cpp<br>
+; int f(int a, int b, int c) {<br>
+; int d = 4;<br>
+; int e = 5;<br>
+; return a + b + c + d + e;<br>
+; }<br>
+; $ clang t.cpp -S -emit-llvm -g -gcodeview -o t.ll<br>
+<br>
+; ASM: .short 4414 # Record kind: S_LOCAL<br>
+; ASM: .long 116 # TypeIndex<br>
+; ASM: .short 1 # Flags<br>
+; ASM: .asciz "a"<br>
+; ASM: .cv_def_range<br>
+<br>
+; ASM: .short 4414 # Record kind: S_LOCAL<br>
+; ASM: .long 116 # TypeIndex<br>
+; ASM: .short 1 # Flags<br>
+; ASM: .asciz "b"<br>
+; ASM: .cv_def_range<br>
+<br>
+; ASM: .short 4414 # Record kind: S_LOCAL<br>
+; ASM: .long 116 # TypeIndex<br>
+; ASM: .short 1 # Flags<br>
+; ASM: .asciz "c"<br>
+; ASM: .cv_def_range<br>
+<br>
+; ASM: .short 4414 # Record kind: S_LOCAL<br>
+; ASM: .long 116 # TypeIndex<br>
+; ASM: .short 0 # Flags<br>
+; ASM: .asciz "d"<br>
+; ASM: .cv_def_range<br>
+<br>
+; ASM: .short 4414 # Record kind: S_LOCAL<br>
+; ASM: .long 116 # TypeIndex<br>
+; ASM: .short 0 # Flags<br>
+; ASM: .asciz "e"<br>
+; ASM: .cv_def_range<br>
+<br>
+<br>
+; ModuleID = 't.cpp'<br>
+source_filename = "t.cpp"<br>
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64-pc-windows-msvc19.0.23918"<br>
+<br>
+; Function Attrs: nounwind uwtable<br>
+define i32 @"\01?f@@YAHHHH@Z"(i32 %a, i32 %b, i32 %c) #0 !dbg !7 {<br>
+entry:<br>
+ %c.addr = alloca i32, align 4<br>
+ %b.addr = alloca i32, align 4<br>
+ %a.addr = alloca i32, align 4<br>
+ %d = alloca i32, align 4<br>
+ %e = alloca i32, align 4<br>
+ store i32 %c, i32* %c.addr, align 4<br>
+ call void @llvm.dbg.declare(metadata i32* %c.addr, metadata !11, metadata !12), !dbg !13<br>
+ store i32 %b, i32* %b.addr, align 4<br>
+ call void @llvm.dbg.declare(metadata i32* %b.addr, metadata !14, metadata !12), !dbg !15<br>
+ store i32 %a, i32* %a.addr, align 4<br>
+ call void @llvm.dbg.declare(metadata i32* %a.addr, metadata !16, metadata !12), !dbg !17<br>
+ call void @llvm.dbg.declare(metadata i32* %d, metadata !18, metadata !12), !dbg !19<br>
+ store i32 4, i32* %d, align 4, !dbg !19<br>
+ call void @llvm.dbg.declare(metadata i32* %e, metadata !20, metadata !12), !dbg !21<br>
+ store i32 5, i32* %e, align 4, !dbg !21<br>
+ %0 = load i32, i32* %a.addr, align 4, !dbg !22<br>
+ %1 = load i32, i32* %b.addr, align 4, !dbg !23<br>
+ %add = add nsw i32 %0, %1, !dbg !24<br>
+ %2 = load i32, i32* %c.addr, align 4, !dbg !25<br>
+ %add1 = add nsw i32 %add, %2, !dbg !26<br>
+ %3 = load i32, i32* %d, align 4, !dbg !27<br>
+ %add2 = add nsw i32 %add1, %3, !dbg !28<br>
+ %4 = load i32, i32* %e, align 4, !dbg !29<br>
+ %add3 = add nsw i32 %add2, %4, !dbg !30<br>
+ ret i32 %add3, !dbg !31<br>
+}<br>
+<br>
+; Function Attrs: nounwind readnone<br>
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1<br>
+<br>
+attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
+attributes #1 = { nounwind readnone }<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_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 273683) (llvm/trunk 273691)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)<br>
+!1 = !DIFile(filename: "t.cpp", directory: "D:\5Csrc\5Cllvm\5Cbuild")<br>
+!2 = !{}<br>
+!3 = !{i32 2, !"CodeView", i32 1}<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 273683) (llvm/trunk 273691)"}<br>
+!7 = distinct !DISubprogram(name: "f", linkageName: "\01?f@@YAHHHH@Z", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)<br>
+!8 = !DISubroutineType(types: !9)<br>
+!9 = !{!10, !10, !10, !10}<br>
+!10 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)<br>
+!11 = !DILocalVariable(name: "c", arg: 3, scope: !7, file: !1, line: 1, type: !10)<br>
+!12 = !DIExpression()<br>
+!13 = !DILocation(line: 1, column: 25, scope: !7)<br>
+!14 = !DILocalVariable(name: "b", arg: 2, scope: !7, file: !1, line: 1, type: !10)<br>
+!15 = !DILocation(line: 1, column: 18, scope: !7)<br>
+!16 = !DILocalVariable(name: "a", arg: 1, scope: !7, file: !1, line: 1, type: !10)<br>
+!17 = !DILocation(line: 1, column: 11, scope: !7)<br>
+!18 = !DILocalVariable(name: "d", scope: !7, file: !1, line: 2, type: !10)<br>
+!19 = !DILocation(line: 2, column: 7, scope: !7)<br>
+!20 = !DILocalVariable(name: "e", scope: !7, file: !1, line: 3, type: !10)<br>
+!21 = !DILocation(line: 3, column: 7, scope: !7)<br>
+!22 = !DILocation(line: 4, column: 10, scope: !7)<br>
+!23 = !DILocation(line: 4, column: 14, scope: !7)<br>
+!24 = !DILocation(line: 4, column: 12, scope: !7)<br>
+!25 = !DILocation(line: 4, column: 18, scope: !7)<br>
+!26 = !DILocation(line: 4, column: 16, scope: !7)<br>
+!27 = !DILocation(line: 4, column: 22, scope: !7)<br>
+!28 = !DILocation(line: 4, column: 20, scope: !7)<br>
+!29 = !DILocation(line: 4, column: 26, scope: !7)<br>
+!30 = !DILocation(line: 4, column: 24, scope: !7)<br>
+!31 = !DILocation(line: 4, column: 3, scope: !7)<br>
<br>
Modified: llvm/trunk/test/DebugInfo/COFF/types-basic.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/types-basic.ll?rev=273696&r1=273695&r2=273696&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/types-basic.ll?rev=273696&r1=273695&r2=273696&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/DebugInfo/COFF/types-basic.ll (original)<br>
+++ llvm/trunk/test/DebugInfo/COFF/types-basic.ll Fri Jun 24 12:55:40 2016<br>
@@ -230,11 +230,11 @@<br>
; CHECK: LinkageName: ?f@@YAXMN_J@Z<br>
; CHECK: }<br>
; CHECK: Local {<br>
-; CHECK: Type: __int64 (0x13)<br>
+; CHECK: Type: float (0x40)<br>
; CHECK: Flags [ (0x1)<br>
; CHECK: IsParameter (0x1)<br>
; CHECK: ]<br>
-; CHECK: VarName: p3<br>
+; CHECK: VarName: p1<br>
; CHECK: }<br>
; CHECK: Local {<br>
; CHECK: Type: double (0x41)<br>
@@ -244,11 +244,11 @@<br>
; CHECK: VarName: p2<br>
; CHECK: }<br>
; CHECK: Local {<br>
-; CHECK: Type: float (0x40)<br>
+; CHECK: Type: __int64 (0x13)<br>
; CHECK: Flags [ (0x1)<br>
; CHECK: IsParameter (0x1)<br>
; CHECK: ]<br>
-; CHECK: VarName: p1<br>
+; CHECK: VarName: p3<br>
; CHECK: }<br>
; CHECK: Local {<br>
; CHECK: Type: int (0x74)<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>