101 lines · plain
1; RUN: opt < %s -S -passes=simplifycfg | FileCheck %s2 3; When SimplifyCFG changes the PHI node into a select instruction, the debug4; information becomes ambiguous. It causes the debugger to display wrong5; variable value.6;7; When in the debugger, on the line "if (read == 4)", the value of "result"8; is reported as '2', where it should be zero.9 10; IR generated with:11; clang -S -g -O2 -emit-llvm pr38763.cpp -o pr38763.ll -mllvm -opt-bisect-limit=1012 13; // pr38763.cpp14; int main() {15; volatile int foo = 4;16; int read = foo;17; int read1 = foo;18;19; int result = 0;20; if (read == 4) {21; result = read1 + 2;22; } else {23; result = read1 - 2;24; }25;26; return result;27; }28 29; Remove the '@llvm.dbg.value' associated with 'result' for the true/false30; branches, as they becomes ambiguous.31 32; CHECK-LABEL: entry33; CHECK: %cmp = icmp eq i32 %foo.0., 4, !dbg !1434; CHECK: %add = add nsw i32 %foo.0.4, 2, !dbg !1635; CHECK-NOT: #dbg_value(i32 %add36; CHECK: %sub = add nsw i32 %foo.0.4, -2, !dbg !1637; CHECK-NOT: #dbg_value(i32 %sub38; CHECK: %result.0 = select i1 %cmp, i32 %add, i32 %sub39; CHECK: #dbg_value(i32 %result.0, !12, !DIExpression(), !1340 41; ModuleID = 'pr38763.cpp'42source_filename = "pr38763.cpp"43target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"44target triple = "x86_64-pc-linux-gnu"45 46; Function Attrs: norecurse nounwind uwtable47define dso_local i32 @main() local_unnamed_addr #0 !dbg !7 {48entry:49 %foo = alloca i32, align 450 store volatile i32 4, ptr %foo, align 451 %foo.0. = load volatile i32, ptr %foo, align 452 %foo.0.4 = load volatile i32, ptr %foo, align 453 call void @llvm.dbg.value(metadata i32 0, metadata !16, metadata !DIExpression()), !dbg !2754 %cmp = icmp eq i32 %foo.0., 4, !dbg !2855 br i1 %cmp, label %if.then, label %if.else, !dbg !3056 57if.then: ; preds = %entry58 %add = add nsw i32 %foo.0.4, 2, !dbg !3159 call void @llvm.dbg.value(metadata i32 %add, metadata !16, metadata !DIExpression()), !dbg !2760 br label %if.end61 62if.else: ; preds = %entry63 %sub = add nsw i32 %foo.0.4, -2, !dbg !3464 call void @llvm.dbg.value(metadata i32 %sub, metadata !16, metadata !DIExpression()), !dbg !2765 br label %if.end66 67if.end: ; preds = %if.else, %if.then68 %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 !2770 ret i32 %result.071}72 73; Function Attrs: nounwind readnone speculatable74declare void @llvm.dbg.value(metadata, metadata, metadata) #275 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!27 = !DILocation(line: 6, column: 7, scope: !7)94!28 = !DILocation(line: 7, column: 12, scope: !29)95!29 = distinct !DILexicalBlock(scope: !7, file: !1, line: 7, column: 7)96!30 = !DILocation(line: 7, column: 7, scope: !7)97!31 = !DILocation(line: 8, column: 20, scope: !32)98!32 = distinct !DILexicalBlock(scope: !29, file: !1, line: 7, column: 18)99!34 = !DILocation(line: 10, column: 20, scope: !35)100!35 = distinct !DILexicalBlock(scope: !29, file: !1, line: 9, column: 10)101