Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit edb7f47

Browse files
committed
Fix a crash when emitting debug info for multi-reg function arguments
by reusing more of the existing machinery This is a follow-up to r312169. Thanks to Björn Pettersson for the testcase! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312773 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit b4f316b)
1 parent 90b3cb1 commit edb7f47

File tree

2 files changed

+69
-14
lines changed

2 files changed

+69
-14
lines changed

lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4809,23 +4809,27 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
48094809
// Check if ValueMap has reg number.
48104810
DenseMap<const Value *, unsigned>::iterator VMI = FuncInfo.ValueMap.find(V);
48114811
if (VMI != FuncInfo.ValueMap.end()) {
4812-
auto *Ty = V->getType();
48134812
const auto &TLI = DAG.getTargetLoweringInfo();
4814-
EVT VT = TLI.getValueType(DAG.getDataLayout(), Ty);
4815-
unsigned NumRegs = TLI.getNumRegisters(Ty->getContext(), VT);
4813+
RegsForValue RFV(V->getContext(), TLI, DAG.getDataLayout(), VMI->second,
4814+
V->getType(), isABIRegCopy(V));
4815+
unsigned NumRegs =
4816+
std::accumulate(RFV.RegCount.begin(), RFV.RegCount.end(), 0);
48164817
if (NumRegs > 1) {
4817-
// The registers are guaranteed to be allocated in sequence.
4818+
unsigned I = 0;
48184819
unsigned Offset = 0;
4819-
MVT RegisterVT = TLI.getRegisterType(Ty->getContext(), VT);
4820-
unsigned RegisterSize = RegisterVT.getSizeInBits();
4821-
for (unsigned I = 0; I != NumRegs; ++I) {
4822-
Op = MachineOperand::CreateReg(VMI->second + I, false);
4823-
auto *FragmentExpr = DIExpression::createFragmentExpression(
4824-
Expr, Offset, RegisterSize);
4825-
FuncInfo.ArgDbgValues.push_back(
4826-
BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), IsDbgDeclare,
4827-
Op->getReg(), Variable, FragmentExpr));
4828-
Offset += RegisterSize;
4820+
auto RegisterVT = RFV.RegVTs.begin();
4821+
for (auto RegCount : RFV.RegCount) {
4822+
unsigned RegisterSize = (RegisterVT++)->getSizeInBits();
4823+
for (unsigned E = I + RegCount; I != E; ++I) {
4824+
// The vregs are guaranteed to be allocated in sequence.
4825+
Op = MachineOperand::CreateReg(VMI->second + I, false);
4826+
auto *FragmentExpr = DIExpression::createFragmentExpression(
4827+
Expr, Offset, RegisterSize);
4828+
FuncInfo.ArgDbgValues.push_back(
4829+
BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), IsDbgDeclare,
4830+
Op->getReg(), Variable, FragmentExpr));
4831+
Offset += RegisterSize;
4832+
}
48294833
}
48304834
return true;
48314835
}

test/DebugInfo/X86/sdag-split-arg.ll

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
; RUN: llc -O0 -filetype=asm %s -o - | FileCheck %s
2+
; Test large integral function arguments passed in multiple registers.
3+
; CHECK: DEBUG_VALUE: foo:bar <- [DW_OP_LLVM_fragment 64 16] %AX
4+
; CHECK: DEBUG_VALUE: foo:bar <- [DW_OP_LLVM_fragment 48 16] %R9W
5+
; CHECK: DEBUG_VALUE: foo:bar <- [DW_OP_LLVM_fragment 32 16] %R10W
6+
; CHECK: DEBUG_VALUE: foo:bar <- [DW_OP_LLVM_fragment 16 16] %R11W
7+
; CHECK: DEBUG_VALUE: foo:bar <- [DW_OP_LLVM_fragment 0 16] %BX
8+
9+
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
10+
target triple = "x86_64-unknown-unknown"
11+
12+
%rec789 = type { [5 x i16] }
13+
14+
define void @foo(%rec789 %bar) !dbg !6 {
15+
%bar.2 = alloca %rec789, align 1
16+
call void @llvm.dbg.value(metadata %rec789 %bar, metadata !17, metadata !DIExpression()), !dbg !18
17+
%1 = extractvalue %rec789 %bar, 0
18+
%.repack = getelementptr inbounds %rec789, %rec789* %bar.2, i16 0, i32 0, i16 0
19+
%.elt = extractvalue [5 x i16] %1, 0
20+
store i16 %.elt, i16* %.repack, align 1
21+
ret void, !dbg !19
22+
}
23+
24+
; Function Attrs: nounwind readnone speculatable
25+
declare void @llvm.dbg.value(metadata, metadata, metadata) #6
26+
27+
!llvm.dbg.cu = !{!0}
28+
!llvm.module.flags = !{!3, !4}
29+
!llvm.ident = !{!5}
30+
31+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2)
32+
!1 = !DIFile(filename: "a.c", directory: "b")
33+
!2 = !{}
34+
!3 = !{i32 2, !"Dwarf Version", i32 4}
35+
!4 = !{i32 2, !"Debug Info Version", i32 3}
36+
!5 = !{!""}
37+
!6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 13, type: !7, isLocal: false, isDefinition: true, scopeLine: 14, isOptimized: false, unit: !0, variables: !2)
38+
!7 = !DISubroutineType(types: !8)
39+
!8 = !{!9, !9}
40+
!9 = !DIDerivedType(tag: DW_TAG_typedef, name: "MyStruct", file: !1, line: 11, baseType: !10)
41+
!10 = !DICompositeType(tag: DW_TAG_structure_type, file: !1, line: 9, size: 80, elements: !11)
42+
!11 = !{!12}
43+
!12 = !DIDerivedType(tag: DW_TAG_member, name: "Array", scope: !10, file: !1, line: 10, baseType: !13, size: 80)
44+
!13 = !DICompositeType(tag: DW_TAG_array_type, baseType: !14, size: 80, elements: !15)
45+
!14 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_signed)
46+
!15 = !{!16}
47+
!16 = !DISubrange(count: 5)
48+
!17 = !DILocalVariable(name: "bar", arg: 1, scope: !6, line: 13, type: !9)
49+
!18 = !DILocation(line: 13, column: 23, scope: !6)
50+
!19 = !DILocation(line: 15, column: 5, scope: !6)
51+
!20 = !DILocation(line: 16, column: 1, scope: !6)

0 commit comments

Comments
 (0)