1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

[SafeStack][DebugInfo] Insert DW_OP_deref in correct location

This patch addresses the issue found in https://bugs.llvm.org/show_bug.cgi?id=44585
where a DW_OP_deref was placed at the end of a dwarf expression, resulting in
corrupt symbols when debugging.

Differential Revision: https://reviews.llvm.org/D73526
This commit is contained in:
Leonard Chan 2020-01-28 12:30:33 -08:00
parent 15841df48b
commit 4199a00ff4
4 changed files with 66 additions and 35 deletions

View File

@ -754,9 +754,9 @@ InstrEmitter::EmitDbgValue(SDDbgValue *SD,
// Indirect addressing is indicated by an Imm as the second parameter.
if (SD->isIndirect())
Expr = DIExpression::append(Expr, {dwarf::DW_OP_deref});
MIB.addReg(0U, RegState::Debug);
MIB.addImm(0U);
else
MIB.addReg(0U, RegState::Debug);
MIB.addMetadata(Var);
MIB.addMetadata(Expr);

View File

@ -51,39 +51,28 @@
; CHECK: SizeOf: 0
; CHECK: Name:
; CHECK: }
; CHECK: Pointer (0x1004) {
; CHECK: TypeLeafKind: LF_POINTER (0x1002)
; CHECK: PointeeType: 0x1003
; CHECK: PtrType: Near32 (0xA)
; CHECK: PtrMode: LValueReference (0x1)
; CHECK: IsFlat: 0
; CHECK: IsConst: 0
; CHECK: IsVolatile: 0
; CHECK: IsUnaligned: 0
; CHECK: SizeOf: 0
; CHECK: }
; CHECK: Array (0x1005) {
; CHECK: Array (0x1004) {
; CHECK: TypeLeafKind: LF_ARRAY (0x1503)
; CHECK: ElementType: char (0x70)
; CHECK: IndexType: unsigned long (0x22)
; CHECK: SizeOf: 7
; CHECK: Name:
; CHECK: }
; CHECK: Array (0x1006) {
; CHECK: Array (0x1005) {
; CHECK: TypeLeafKind: LF_ARRAY (0x1503)
; CHECK: ElementType: 0x1005
; CHECK: ElementType: 0x1004
; CHECK: IndexType: unsigned long (0x22)
; CHECK: SizeOf: 35
; CHECK: Name:
; CHECK: }
; CHECK: Array (0x1007) {
; CHECK: Array (0x1006) {
; CHECK: TypeLeafKind: LF_ARRAY (0x1503)
; CHECK: ElementType: 0x1006
; CHECK: ElementType: 0x1005
; CHECK: IndexType: unsigned long (0x22)
; CHECK: SizeOf: 70
; CHECK: Name:
; CHECK: }
; CHECK: Struct (0x1008) {
; CHECK: Struct (0x1007) {
; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505)
; CHECK: MemberCount: 0
; CHECK: Properties [ (0x280)
@ -97,16 +86,16 @@
; CHECK: Name: incomplete_struct
; CHECK: LinkageName: .?AUincomplete_struct@@
; CHECK: }
; CHECK: Array (0x1009) {
; CHECK: Array (0x1008) {
; CHECK: TypeLeafKind: LF_ARRAY (0x1503)
; CHECK: ElementType: incomplete_struct (0x1008)
; CHECK: ElementType: incomplete_struct (0x1007)
; CHECK: IndexType: unsigned long (0x22)
; CHECK: SizeOf: 12
; CHECK: Name:
; CHECK: }
; CHECK: Pointer (0x100A) {
; CHECK: Pointer (0x1009) {
; CHECK: TypeLeafKind: LF_POINTER (0x1002)
; CHECK: PointeeType: 0x1009
; CHECK: PointeeType: 0x1008
; CHECK: PtrType: Near32 (0xA)
; CHECK: PtrMode: Pointer (0x0)
; CHECK: IsFlat: 0
@ -115,7 +104,7 @@
; CHECK: IsUnaligned: 0
; CHECK: SizeOf: 4
; CHECK: }
; CHECK: FieldList (0x100B) {
; CHECK: FieldList (0x100A) {
; CHECK: TypeLeafKind: LF_FIELDLIST (0x1203)
; CHECK: DataMember {
; CHECK: TypeLeafKind: LF_MEMBER (0x150D)
@ -125,31 +114,31 @@
; CHECK: Name: s1
; CHECK: }
; CHECK: }
; CHECK: Struct (0x100C) {
; CHECK: Struct (0x100B) {
; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505)
; CHECK: MemberCount: 1
; CHECK: Properties [ (0x200)
; CHECK: HasUniqueName (0x200)
; CHECK: ]
; CHECK: FieldList: <field list> (0x100B)
; CHECK: FieldList: <field list> (0x100A)
; CHECK: DerivedFrom: 0x0
; CHECK: VShape: 0x0
; CHECK: SizeOf: 4
; CHECK: Name: incomplete_struct
; CHECK: LinkageName: .?AUincomplete_struct@@
; CHECK: }
; CHECK: StringId (0x100D) {
; CHECK: StringId (0x100C) {
; CHECK: TypeLeafKind: LF_STRING_ID (0x1605)
; CHECK: Id: 0x0
; CHECK: StringData: /t.cpp
; CHECK: }
; CHECK: UdtSourceLine (0x100E) {
; CHECK: UdtSourceLine (0x100D) {
; CHECK: TypeLeafKind: LF_UDT_SRC_LINE (0x1606)
; CHECK: UDT: incomplete_struct (0x100C)
; CHECK: SourceFile: /t.cpp (0x100D)
; CHECK: UDT: incomplete_struct (0x100B)
; CHECK: SourceFile: /t.cpp (0x100C)
; CHECK: LineNumber: 4
; CHECK: }
; CHECK: Modifier (0x100F) {
; CHECK: Modifier (0x100E) {
; CHECK: TypeLeafKind: LF_MODIFIER (0x1001)
; CHECK: ModifiedType: int (0x74)
; CHECK: Modifiers [ (0x3)
@ -157,9 +146,9 @@
; CHECK: Volatile (0x2)
; CHECK: ]
; CHECK: }
; CHECK: Array (0x1010) {
; CHECK: Array (0x100F) {
; CHECK: TypeLeafKind: LF_ARRAY (0x1503)
; CHECK: ElementType: const volatile int (0x100F)
; CHECK: ElementType: const volatile int (0x100E)
; CHECK: IndexType: unsigned long (0x22)
; CHECK: SizeOf: 16
; CHECK: Name:

View File

@ -14,7 +14,7 @@
; }
; CHECK: ![[ZZZ:.*]] = !DILocalVariable(name: "zzz",
; CHECK: DBG_VALUE {{.*}} ![[ZZZ]], !DIExpression(DW_OP_constu, 400, DW_OP_minus, DW_OP_deref)
; CHECK: DBG_VALUE {{.*}} ![[ZZZ]], !DIExpression(DW_OP_constu, 400, DW_OP_minus)
%struct.S = type { [100 x i32] }

View File

@ -0,0 +1,42 @@
; This test prevents a regression of PR44585 where the DW_OP_deref is incorrectly placed at the end of the expression chain.
; RUN: llc -O0 -mtriple=x86_64-unknown-linux-gnu -filetype=obj %s -o - | llvm-dwarfdump - --name=value | FileCheck %s
; REQUIRES: object-emission
; CHECK: DW_TAG_variable
; CHECK-NEXT: DW_AT_location
; CHECK-NEXT: DW_OP_breg{{[0-9]+}} R{{[0-9A-Z]+}}-8
; CHECK-NEXT: DW_OP_breg{{[0-9]+}} R{{[0-9A-Z]+}}+8, DW_OP_deref, DW_OP_lit8, DW_OP_minus
; CHECK-NEXT: DW_AT_name ("value")
define dso_local void @_Z4funcv() safestack !dbg !7 {
%1 = alloca i8, align 8
call void @llvm.dbg.declare(metadata i8* %1, metadata !11, metadata !DIExpression()), !dbg !22
call void @extern_func(i8* %1), !dbg !22
ret void
}
declare void @llvm.dbg.declare(metadata, metadata, metadata)
declare void @extern_func(i8* %0)
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!4}
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, emissionKind: FullDebug)
!1 = !DIFile(filename: "/tmp/test3.cpp", directory: "")
!4 = !{i32 2, !"Debug Info Version", i32 3}
!7 = distinct !DISubprogram(name: "func", linkageName: "_Z4funcv", scope: !8, file: !8, line: 7, type: !9, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
!8 = !DIFile(filename: "/tmp/test3.cpp", directory: "")
!9 = !DISubroutineType(types: !10)
!10 = !{null}
!11 = !DILocalVariable(name: "value", scope: !7, file: !8, line: 8, type: !12)
!12 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "A", file: !8, line: 1, size: 64, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !13, identifier: "_ZTS1A")
!13 = !{!14, !18}
!14 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !12, file: !8, line: 4, baseType: !15, size: 64, flags: DIFlagPublic)
!15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64)
!16 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !17)
!17 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
!18 = !DISubprogram(name: "A", scope: !12, file: !8, line: 3, type: !19, scopeLine: 3, flags: DIFlagPublic | DIFlagPrototyped, spFlags: 0)
!19 = !DISubroutineType(types: !20)
!20 = !{null, !21, !15}
!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
!22 = !DILocation(line: 8, column: 5, scope: !7)