Skip to content

Commit 0d3e4d9

Browse files
committed
[Debug-Info][llvm-dwarfdump] Don't use DW_FORM_data4/8
to encode the constants for DW_AT_data_member_location. Summary: In DWARF v3, DW_FORM_data4/8 in DW_AT_data_member_location are interpreted as location list pointers. Interpreting constants as pointers is not expected, so we use DW_FORM_udata to encode the constants. Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D105687
1 parent 3211ead commit 0d3e4d9

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -1618,9 +1618,18 @@ DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
16181618
addUInt(*MemLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
16191619
addUInt(*MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes);
16201620
addBlock(MemberDie, dwarf::DW_AT_data_member_location, MemLocationDie);
1621-
} else if (!IsBitfield || DD->useDWARF2Bitfields())
1622-
addUInt(MemberDie, dwarf::DW_AT_data_member_location, None,
1623-
OffsetInBytes);
1621+
} else if (!IsBitfield || DD->useDWARF2Bitfields()) {
1622+
// In DWARF v3, DW_FORM_data4/8 in DW_AT_data_member_location are
1623+
// interpreted as location-list pointers. Interpreting constants as
1624+
// pointers is not expected, so we use DW_FORM_udata to encode the
1625+
// constants here.
1626+
if (DD->getDwarfVersion() == 3)
1627+
addUInt(MemberDie, dwarf::DW_AT_data_member_location,
1628+
dwarf::DW_FORM_udata, OffsetInBytes);
1629+
else
1630+
addUInt(MemberDie, dwarf::DW_AT_data_member_location, None,
1631+
OffsetInBytes);
1632+
}
16241633
}
16251634

16261635
if (DT->isProtected())

llvm/test/DebugInfo/MSP430/dwarf-basics.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
; CHECK: DW_AT_type (0x{{.*}} "*")
8585
; CHECK: DW_AT_decl_file ("/tmp{{[/\\]}}dwarf-basics.c")
8686
; CHECK: DW_AT_decl_line (2)
87-
; CHECK: DW_AT_data_member_location (0x00)
87+
; CHECK: DW_AT_data_member_location (0)
8888

8989
; CHECK: NULL
9090

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -dwarf-version=3 -O0 -o - -filetype=obj < %s | \
2+
; RUN: llvm-dwarfdump -v -debug-info -name g -| FileCheck %s
3+
4+
; CHECK: DW_AT_name [DW_FORM_strp] {{.*}} "g"
5+
; CHECK: DW_AT_data_member_location [DW_FORM_udata] (65536)
6+
7+
; ModuleID = '1.cpp'
8+
source_filename = "1.cpp"
9+
10+
%struct.e = type { [65536 x i8], i8 }
11+
12+
@E = dso_local local_unnamed_addr global %struct.e zeroinitializer, align 1, !dbg !0
13+
14+
!llvm.dbg.cu = !{!2}
15+
!llvm.module.flags = !{!14, !15, !16, !17}
16+
!llvm.ident = !{!18}
17+
18+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
19+
!1 = distinct !DIGlobalVariable(name: "E", scope: !2, file: !3, line: 5, type: !6, isLocal: false, isDefinition: true)
20+
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 13.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
21+
!3 = !DIFile(filename: "1.cpp", directory: "/tmp")
22+
!4 = !{}
23+
!5 = !{!0}
24+
!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "e", file: !3, line: 1, size: 524296, flags: DIFlagTypePassByValue, elements: !7, identifier: "_ZTS1e")
25+
!7 = !{!8, !13}
26+
!8 = !DIDerivedType(tag: DW_TAG_member, name: "f", scope: !6, file: !3, line: 2, baseType: !9, size: 524288)
27+
!9 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, size: 524288, elements: !11)
28+
!10 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_unsigned_char)
29+
!11 = !{!12}
30+
!12 = !DISubrange(count: 65536)
31+
!13 = !DIDerivedType(tag: DW_TAG_member, name: "g", scope: !6, file: !3, line: 3, baseType: !10, size: 8, offset: 524288)
32+
!14 = !{i32 7, !"Dwarf Version", i32 3}
33+
!15 = !{i32 2, !"Debug Info Version", i32 3}
34+
!16 = !{i32 1, !"wchar_size", i32 4}
35+
!17 = !{i32 7, !"uwtable", i32 1}
36+
!18 = !{!"clang version 13.0.0"}

0 commit comments

Comments
 (0)