Adrian Prantl | 15db52b | 2013-04-23 19:56:03 +0000 | [diff] [blame] | 1 | ; RUN: opt -inline -S < %s | FileCheck %s |
| 2 | |
| 3 | ; Created from source |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 4 | ; |
| 5 | ; |
| 6 | ; 1 // test.cpp |
| 7 | ; 2 extern int global_var; |
| 8 | ; 3 extern int test_ext(int k); |
| 9 | ; 4 int test (int k) { |
| 10 | ; 5 int k2 = test_ext(k); |
| 11 | ; 6 if (k2 > 100) |
| 12 | ; 7 return k2; |
| 13 | ; 8 return 0; |
| 14 | ; 9 } |
| 15 | ; 10 |
| 16 | ; 11 int test2() { |
| 17 | ; 12 try |
| 18 | ; 13 { |
| 19 | ; 14 test(global_var); |
| 20 | ; 15 } |
| 21 | ; 16 catch (int e) { |
| 22 | ; 17 global_var = 0; |
| 23 | ; 18 } |
| 24 | ; 19 global_var = 1; |
| 25 | ; 20 return 0; |
| 26 | ; 21 } |
Adrian Prantl | 15db52b | 2013-04-23 19:56:03 +0000 | [diff] [blame] | 27 | |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 28 | ; CHECK: _Z4testi.exit: |
Adrian Prantl | 3e1758c | 2013-04-29 22:25:52 +0000 | [diff] [blame] | 29 | ; Make sure the branch instruction created during inlining has a debug location, |
| 30 | ; so the range of the inlined function is correct. |
David Blaikie | df70628 | 2015-01-21 22:57:29 +0000 | [diff] [blame] | 31 | ; CHECK: br label %invoke.cont, !dbg [[MD:![0-9]+]] |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 32 | ; The branch instruction has the source location of line 9 and its inlined location |
| 33 | ; has the source location of line 14. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 34 | ; CHECK: [[INL:![0-9]*]] = distinct !DILocation(line: 14, scope: {{.*}}) |
| 35 | ; CHECK: [[MD]] = !DILocation(line: 9, scope: {{.*}}, inlinedAt: [[INL]]) |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 36 | |
| 37 | ; ModuleID = 'test.cpp' |
| 38 | target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" |
| 39 | target triple = "x86_64-apple-darwin12.0.0" |
Adrian Prantl | 15db52b | 2013-04-23 19:56:03 +0000 | [diff] [blame] | 40 | |
| 41 | @_ZTIi = external constant i8* |
| 42 | @global_var = external global i32 |
| 43 | |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 44 | define i32 @_Z4testi(i32 %k) !dbg !4 { |
Adrian Prantl | 15db52b | 2013-04-23 19:56:03 +0000 | [diff] [blame] | 45 | entry: |
| 46 | %retval = alloca i32, align 4 |
| 47 | %k.addr = alloca i32, align 4 |
| 48 | %k2 = alloca i32, align 4 |
| 49 | store i32 %k, i32* %k.addr, align 4 |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 50 | call void @llvm.dbg.declare(metadata i32* %k.addr, metadata !13, metadata !DIExpression()), !dbg !14 |
| 51 | call void @llvm.dbg.declare(metadata i32* %k2, metadata !15, metadata !DIExpression()), !dbg !16 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 52 | %0 = load i32, i32* %k.addr, align 4, !dbg !16 |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 53 | %call = call i32 @_Z8test_exti(i32 %0), !dbg !16 |
| 54 | store i32 %call, i32* %k2, align 4, !dbg !16 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 55 | %1 = load i32, i32* %k2, align 4, !dbg !17 |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 56 | %cmp = icmp sgt i32 %1, 100, !dbg !17 |
| 57 | br i1 %cmp, label %if.then, label %if.end, !dbg !17 |
Adrian Prantl | 15db52b | 2013-04-23 19:56:03 +0000 | [diff] [blame] | 58 | |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 59 | if.then: ; preds = %entry |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 60 | %2 = load i32, i32* %k2, align 4, !dbg !18 |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 61 | store i32 %2, i32* %retval, !dbg !18 |
| 62 | br label %return, !dbg !18 |
Adrian Prantl | 15db52b | 2013-04-23 19:56:03 +0000 | [diff] [blame] | 63 | |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 64 | if.end: ; preds = %entry |
| 65 | store i32 0, i32* %retval, !dbg !19 |
| 66 | br label %return, !dbg !19 |
Adrian Prantl | 15db52b | 2013-04-23 19:56:03 +0000 | [diff] [blame] | 67 | |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 68 | return: ; preds = %if.end, %if.then |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 69 | %3 = load i32, i32* %retval, !dbg !20 |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 70 | ret i32 %3, !dbg !20 |
| 71 | } |
| 72 | |
| 73 | ; Function Attrs: nounwind readnone |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 74 | declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 75 | |
| 76 | declare i32 @_Z8test_exti(i32) |
| 77 | |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 78 | define i32 @_Z5test2v() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !dbg !10 { |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 79 | entry: |
| 80 | %exn.slot = alloca i8* |
| 81 | %ehselector.slot = alloca i32 |
| 82 | %e = alloca i32, align 4 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 83 | %0 = load i32, i32* @global_var, align 4, !dbg !21 |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 84 | %call = invoke i32 @_Z4testi(i32 %0) |
| 85 | to label %invoke.cont unwind label %lpad, !dbg !21 |
| 86 | |
| 87 | invoke.cont: ; preds = %entry |
| 88 | br label %try.cont, !dbg !23 |
| 89 | |
| 90 | lpad: ; preds = %entry |
David Majnemer | 7fddecc | 2015-06-17 20:52:32 +0000 | [diff] [blame] | 91 | %1 = landingpad { i8*, i32 } |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 92 | catch i8* bitcast (i8** @_ZTIi to i8*), !dbg !21 |
| 93 | %2 = extractvalue { i8*, i32 } %1, 0, !dbg !21 |
| 94 | store i8* %2, i8** %exn.slot, !dbg !21 |
| 95 | %3 = extractvalue { i8*, i32 } %1, 1, !dbg !21 |
| 96 | store i32 %3, i32* %ehselector.slot, !dbg !21 |
| 97 | br label %catch.dispatch, !dbg !21 |
| 98 | |
| 99 | catch.dispatch: ; preds = %lpad |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 100 | %sel = load i32, i32* %ehselector.slot, !dbg !23 |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 101 | %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #2, !dbg !23 |
| 102 | %matches = icmp eq i32 %sel, %4, !dbg !23 |
| 103 | br i1 %matches, label %catch, label %eh.resume, !dbg !23 |
| 104 | |
| 105 | catch: ; preds = %catch.dispatch |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 106 | call void @llvm.dbg.declare(metadata i32* %e, metadata !24, metadata !DIExpression()), !dbg !25 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 107 | %exn = load i8*, i8** %exn.slot, !dbg !23 |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 108 | %5 = call i8* @__cxa_begin_catch(i8* %exn) #2, !dbg !23 |
| 109 | %6 = bitcast i8* %5 to i32*, !dbg !23 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 110 | %7 = load i32, i32* %6, align 4, !dbg !23 |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 111 | store i32 %7, i32* %e, align 4, !dbg !23 |
| 112 | store i32 0, i32* @global_var, align 4, !dbg !26 |
| 113 | call void @__cxa_end_catch() #2, !dbg !28 |
| 114 | br label %try.cont, !dbg !28 |
| 115 | |
| 116 | try.cont: ; preds = %catch, %invoke.cont |
| 117 | store i32 1, i32* @global_var, align 4, !dbg !29 |
| 118 | ret i32 0, !dbg !30 |
| 119 | |
| 120 | eh.resume: ; preds = %catch.dispatch |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 121 | %exn1 = load i8*, i8** %exn.slot, !dbg !23 |
| 122 | %sel2 = load i32, i32* %ehselector.slot, !dbg !23 |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 123 | %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn1, 0, !dbg !23 |
| 124 | %lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %sel2, 1, !dbg !23 |
| 125 | resume { i8*, i32 } %lpad.val3, !dbg !23 |
Adrian Prantl | 15db52b | 2013-04-23 19:56:03 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | declare i32 @__gxx_personality_v0(...) |
| 129 | |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 130 | ; Function Attrs: nounwind readnone |
| 131 | declare i32 @llvm.eh.typeid.for(i8*) #1 |
Adrian Prantl | 15db52b | 2013-04-23 19:56:03 +0000 | [diff] [blame] | 132 | |
| 133 | declare i8* @__cxa_begin_catch(i8*) |
| 134 | |
| 135 | declare void @__cxa_end_catch() |
| 136 | |
Adrian Prantl | 1d5f8f9 | 2013-04-24 01:44:15 +0000 | [diff] [blame] | 137 | attributes #1 = { nounwind readnone } |
| 138 | attributes #2 = { nounwind } |
Adrian Prantl | 15db52b | 2013-04-23 19:56:03 +0000 | [diff] [blame] | 139 | |
| 140 | !llvm.dbg.cu = !{!0} |
Manman Ren | 409558f | 2013-11-22 21:49:45 +0000 | [diff] [blame] | 141 | !llvm.module.flags = !{!31} |
Adrian Prantl | 15db52b | 2013-04-23 19:56:03 +0000 | [diff] [blame] | 142 | |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 143 | !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.3 ", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 144 | !1 = !DIFile(filename: "<unknown>", directory: "") |
Duncan P. N. Exon Smith | 988a7f8 | 2015-03-27 20:46:33 +0000 | [diff] [blame] | 145 | !2 = !{} |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 146 | !4 = distinct !DISubprogram(name: "test", linkageName: "_Z4testi", line: 4, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 4, file: !5, scope: !6, type: !7, variables: !2) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 147 | !5 = !DIFile(filename: "test.cpp", directory: "") |
| 148 | !6 = !DIFile(filename: "test.cpp", directory: "") |
| 149 | !7 = !DISubroutineType(types: !8) |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 150 | !8 = !{!9, !9} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 151 | !9 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 152 | !10 = distinct !DISubprogram(name: "test2", linkageName: "_Z5test2v", line: 11, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 11, file: !5, scope: !6, type: !11, variables: !2) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 153 | !11 = !DISubroutineType(types: !12) |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 154 | !12 = !{!9} |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 155 | !13 = !DILocalVariable(name: "k", line: 4, arg: 1, scope: !4, file: !6, type: !9) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 156 | !14 = !DILocation(line: 4, scope: !4) |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 157 | !15 = !DILocalVariable(name: "k2", line: 5, scope: !4, file: !6, type: !9) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 158 | !16 = !DILocation(line: 5, scope: !4) |
| 159 | !17 = !DILocation(line: 6, scope: !4) |
| 160 | !18 = !DILocation(line: 7, scope: !4) |
| 161 | !19 = !DILocation(line: 8, scope: !4) |
| 162 | !20 = !DILocation(line: 9, scope: !4) |
| 163 | !21 = !DILocation(line: 14, scope: !22) |
| 164 | !22 = distinct !DILexicalBlock(line: 13, column: 0, file: !5, scope: !10) |
| 165 | !23 = !DILocation(line: 15, scope: !22) |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 166 | !24 = !DILocalVariable(name: "e", line: 16, scope: !10, file: !6, type: !9) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 167 | !25 = !DILocation(line: 16, scope: !10) |
| 168 | !26 = !DILocation(line: 17, scope: !27) |
| 169 | !27 = distinct !DILexicalBlock(line: 16, column: 0, file: !5, scope: !10) |
| 170 | !28 = !DILocation(line: 18, scope: !27) |
| 171 | !29 = !DILocation(line: 19, scope: !10) |
| 172 | !30 = !DILocation(line: 20, scope: !10) |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 173 | !31 = !{i32 1, !"Debug Info Version", i32 3} |