Blame SOURCES/0001-GlobalISel-Lower-dbg.declare-into-indirect-DBG_VALUE.patch

b0a370
From 9959e0572c47e3cdedb51d05bf76bb56965ede98 Mon Sep 17 00:00:00 2001
b0a370
From: Tom Stellard <tstellar@redhat.com>
b0a370
Date: Fri, 7 Sep 2018 22:19:20 -0700
b0a370
Subject: [PATCH] [GlobalISel] Lower dbg.declare into indirect DBG_VALUE
b0a370
b0a370
Summary:
b0a370
D31439 changed the semantics of dbg.declare to take the address of a
b0a370
variable as the first argument, making it indirect.  It specifically
b0a370
updated FastISel for this change here:
b0a370
b0a370
https://reviews.llvm.org/D31439#change-WVArzi177jPl
b0a370
b0a370
GlobalISel needs to follow suit, or else it will be missing a level of
b0a370
indirection in the generated debuginfo.  This problem was seen in a Rust
b0a370
debuginfo test on aarch64, since GlobalISel is used at -O0 for aarch64.
b0a370
b0a370
https://github.com/rust-lang/rust/issues/49807
b0a370
https://bugzilla.redhat.com/show_bug.cgi?id=1611597
b0a370
https://bugzilla.redhat.com/show_bug.cgi?id=1625768
b0a370
b0a370
Reviewers: dblaikie, aprantl, t.p.northover, javed.absar, rnk
b0a370
b0a370
Reviewed By: rnk
b0a370
b0a370
Subscribers: #debug-info, rovka, kristof.beyls, JDevlieghere, llvm-commits, tstellar
b0a370
b0a370
Differential Revision: https://reviews.llvm.org/D51749
b0a370
---
b0a370
 lib/CodeGen/GlobalISel/IRTranslator.cpp        |  9 ++--
b0a370
 test/CodeGen/AArch64/GlobalISel/debug-cpp.ll   | 67 ++++++++++++++++++++++++++
b0a370
 test/CodeGen/AArch64/GlobalISel/debug-insts.ll |  4 +-
b0a370
 3 files changed, 74 insertions(+), 6 deletions(-)
b0a370
 create mode 100644 test/CodeGen/AArch64/GlobalISel/debug-cpp.ll
b0a370
b0a370
diff --git a/lib/CodeGen/GlobalISel/IRTranslator.cpp b/lib/CodeGen/GlobalISel/IRTranslator.cpp
b0a370
index 75496fb..9926be3 100644
b0a370
--- a/lib/CodeGen/GlobalISel/IRTranslator.cpp
b0a370
+++ b/lib/CodeGen/GlobalISel/IRTranslator.cpp
b0a370
@@ -763,9 +763,12 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
b0a370
       // instructions (in fact, they get ignored if they *do* exist).
b0a370
       MF->setVariableDbgInfo(DI.getVariable(), DI.getExpression(),
b0a370
                              getOrCreateFrameIndex(*AI), DI.getDebugLoc());
b0a370
-    } else
b0a370
-      MIRBuilder.buildDirectDbgValue(getOrCreateVReg(*Address),
b0a370
-                                     DI.getVariable(), DI.getExpression());
b0a370
+    } else {
b0a370
+      // A dbg.declare describes the address of a source variable, so lower it
b0a370
+      // into an indirect DBG_VALUE.
b0a370
+      MIRBuilder.buildIndirectDbgValue(getOrCreateVReg(*Address),
b0a370
+                                       DI.getVariable(), DI.getExpression());
b0a370
+    }
b0a370
     return true;
b0a370
   }
b0a370
   case Intrinsic::vaend:
