Skip to content

Commit 88d34d4

Browse files
committed
[DebugInfo] Fix minor debug info bug in deleteDeadLoop
Using a DebugVariable as the set key rather than std::pair<DIVariable *, DIExpression *> ensures we don't accidently confuse multiple instances of inlined variables. Reviewed By: jryans Differential Revision: https://reviews.llvm.org/D133303
1 parent 5fe9273 commit 88d34d4

File tree

2 files changed

+105
-5
lines changed

2 files changed

+105
-5
lines changed

llvm/lib/Transforms/Utils/LoopUtils.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE,
594594
}
595595

596596
// Use a map to unique and a vector to guarantee deterministic ordering.
597-
llvm::SmallDenseSet<std::pair<DIVariable *, DIExpression *>, 4> DeadDebugSet;
597+
llvm::SmallDenseSet<DebugVariable, 4> DeadDebugSet;
598598
llvm::SmallVector<DbgVariableIntrinsic *, 4> DeadDebugInst;
599599

600600
if (ExitBlock) {
@@ -623,11 +623,8 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE,
623623
auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I);
624624
if (!DVI)
625625
continue;
626-
auto Key =
627-
DeadDebugSet.find({DVI->getVariable(), DVI->getExpression()});
628-
if (Key != DeadDebugSet.end())
626+
if (!DeadDebugSet.insert(DebugVariable(DVI)).second)
629627
continue;
630-
DeadDebugSet.insert({DVI->getVariable(), DVI->getExpression()});
631628
DeadDebugInst.push_back(DVI);
632629
}
633630

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
; RUN: opt -S %s -passes=loop-deletion | FileCheck %s
2+
3+
;; Generated from this C source:
4+
;; static int f(int p) { return p * p * 2; }
5+
;; static int zero() { return 0; }
6+
;; void fun() {
7+
;; for (int __attribute__((nodebug)) i = zero(); i < 0; ++i) {
8+
;; f(i);
9+
;; f(i + 1);
10+
;; }
11+
;; }
12+
;;
13+
;; Check that loop-deletion doesn't accidently mistake debug intrinsics for
14+
;; different inlined instances of a variable as the same variable.
15+
16+
; CHECK-LABEL: for.cond.cleanup: ; preds = %entry
17+
; CHECK-NEXT: @llvm.dbg.value({{.+}}, metadata ![[P:[0-9]+]],{{.+}}), !dbg ![[DBG1:[0-9]+]]
18+
; CHECK-NEXT: @llvm.dbg.value({{.+}}, metadata ![[P]], {{.+}}), !dbg ![[DBG2:[0-9]+]]
19+
20+
; CHECK-DAG: ![[P]] = !DILocalVariable(name: "p",
21+
; CHECK-DAG: ![[DBG1]] = !DILocation({{.+}}, inlinedAt: ![[IA1:[0-9]+]])
22+
; CHECK-DAG: ![[DBG2]] = !DILocation({{.+}}, inlinedAt: ![[IA2:[0-9]+]])
23+
; CHECK-DAG: ![[IA1]] = distinct !DILocation(line: 5,
24+
; CHECK-DAG: ![[IA2]] = distinct !DILocation(line: 6,
25+
26+
define dso_local void @fun() !dbg !9 {
27+
entry:
28+
br label %for.cond, !dbg !13
29+
30+
for.cond: ; preds = %for.inc, %entry
31+
%i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ], !dbg !15
32+
%cmp = icmp slt i32 %i.0, 0, !dbg !16
33+
br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !18
34+
35+
for.cond.cleanup: ; preds = %for.cond
36+
br label %for.end
37+
38+
for.body: ; preds = %for.cond
39+
call void @llvm.dbg.value(metadata i32 %i.0, metadata !19, metadata !DIExpression()), !dbg !25
40+
%mul.i = mul nsw i32 %i.0, %i.0, !dbg !28
41+
%mul1.i = mul nsw i32 %mul.i, 2, !dbg !29
42+
%add = add nsw i32 %i.0, 1, !dbg !30
43+
call void @llvm.dbg.value(metadata i32 %add, metadata !19, metadata !DIExpression()), !dbg !31
44+
%mul.i1 = mul nsw i32 %add, %add, !dbg !33
45+
%mul1.i2 = mul nsw i32 %mul.i1, 2, !dbg !34
46+
br label %for.inc, !dbg !35
47+
48+
for.inc: ; preds = %for.body
49+
%inc = add nsw i32 %i.0, 1, !dbg !36
50+
br label %for.cond, !dbg !37, !llvm.loop !38
51+
52+
for.end: ; preds = %for.cond.cleanup
53+
ret void, !dbg !41
54+
}
55+
56+
declare void @llvm.dbg.value(metadata, metadata, metadata)
57+
58+
!llvm.dbg.cu = !{!0}
59+
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
60+
!llvm.ident = !{!8}
61+
62+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 16.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
63+
!1 = !DIFile(filename: "test.c", directory: "/")
64+
!2 = !{i32 7, !"Dwarf Version", i32 5}
65+
!3 = !{i32 2, !"Debug Info Version", i32 3}
66+
!4 = !{i32 1, !"wchar_size", i32 4}
67+
!5 = !{i32 8, !"PIC Level", i32 2}
68+
!6 = !{i32 7, !"PIE Level", i32 2}
69+
!7 = !{i32 7, !"uwtable", i32 2}
70+
!8 = !{!"clang version 16.0.0"}
71+
!9 = distinct !DISubprogram(name: "fun", scope: !1, file: !1, line: 3, type: !10, scopeLine: 3, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12)
72+
!10 = !DISubroutineType(types: !11)
73+
!11 = !{null}
74+
!12 = !{}
75+
!13 = !DILocation(line: 4, column: 8, scope: !14)
76+
!14 = distinct !DILexicalBlock(scope: !9, file: !1, line: 4, column: 3)
77+
!15 = !DILocation(line: 4, scope: !14)
78+
!16 = !DILocation(line: 4, column: 51, scope: !17)
79+
!17 = distinct !DILexicalBlock(scope: !14, file: !1, line: 4, column: 3)
80+
!18 = !DILocation(line: 4, column: 3, scope: !14)
81+
!19 = !DILocalVariable(name: "p", arg: 1, scope: !20, file: !1, line: 1, type: !23)
82+
!20 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !21, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !24)
83+
!21 = !DISubroutineType(types: !22)
84+
!22 = !{!23, !23}
85+
!23 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
86+
!24 = !{!19}
87+
!25 = !DILocation(line: 0, scope: !20, inlinedAt: !26)
88+
!26 = distinct !DILocation(line: 5, column: 5, scope: !27)
89+
!27 = distinct !DILexicalBlock(scope: !17, file: !1, line: 4, column: 61)
90+
!28 = !DILocation(line: 1, column: 32, scope: !20, inlinedAt: !26)
91+
!29 = !DILocation(line: 1, column: 36, scope: !20, inlinedAt: !26)
92+
!30 = !DILocation(line: 6, column: 8, scope: !27)
93+
!31 = !DILocation(line: 0, scope: !20, inlinedAt: !32)
94+
!32 = distinct !DILocation(line: 6, column: 5, scope: !27)
95+
!33 = !DILocation(line: 1, column: 32, scope: !20, inlinedAt: !32)
96+
!34 = !DILocation(line: 1, column: 36, scope: !20, inlinedAt: !32)
97+
!35 = !DILocation(line: 7, column: 3, scope: !27)
98+
!36 = !DILocation(line: 4, column: 56, scope: !17)
99+
!37 = !DILocation(line: 4, column: 3, scope: !17)
100+
!38 = distinct !{!38, !18, !39, !40}
101+
!39 = !DILocation(line: 7, column: 3, scope: !14)
102+
!40 = !{!"llvm.loop.mustprogress"}
103+
!41 = !DILocation(line: 8, column: 1, scope: !9)

0 commit comments

Comments
 (0)