llvm.org GIT mirror llvm / e8654da
[DebugInfo][Dexter] Speculated BB presents illegal variable value to debugger. When SimplifyCFG changes the PHI node into a select instruction, the debug information becomes ambiguous. It causes the debugger to display wrong variable value. Differential Revision: https://reviews.llvm.org/D51976 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342527 91177308-0d34-0410-b5e6-96231b3b80d8 Carlos Alberto Enciso 1 year, 9 months ago
4 changed file(s) with 119 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
442442 void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N,
443443 LoadInst &NewLI);
444444
445 /// Remove the debug intrinsic instructions for the given instruction.
446 void dropDebugUsers(Instruction &I);
447
445448 //===----------------------------------------------------------------------===//
446449 // Intrinsic pattern matching
447450 //
25212521 }
25222522 }
25232523
2524 void llvm::dropDebugUsers(Instruction &I) {
2525 SmallVector DbgUsers;
2526 findDbgUsers(DbgUsers, &I);
2527 for (auto *DII : DbgUsers)
2528 DII->eraseFromParent();
2529 }
2530
25242531 namespace {
25252532
25262533 /// A potential constituent of a bitreverse or bswap expression. See
23692369 // Move all 'aggressive' instructions, which are defined in the
23702370 // conditional parts of the if's up to the dominating block.
23712371 if (IfBlock1) {
2372 for (auto &I : *IfBlock1)
2372 for (auto &I : *IfBlock1) {
23732373 I.dropUnknownNonDebugMetadata();
2374 dropDebugUsers(I);
2375 }
23742376 DomBlock->getInstList().splice(InsertPt->getIterator(),
23752377 IfBlock1->getInstList(), IfBlock1->begin(),
23762378 IfBlock1->getTerminator()->getIterator());
23772379 }
23782380 if (IfBlock2) {
2379 for (auto &I : *IfBlock2)
2381 for (auto &I : *IfBlock2) {
23802382 I.dropUnknownNonDebugMetadata();
2383 dropDebugUsers(I);
2384 }
23812385 DomBlock->getInstList().splice(InsertPt->getIterator(),
23822386 IfBlock2->getInstList(), IfBlock2->begin(),
23832387 IfBlock2->getTerminator()->getIterator());
0 ; RUN: opt < %s -S -simplifycfg | FileCheck %s
1
2 ; When SimplifyCFG changes the PHI node into a select instruction, the debug
3 ; information becomes ambiguous. It causes the debugger to display wrong
4 ; variable value.
5 ;
6 ; When in the debugger, on the line "if (read == 4)", the value of "result"
7 ; is reported as '2', where it should be zero.
8
9 ; IR generated with:
10 ; clang -S -g -O2 -emit-llvm pr38763.cpp -o pr38763.ll -mllvm -opt-bisect-limit=10
11
12 ; // pr38763.cpp
13 ; int main() {
14 ; volatile int foo = 4;
15 ; int read = foo;
16 ; int read1 = foo;
17 ;
18 ; int result = 0;
19 ; if (read == 4) {
20 ; result = read1 + 2;
21 ; } else {
22 ; result = read1 - 2;
23 ; }
24 ;
25 ; return result;
26 ; }
27
28 ; Remove the '@llvm.dbg.value' associated with 'result' for the true/false
29 ; branches, as they becomes ambiguous.
30
31 ; CHECK-LABEL: entry
32 ; CHECK: %cmp = icmp eq i32 %foo.0., 4
33 ; CHECK: %add = add nsw i32 %foo.0.4, 2, !dbg !18
34 ; CHECK-NOT: @llvm.dbg.value(metadata i32 %add
35 ; CHECK: %sub = add nsw i32 %foo.0.4, -2, !dbg !21
36 ; CHECK-NOT: @llvm.dbg.value(metadata i32 %sub
37 ; CHECK: %result.0 = select i1 %cmp, i32 %add, i32 %sub
38 ; CHECK: call void @llvm.dbg.value(metadata i32 %result.0, metadata !12, metadata !DIExpression()), !dbg !17
39
40 ; ModuleID = 'pr38763.cpp'
41 source_filename = "pr38763.cpp"
42 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
43 target triple = "x86_64-pc-linux-gnu"
44
45 ; Function Attrs: norecurse nounwind uwtable
46 define dso_local i32 @main() local_unnamed_addr #0 !dbg !7 {
47 entry:
48 %foo = alloca i32, align 4
49 %foo.0..sroa_cast = bitcast i32* %foo to i8*
50 store volatile i32 4, i32* %foo, align 4, !tbaa !19
51 %foo.0. = load volatile i32, i32* %foo, align 4
52 %foo.0.4 = load volatile i32, i32* %foo, align 4
53 call void @llvm.dbg.value(metadata i32 0, metadata !16, metadata !DIExpression()), !dbg !27
54 %cmp = icmp eq i32 %foo.0., 4
55 br i1 %cmp, label %if.then, label %if.else
56
57 if.then: ; preds = %entry
58 %add = add nsw i32 %foo.0.4, 2, !dbg !31
59 call void @llvm.dbg.value(metadata i32 %add, metadata !16, metadata !DIExpression()), !dbg !27
60 br label %if.end
61
62 if.else: ; preds = %entry
63 %sub = add nsw i32 %foo.0.4, -2, !dbg !34
64 call void @llvm.dbg.value(metadata i32 %sub, metadata !16, metadata !DIExpression()), !dbg !27
65 br label %if.end
66
67 if.end: ; preds = %if.else, %if.then
68 %result.0 = phi i32 [ %add, %if.then ], [ %sub, %if.else ]
69 call void @llvm.dbg.value(metadata i32 %result.0, metadata !16, metadata !DIExpression()), !dbg !27
70 ret i32 %result.0
71 }
72
73 ; Function Attrs: nounwind readnone speculatable
74 declare void @llvm.dbg.value(metadata, metadata, metadata) #2
75
76 !llvm.dbg.cu = !{!0}
77 !llvm.module.flags = !{!3, !4, !5}
78 !llvm.ident = !{!6}
79
80 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.0 (trunk 342209)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
81 !1 = !DIFile(filename: "pr38763.cpp", directory: ".")
82 !2 = !{}
83 !3 = !{i32 2, !"Dwarf Version", i32 4}
84 !4 = !{i32 2, !"Debug Info Version", i32 3}
85 !5 = !{i32 1, !"wchar_size", i32 4}
86 !6 = !{!"clang version 8.0.0 (trunk 342209)"}
87 !7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !11)
88 !8 = !DISubroutineType(types: !9)
89 !9 = !{!10}
90 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
91 !11 = !{!16}
92 !16 = !DILocalVariable(name: "result", scope: !7, file: !1, line: 6, type: !10)
93 !19 = !{!20, !20, i64 0}
94 !20 = !{!"int", !21, i64 0}
95 !21 = !{!"omnipotent char", !22, i64 0}
96 !22 = !{!"Simple C++ TBAA"}
97 !27 = !DILocation(line: 6, column: 7, scope: !7)
98 !29 = distinct !DILexicalBlock(scope: !7, file: !1, line: 7, column: 7)
99 !31 = !DILocation(line: 8, column: 20, scope: !32)
100 !32 = distinct !DILexicalBlock(scope: !29, file: !1, line: 7, column: 18)
101 !34 = !DILocation(line: 10, column: 20, scope: !35)
102 !35 = distinct !DILexicalBlock(scope: !29, file: !1, line: 9, column: 10)