b0a370
diff --git a/test/CodeGen/AArch64/GlobalISel/debug-cpp.ll b/test/CodeGen/AArch64/GlobalISel/debug-cpp.ll
b0a370
new file mode 100644
b0a370
index 0000000..e5a4e55
b0a370
--- /dev/null
b0a370
+++ b/test/CodeGen/AArch64/GlobalISel/debug-cpp.ll
b0a370
@@ -0,0 +1,67 @@
b0a370
+; RUN: llc -global-isel -mtriple=aarch64 %s -stop-after=irtranslator -o - | FileCheck %s
b0a370
+; RUN: llc -mtriple=aarch64 -global-isel --global-isel-abort=0 -o /dev/null
b0a370
+
b0a370
+; struct NTCopy {
b0a370
+;   NTCopy();
b0a370
+;   NTCopy(const NTCopy &);
b0a370
+;   int x;
b0a370
+; };
b0a370
+; int foo(NTCopy o) {
b0a370
+;   return o.x;
b0a370
+; }
b0a370
+
b0a370
+; ModuleID = 'ntcopy.cpp'
b0a370
+source_filename = "ntcopy.cpp"
b0a370
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
b0a370
+target triple = "aarch64-unknown-linux-gnu"
b0a370
+
b0a370
+%struct.NTCopy = type { i32 }
b0a370
+
b0a370
+; CHECK-LABEL: name: _Z3foo6NTCopy
b0a370
+; CHECK: DBG_VALUE debug-use %{{[0-9]+}}(p0), 0, !23, !DIExpression(), debug-location !24
b0a370
+; Function Attrs: noinline nounwind optnone
b0a370
+define dso_local i32 @_Z3foo6NTCopy(%struct.NTCopy* %o) #0 !dbg !7 {
b0a370
+entry:
b0a370
+  call void @llvm.dbg.declare(metadata %struct.NTCopy* %o, metadata !23, metadata !DIExpression()), !dbg !24
b0a370
+  %x = getelementptr inbounds %struct.NTCopy, %struct.NTCopy* %o, i32 0, i32 0, !dbg !25
b0a370
+  %0 = load i32, i32* %x, align 4, !dbg !25
b0a370
+  ret i32 %0, !dbg !26
b0a370
+}
b0a370
+
b0a370
+; Function Attrs: nounwind readnone speculatable
b0a370
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
b0a370
+
b0a370
+attributes #0 = { noinline nounwind optnone }
b0a370
+attributes #1 = { nounwind readnone speculatable }
b0a370
+
b0a370
+!llvm.dbg.cu = !{!0}
b0a370
+!llvm.module.flags = !{!3, !4, !5}
b0a370
+!llvm.ident = !{!6}
b0a370
+
b0a370
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
b0a370
+!1 = !DIFile(filename: "ntcopy.cpp", directory: "/tmp")
b0a370
+!2 = !{}
b0a370
+!3 = !{i32 2, !"Dwarf Version", i32 4}
b0a370
+!4 = !{i32 2, !"Debug Info Version", i32 3}
b0a370
+!5 = !{i32 1, !"wchar_size", i32 4}
b0a370
+!6 = !{!"clang version 8.0.0 "}
b0a370
+!7 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foo6NTCopy", scope: !1, file: !1, line: 6, type: !8, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
b0a370
+!8 = !DISubroutineType(types: !9)
b0a370
+!9 = !{!10, !11}
b0a370
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
b0a370
+!11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "NTCopy", file: !1, line: 1, size: 32, elements: !12, identifier: "_ZTS6NTCopy")
b0a370
+!12 = !{!13, !14, !18}
b0a370
+!13 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !11, file: !1, line: 4, baseType: !10, size: 32)
b0a370
+!14 = !DISubprogram(name: "NTCopy", scope: !11, file: !1, line: 2, type: !15, isLocal: false, isDefinition: false, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false)
b0a370
+!15 = !DISubroutineType(types: !16)
b0a370
+!16 = !{null, !17}
b0a370
+!17 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
b0a370
+!18 = !DISubprogram(name: "NTCopy", scope: !11, file: !1, line: 3, type: !19, isLocal: false, isDefinition: false, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false)
b0a370
+!19 = !DISubroutineType(types: !20)
b0a370
+!20 = !{null, !17, !21}
b0a370
+!21 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !22, size: 64)
b0a370
+!22 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !11)
b0a370
+!23 = !DILocalVariable(name: "o", arg: 1, scope: !7, file: !1, line: 6, type: !11)
b0a370
+!24 = !DILocation(line: 6, column: 16, scope: !7)
b0a370
+!25 = !DILocation(line: 7, column: 12, scope: !7)
b0a370
+!26 = !DILocation(line: 7, column: 3, scope: !7)
b0a370
diff --git a/test/CodeGen/AArch64/GlobalISel/debug-insts.ll b/test/CodeGen/AArch64/GlobalISel/debug-insts.ll
b0a370
index 8309e00..256eb37 100644
b0a370
--- a/test/CodeGen/AArch64/GlobalISel/debug-insts.ll
b0a370
+++ b/test/CodeGen/AArch64/GlobalISel/debug-insts.ll
b0a370
@@ -6,18 +6,16 @@
b0a370
 ; CHECK:    - { id: {{.*}}, name: in.addr, type: default, offset: 0, size: {{.*}}, alignment: {{.*}},
b0a370
 ; CHECK-NEXT: callee-saved-register: '', callee-saved-restored: true,
b0a370
 ; CHECK-NEXT: debug-info-variable: '!11', debug-info-expression: '!DIExpression()',
b0a370
-; CHECK: DBG_VALUE debug-use %0(s32), debug-use $noreg, !11, !DIExpression(), debug-location !12
b0a370
 define void @debug_declare(i32 %in) #0 !dbg !7 {
b0a370
 entry:
b0a370
   %in.addr = alloca i32, align 4
b0a370
   store i32 %in, i32* %in.addr, align 4
b0a370
   call void @llvm.dbg.declare(metadata i32* %in.addr, metadata !11, metadata !DIExpression()), !dbg !12
b0a370
-  call void @llvm.dbg.declare(metadata i32 %in, metadata !11, metadata !DIExpression()), !dbg !12
b0a370
   ret void, !dbg !12
b0a370
 }
b0a370
 
b0a370
 ; CHECK-LABEL: name: debug_declare_vla
b0a370
-; CHECK: DBG_VALUE debug-use %{{[0-9]+}}(p0), debug-use $noreg, !14, !DIExpression(), debug-location !15
b0a370
+; CHECK: DBG_VALUE debug-use %{{[0-9]+}}(p0), 0, !14, !DIExpression(), debug-location !15
b0a370
 define void @debug_declare_vla(i32 %in) #0 !dbg !13 {
b0a370
 entry:
b0a370
   %vla.addr = alloca i32, i32 %in
b0a370
-- 
b0a370
1.8.3.1
b0a370