Vedant Kumar | b0585893c | 2018-04-17 22:03:08 +0000 | [diff] [blame] | 1 | ; RUN: opt -S < %s -mem2reg -verify | FileCheck %s |
| 2 | |
| 3 | target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" |
| 4 | target triple = "x86_64-apple-macosx10.13.0" |
| 5 | |
| 6 | ; Original source (with some whitespace removed): |
| 7 | ; |
| 8 | ; extern int *getp(); |
| 9 | ; extern int cond(); |
| 10 | ; int get1() { return *getp(); } |
| 11 | ; int get2(int *p) { return *p; } |
| 12 | ; int bug(int *p) { |
| 13 | ; if (cond()) return get1(); |
| 14 | ; else return get2(p); |
| 15 | ; } |
| 16 | |
| 17 | define i32 @get1() !dbg !8 { |
| 18 | %1 = call i32* (...) @getp(), !dbg !12 |
| 19 | %2 = load i32, i32* %1, align 4, !dbg !13 |
| 20 | ret i32 %2, !dbg !14 |
| 21 | } |
| 22 | |
| 23 | declare i32* @getp(...) |
| 24 | |
| 25 | define i32 @get2(i32*) !dbg !15 { |
| 26 | %2 = alloca i32*, align 8 |
| 27 | store i32* %0, i32** %2, align 8 |
| 28 | call void @llvm.dbg.declare(metadata i32** %2, metadata !19, metadata !DIExpression()), !dbg !20 |
| 29 | %3 = load i32*, i32** %2, align 8, !dbg !21 |
| 30 | %4 = load i32, i32* %3, align 4, !dbg !22 |
| 31 | ret i32 %4, !dbg !23 |
| 32 | } |
| 33 | |
| 34 | declare void @llvm.dbg.declare(metadata, metadata, metadata) |
| 35 | |
| 36 | ; CHECK-LABEL: define i32 @bug |
| 37 | define i32 @bug(i32*) !dbg !24 { |
| 38 | %2 = alloca i32, align 4 |
| 39 | %3 = alloca i32*, align 8 |
| 40 | store i32* %0, i32** %3, align 8 |
| 41 | call void @llvm.dbg.declare(metadata i32** %3, metadata !25, metadata !DIExpression()), !dbg !26 |
| 42 | %4 = call i32 (...) @cond(), !dbg !27 |
| 43 | %5 = icmp ne i32 %4, 0, !dbg !27 |
| 44 | br i1 %5, label %6, label %8, !dbg !29 |
| 45 | |
| 46 | ; <label>:6: ; preds = %1 |
| 47 | %7 = call i32 @get1(), !dbg !30 |
| 48 | store i32 %7, i32* %2, align 4, !dbg !31 |
| 49 | br label %11, !dbg !31 |
| 50 | |
| 51 | ; <label>:8: ; preds = %1 |
| 52 | %9 = load i32*, i32** %3, align 8, !dbg !32 |
| 53 | %10 = call i32 @get2(i32* %9), !dbg !33 |
| 54 | store i32 %10, i32* %2, align 4, !dbg !34 |
| 55 | br label %11, !dbg !34 |
| 56 | |
| 57 | ; <label>:11: ; preds = %8, %6 |
| 58 | %12 = load i32, i32* %2, align 4, !dbg !35 |
| 59 | ret i32 %12, !dbg !35 |
| 60 | |
| 61 | ; CHECK: [[phi:%.*]] = phi i32 [ {{.*}} ], [ {{.*}} ], !dbg [[mergedLoc:![0-9]+]] |
| 62 | ; CHECK-NEXT: ret i32 [[phi]], !dbg [[retLoc:![0-9]+]] |
| 63 | } |
| 64 | |
| 65 | ; CHECK: [[commonScope:![0-9]+]] = distinct !DILexicalBlock(scope: {{.*}}, file: !1, line: 15, column: 7) |
| 66 | ; CHECK: [[mergedLoc]] = !DILocation(line: 0, scope: [[commonScope]]) |
| 67 | ; CHECK: [[retLoc]] = !DILocation(line: 23, column: 1 |
| 68 | |
| 69 | declare i32 @cond(...) |
| 70 | |
| 71 | !llvm.dbg.cu = !{!0} |
| 72 | !llvm.module.flags = !{!3, !4, !5, !6} |
| 73 | !llvm.ident = !{!7} |
| 74 | |
| 75 | !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Apple LLVM version 9.1.0 (clang-902.2.37.2)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) |
| 76 | !1 = !DIFile(filename: "bug.c", directory: "/bug") |
| 77 | !2 = !{} |
| 78 | !3 = !{i32 2, !"Dwarf Version", i32 4} |
| 79 | !4 = !{i32 2, !"Debug Info Version", i32 3} |
| 80 | !5 = !{i32 1, !"wchar_size", i32 4} |
| 81 | !6 = !{i32 7, !"PIC Level", i32 2} |
| 82 | !7 = !{!"Apple LLVM version 9.1.0 (clang-902.2.37.2)"} |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 83 | !8 = distinct !DISubprogram(name: "get1", scope: !1, file: !1, line: 6, type: !9, isLocal: false, isDefinition: true, scopeLine: 6, isOptimized: false, unit: !0, retainedNodes: !2) |
Vedant Kumar | b0585893c | 2018-04-17 22:03:08 +0000 | [diff] [blame] | 84 | !9 = !DISubroutineType(types: !10) |
| 85 | !10 = !{!11} |
| 86 | !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) |
| 87 | !12 = !DILocation(line: 7, column: 11, scope: !8) |
| 88 | !13 = !DILocation(line: 7, column: 10, scope: !8) |
| 89 | !14 = !DILocation(line: 7, column: 3, scope: !8) |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 90 | !15 = distinct !DISubprogram(name: "get2", scope: !1, file: !1, line: 10, type: !16, isLocal: false, isDefinition: true, scopeLine: 10, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2) |
Vedant Kumar | b0585893c | 2018-04-17 22:03:08 +0000 | [diff] [blame] | 91 | !16 = !DISubroutineType(types: !17) |
| 92 | !17 = !{!11, !18} |
| 93 | !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64) |
| 94 | !19 = !DILocalVariable(name: "p", arg: 1, scope: !15, file: !1, line: 10, type: !18) |
| 95 | !20 = !DILocation(line: 10, column: 15, scope: !15) |
| 96 | !21 = !DILocation(line: 11, column: 11, scope: !15) |
| 97 | !22 = !DILocation(line: 11, column: 10, scope: !15) |
| 98 | !23 = !DILocation(line: 11, column: 3, scope: !15) |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 99 | !24 = distinct !DISubprogram(name: "bug", scope: !1, file: !1, line: 14, type: !16, isLocal: false, isDefinition: true, scopeLine: 14, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2) |
Vedant Kumar | b0585893c | 2018-04-17 22:03:08 +0000 | [diff] [blame] | 100 | !25 = !DILocalVariable(name: "p", arg: 1, scope: !24, file: !1, line: 14, type: !18) |
| 101 | !26 = !DILocation(line: 14, column: 14, scope: !24) |
| 102 | !27 = !DILocation(line: 15, column: 7, scope: !28) |
| 103 | !28 = distinct !DILexicalBlock(scope: !24, file: !1, line: 15, column: 7) |
| 104 | !29 = !DILocation(line: 15, column: 7, scope: !24) |
| 105 | !30 = !DILocation(line: 16, column: 12, scope: !28) |
| 106 | !31 = !DILocation(line: 16, column: 5, scope: !28) |
| 107 | !32 = !DILocation(line: 18, column: 17, scope: !28) |
| 108 | !33 = !DILocation(line: 18, column: 12, scope: !28) |
| 109 | !34 = !DILocation(line: 18, column: 5, scope: !28) |
| 110 | !35 = !DILocation(line: 23, column: 1, scope: !24) |