Skip to content

Commit 7ca2386

Browse files
Merge pull request #362 from adrian-prantl/57294211-1
Cherry-pick DwarfExpression bugfix.
2 parents 7cc97aa + 7743452 commit 7ca2386

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,18 @@ bool DwarfExpression::addMachineReg(const TargetRegisterInfo &TRI,
155155
CurSubReg.set(Offset, Offset + Size);
156156

157157
// If this sub-register has a DWARF number and we haven't covered
158-
// its range, emit a DWARF piece for it.
159-
if (CurSubReg.test(Coverage)) {
158+
// its range, and its range covers the value, emit a DWARF piece for it.
159+
if (Offset < MaxSize && CurSubReg.test(Coverage)) {
160160
// Emit a piece for any gap in the coverage.
161161
if (Offset > CurPos)
162-
DwarfRegs.push_back({-1, Offset - CurPos, "no DWARF register encoding"});
162+
DwarfRegs.push_back(
163+
{-1, Offset - CurPos, "no DWARF register encoding"});
163164
DwarfRegs.push_back(
164165
{Reg, std::min<unsigned>(Size, MaxSize - Offset), "sub-register"});
165-
if (Offset >= MaxSize)
166-
break;
167-
168-
// Mark it as emitted.
169-
Coverage.set(Offset, Offset + Size);
170-
CurPos = Offset + Size;
171166
}
167+
// Mark it as emitted.
168+
Coverage.set(Offset, Offset + Size);
169+
CurPos = Offset + Size;
172170
}
173171
// Failed to find any DWARF encoding.
174172
if (CurPos == 0)
@@ -391,6 +389,7 @@ void DwarfExpression::addExpression(DIExpressionCursor &&ExprCursor,
391389
// empty DW_OP_piece / DW_OP_bit_piece before we emitted the base
392390
// location.
393391
assert(OffsetInBits >= FragmentOffset && "fragment offset not added?");
392+
assert(SizeInBits >= OffsetInBits - FragmentOffset && "size underflow");
394393

395394
// If addMachineReg already emitted DW_OP_piece operations to represent
396395
// a super-register by splicing together sub-registers, subtract the size
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# RUN: llc -start-before=livedebugvalues -filetype=obj -o - %s | \
2+
# RUN: llvm-dwarfdump -debug-info - | FileCheck %s
3+
#
4+
# In this test the first DBG_VALUE is 32 bits large and sits in 128-bit register Q8,
5+
# which has to be decomposed into two 64-bit register D16, D17.
6+
# This test ensures that the unused D17 is suppressed in the output.
7+
#
8+
# CHECK: .debug_info contents:
9+
# CHECK: DW_TAG_formal_parameter
10+
# CHECK-NEXT: DW_AT_location
11+
# CHECK-NEXT: DW_OP_regx D16, DW_OP_piece 0x4, DW_OP_regx D15, DW_OP_bit_piece 0x20 0x20
12+
# CHECK-NEXT: DW_AT_name {{.*}}"boundingRect"
13+
--- |
14+
target triple = "thumbv7k-apple-watchos"
15+
define swiftcc void @f() !dbg !5 {
16+
ret void
17+
}
18+
!llvm.module.flags = !{!0}
19+
!llvm.dbg.cu = !{!2}
20+
!0 = !{i32 2, !"Debug Info Version", i32 3}
21+
!2 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !3,
22+
isOptimized: true, runtimeVersion: 5, emissionKind: FullDebug, enums: !4, globals: !4, imports: !4)
23+
!3 = !DIFile(filename: "t.swift", directory: "/")
24+
!4 = !{}
25+
!5 = distinct !DISubprogram(name: "f", scope: !3, file: !3, line: 388, type: !9, scopeLine: 388, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !4)
26+
!9 = !DISubroutineType(types: !4)
27+
!10 = !DILocation(line: 0, scope: !5)
28+
!12 = !DILocalVariable(name: "boundingRect", arg: 1, scope: !5, file: !3, line: 388, type: !13)
29+
!13 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !14)
30+
!14 = !DICompositeType(tag: DW_TAG_structure_type, name: "CGRect", scope: !5, file: !3, line: 46, size: 128, elements: !4, runtimeLang: DW_LANG_Swift, identifier: "$sSo6CGRectVD")
31+
name: 'f'
32+
body: |
33+
bb.0:
34+
DBG_VALUE $s31, $noreg, !12, !DIExpression(DW_OP_LLVM_fragment, 32, 32), debug-location !10
35+
DBG_VALUE $q8, $noreg, !12, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !10
36+
renamable $r0 = t2ADDri $r6, 144, 14, $noreg, $noreg, debug-location !10

llvm/test/MC/X86/dwarf-size-field-overflow.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# This test generates too many debug location entries to fit into 65KB required
22
# by DWARF < 5. Check that the location is set to 0 instead of crashing.
33
#
4-
# RUN: %python %s 4000 | llc -mtriple=x86_64-apple-darwin -filetype=obj -o %t
5-
# RUN: llvm-dwarfdump %t | FileCheck %s
4+
# RUN: %python %s 5750 | llc -mtriple=x86_64-apple-darwin -filetype=obj -o - \
5+
# RUN: | llvm-dwarfdump - | FileCheck %s
66
#
77
# CHECK: 0x0000004d: DW_TAG_formal_parameter
88
# CHECK-NEXT: DW_AT_location (0x00000000
@@ -39,11 +39,11 @@ attributes #0 = {{ nounwind readnone speculatable }}
3939
!34 = !DILocation(line: 12, column: 8, scope: !24)
4040
"""
4141

42-
CALL = "call void @llvm.dbg.value(metadata i64 {0}, metadata !30, metadata !DIExpression(DW_OP_LLVM_fragment, {0}, 64)), !dbg !34"
42+
CALL = "call void @llvm.dbg.value(metadata i64 {0}, metadata !30, metadata !DIExpression(DW_OP_LLVM_fragment, {1}, 8)), !dbg !34"
4343

4444
if __name__ == '__main__':
4545
N = int(sys.argv[1])
4646
calls = []
4747
for i in range(0, N):
48-
calls.append(CALL.format(i * 10**12))
48+
calls.append(CALL.format(i * 10**12, i*8))
4949
print(SKELETON.format('\n'.join(calls)))

0 commit comments

Comments
 (0)