Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -8798,11 +8798,29 @@ SDB->setValue(&Arg, Res); if (!TM.Options.EnableFastISel && Res.getOpcode() == ISD::BUILD_PAIR) { + // We want to find the highest frame index involved here (associating + // the argument with the lowest stack address involved). The + // getCopyFromParts call above is swapping the order of the operands to + // BUILD_PAIR depending on endianess, so we need to assume that all + // targets puts the least significant bits in first operand of the pair + // and the most significant bits in the second operand. Thus, for big + // endian targets we should look for the frame index in the second + // operand. + bool BigEndian = DAG.getDataLayout().isBigEndian(); if (LoadSDNode *LNode = - dyn_cast(Res.getOperand(0).getNode())) + dyn_cast(Res.getOperand(BigEndian ? 1 : 0).getNode())) if (FrameIndexSDNode *FI = - dyn_cast(LNode->getBasePtr().getNode())) - FuncInfo->setArgumentFrameIndex(&Arg, FI->getIndex()); + dyn_cast(LNode->getBasePtr().getNode())) { +#ifndef NDEBUG + if (LoadSDNode *OtherLNode = + dyn_cast(Res.getOperand(BigEndian ? 0 : 1).getNode())) + if (FrameIndexSDNode *OtherFI = + dyn_cast(OtherLNode->getBasePtr().getNode())) + assert(FI->getIndex() > OtherFI->getIndex() && + "Did not find the highest FI."); +#endif + FuncInfo->setArgumentFrameIndex(&Arg, FI->getIndex()); + } } // Update the SwiftErrorVRegDefMap. Index: test/CodeGen/PowerPC/debuginfo-stackarg.ll =================================================================== --- /dev/null +++ test/CodeGen/PowerPC/debuginfo-stackarg.ll @@ -0,0 +1,79 @@ +; RUN: llc < %s -O1 -o - | FileCheck %s + +; This ll-file was created by: +; clang --target=powerpc-apple-darwin9 -O1 -S -g -emit-llvm debuginfo-stackarg.c +; +; with debuginfo-stackarg.c being the program: +; long long foo(long long bar1, long long bar2, long long bar3, long long bar4, long long bar5) +; { +; return bar1 + bar2 + bar3 + bar4 + bar5; +; } + +; ModuleID = 'debuginfo-stackarg.c' +source_filename = "debuginfo-stackarg.c" +target datalayout = "E-m:o-p:32:32-f64:32:64-n32" +target triple = "powerpc-apple-macosx10.5.0" + +; Function Attrs: nounwind readnone ssp uwtable +define i64 @foo(i64 %bar1, i64 %bar2, i64 %bar3, i64 %bar4, i64 %bar5) local_unnamed_addr #0 !dbg !8 { +; Variable bar5 should be associated with a position on the stack (relative r1). +; Let's verify that we point out the start address (lowest address). +; +; The variable seems to be stored as 4 bytes at offset 56 and 4 bytes at offset 60, +; so we should tell the debugger that the variable is stored as 8 bytes starting at offset 56. +; I'm assuming that the calling convention is to storing the whole 64-bit value in big-endian style on the stack. +; +; CHECK: DEBUG_VALUE: foo:bar5 <- [DW_OP_plus_uconst 56] [%R1+0] +; CHECK: lwz r{{[0-9]+}}, 60(r1) +; CHECK: lwz r{{[0-9]+}}, 56(r1) +entry: + tail call void @llvm.dbg.value(metadata i64 %bar1, metadata !13, metadata !DIExpression()), !dbg !18 + tail call void @llvm.dbg.value(metadata i64 %bar2, metadata !14, metadata !DIExpression()), !dbg !19 + tail call void @llvm.dbg.value(metadata i64 %bar3, metadata !15, metadata !DIExpression()), !dbg !20 + tail call void @llvm.dbg.value(metadata i64 %bar4, metadata !16, metadata !DIExpression()), !dbg !21 + tail call void @llvm.dbg.value(metadata i64 %bar5, metadata !17, metadata !DIExpression()), !dbg !22 + %add = add nsw i64 %bar2, %bar1, !dbg !23 + %add1 = add nsw i64 %add, %bar3, !dbg !24 + %add2 = add nsw i64 %add1, %bar4, !dbg !25 + %add3 = add nsw i64 %add2, %bar5, !dbg !26 + ret i64 %add3, !dbg !27 +} + +; Function Attrs: nounwind readnone speculatable +declare void @llvm.dbg.value(metadata, metadata, metadata) #1 + +attributes #0 = { nounwind readnone ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="-altivec,-bpermd,-crypto,-direct-move,-extdiv,-htm,-power8-vector,-power9-vector,-qpx,-vsx" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone speculatable } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5, !6} +!llvm.ident = !{!7} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "debuginfo-stackarg.c", directory: "/repo") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 2} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 4} +!6 = !{i32 7, !"PIC Level", i32 2} +!7 = !{!"clang version 6.0.0"} +!8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !12) +!9 = !DISubroutineType(types: !10) +!10 = !{!11, !11, !11, !11, !11, !11} +!11 = !DIBasicType(name: "long long int", size: 64, encoding: DW_ATE_signed) +!12 = !{!13, !14, !15, !16, !17} +!13 = !DILocalVariable(name: "bar1", arg: 1, scope: !8, file: !1, line: 1, type: !11) +!14 = !DILocalVariable(name: "bar2", arg: 2, scope: !8, file: !1, line: 1, type: !11) +!15 = !DILocalVariable(name: "bar3", arg: 3, scope: !8, file: !1, line: 1, type: !11) +!16 = !DILocalVariable(name: "bar4", arg: 4, scope: !8, file: !1, line: 1, type: !11) +!17 = !DILocalVariable(name: "bar5", arg: 5, scope: !8, file: !1, line: 1, type: !11) +!18 = !DILocation(line: 1, column: 25, scope: !8) +!19 = !DILocation(line: 1, column: 41, scope: !8) +!20 = !DILocation(line: 1, column: 57, scope: !8) +!21 = !DILocation(line: 1, column: 73, scope: !8) +!22 = !DILocation(line: 1, column: 89, scope: !8) +!23 = !DILocation(line: 3, column: 15, scope: !8) +!24 = !DILocation(line: 3, column: 22, scope: !8) +!25 = !DILocation(line: 3, column: 29, scope: !8) +!26 = !DILocation(line: 3, column: 36, scope: !8) +!27 = !DILocation(line: 3, column: 3, scope: !8)