Skip to content

Commit 0e5c504

Browse files
authored
[DebugInfo] [SelectionDAG] Fix handling of duplicate dbg values (#86598)
Before this fix, a duplicate llvm.dbg.value intrinsic referring to an argument, after an alloca, would be generated with `$noreg`, losing debug information. Instead, we silently drop the second debug info, so it doesn't break the first one. rdar://125375717
1 parent 601d7ea commit 0e5c504

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6007,12 +6007,15 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
60076007
// incorrect hoisting of the DBG_VALUE to the function entry).
60086008
// Notice that we allow one dbg.value per IR level argument, to accommodate
60096009
// for the situation with fragments above.
6010+
// If there is no node for the value being handled, we return true to skip
6011+
// the normal generation of debug info, as it would kill existing debug
6012+
// info for the parameter in case of duplicates.
60106013
if (VariableIsFunctionInputArg) {
60116014
unsigned ArgNo = Arg->getArgNo();
60126015
if (ArgNo >= FuncInfo.DescribedArgs.size())
60136016
FuncInfo.DescribedArgs.resize(ArgNo + 1, false);
60146017
else if (!IsInPrologue && FuncInfo.DescribedArgs.test(ArgNo))
6015-
return false;
6018+
return !NodeMap[V].getNode();
60166019
FuncInfo.DescribedArgs.set(ArgNo);
60176020
}
60186021
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -start-after=codegenprepare -stop-before=finalize-isel -o - %s -experimental-debug-variable-locations=false | FileCheck %s
2+
3+
; Input to this test was created by reducing a Swift file using bugpoint
4+
5+
; CHECK-DAG: ![[LHS:.*]] = !DILocalVariable(name: "lhs"
6+
7+
define hidden i64 @"_wideDivide42"(ptr %0, ptr %1, ptr %2, i64 %3, i64 %4, i64 %5, i64 %6, i64 %7, i64 %8) local_unnamed_addr !dbg !16 {
8+
; CHECK-LABEL: name: _wideDivide42
9+
; CHECK-NOT: DBG_VALUE
10+
; CHECK: DBG_VALUE $rcx, $noreg, ![[LHS]], !DIExpression(DW_OP_LLVM_fragment, 0, 64)
11+
; CHECK-NEXT: DBG_VALUE $r8, $noreg, ![[LHS]], !DIExpression(DW_OP_LLVM_fragment, 64, 64)
12+
; CHECK-NEXT: DBG_VALUE $r9, $noreg, ![[LHS]], !DIExpression(DW_OP_LLVM_fragment, 128, 64)
13+
; CHECK-NEXT: DBG_VALUE %fixed-stack.{{.+}}, ![[LHS]], !DIExpression(DW_OP_LLVM_fragment, 192, 64)
14+
; The duplicates should be removed:
15+
; CHECK-NOT: DBG_VALUE
16+
17+
entry:
18+
%9 = alloca i64, align 8
19+
call void @llvm.dbg.value(metadata i64 %3, metadata !24, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 64)), !dbg !67
20+
call void @llvm.dbg.value(metadata i64 %4, metadata !24, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 64)), !dbg !67
21+
call void @llvm.dbg.value(metadata i64 %3, metadata !24, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 64)), !dbg !67
22+
call void @llvm.dbg.value(metadata i64 %4, metadata !24, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 64)), !dbg !67
23+
call void @llvm.dbg.value(metadata i64 %5, metadata !24, metadata !DIExpression(DW_OP_LLVM_fragment, 128, 64)), !dbg !67
24+
call void @llvm.dbg.value(metadata i64 %6, metadata !24, metadata !DIExpression(DW_OP_LLVM_fragment, 192, 64)), !dbg !67
25+
br i1 poison, label %11, label %10, !dbg !68
26+
27+
10: ; preds = %entry
28+
tail call void asm sideeffect "", "n"(i32 7) #7
29+
unreachable
30+
31+
11: ; preds = %entry
32+
tail call void @abort()
33+
unreachable
34+
}
35+
36+
declare void @abort()
37+
38+
declare void @llvm.dbg.value(metadata, metadata, metadata)
39+
40+
attributes #7 = { nounwind }
41+
42+
!llvm.dbg.cu = !{!0}
43+
!llvm.module.flags = !{!13}
44+
!llvm.linker.options = !{!14, !15}
45+
46+
!0 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !1, producer: "Swift", isOptimized: true, runtimeVersion: 6, emissionKind: FullDebug)
47+
!1 = !DIFile(filename: "Int128.swift", directory: "")
48+
!13 = !{i32 2, !"Debug Info Version", i32 3}
49+
!14 = !{!"-lswiftCore"}
50+
!15 = !{!"-lobjc"}
51+
!16 = distinct !DISubprogram(name: "_wideDivide42", scope: !0, file: !1, line: 222, type: !17, scopeLine: 222, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !23)
52+
!17 = !DISubroutineType(types: !18)
53+
!18 = !{!19, !20, !20, !20, !20, !20, !20}
54+
!19 = !DICompositeType(tag: DW_TAG_structure_type, name: "4 x UInt64", flags: DIFlagFwdDecl, runtimeLang: DW_LANG_Swift)
55+
!20 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "UInt64", scope: !1, file: !1, size: 64, elements: !22, runtimeLang: DW_LANG_Swift)
56+
!22 = !{}
57+
!23 = !{!24, !27}
58+
!24 = !DILocalVariable(name: "lhs", arg: 1, scope: !16, file: !1, line: 223, type: !25, flags: DIFlagArtificial)
59+
!25 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !26)
60+
!26 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "2 x 2 x UInt64", file: !1, size: 256, elements: !22, runtimeLang: DW_LANG_Swift)
61+
!27 = !DILocalVariable(name: "rhs", arg: 2, scope: !16, file: !1, line: 223, type: !28, flags: DIFlagArtificial)
62+
!28 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !29)
63+
!29 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "2 x UInt64", file: !1, size: 128, elements: !22, runtimeLang: DW_LANG_Swift)
64+
!67 = !DILocation(line: 0, scope: !16)
65+
!68 = !DILocation(line: 225, column: 9, scope: !16)

0 commit comments

Comments
 (0)