blob: 2bae87e8754512dae62ec95edbb08c83cec92e85 [file] [log] [blame]
Adrian Prantl09416382013-04-30 17:08:16 +00001; RUN: opt -inline -S < %s | FileCheck %s
2;
3; A hand-edited version of inline-debug-info.ll to test inlining of a
4; function with multiple returns.
5;
6; Make sure the branch instructions created during inlining has a debug location,
7; so the range of the inlined function is correct.
8; CHECK: br label %_Z4testi.exit, !dbg ![[MD:[0-9]+]]
9; CHECK: br label %_Z4testi.exit, !dbg ![[MD]]
10; CHECK: br label %invoke.cont, !dbg ![[MD]]
11; The branch instruction has the source location of line 9 and its inlined location
12; has the source location of line 14.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000013; CHECK: ![[INL:[0-9]+]] = distinct !DILocation(line: 14, scope: {{.*}})
14; CHECK: ![[MD]] = !DILocation(line: 9, scope: {{.*}}, inlinedAt: ![[INL]])
Adrian Prantl09416382013-04-30 17:08:16 +000015
16; ModuleID = 'test.cpp'
17target 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"
18target triple = "x86_64-apple-darwin12.0.0"
19
20@_ZTIi = external constant i8*
21@global_var = external global i32
22
23; copy of above function with multiple returns
Peter Collingbourned4bff302015-11-05 22:03:56 +000024define i32 @_Z4testi(i32 %k) !dbg !4 {
Adrian Prantl09416382013-04-30 17:08:16 +000025entry:
26 %retval = alloca i32, align 4
27 %k.addr = alloca i32, align 4
28 %k2 = alloca i32, align 4
29 store i32 %k, i32* %k.addr, align 4
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000030 call void @llvm.dbg.declare(metadata i32* %k.addr, metadata !13, metadata !DIExpression()), !dbg !14
31 call void @llvm.dbg.declare(metadata i32* %k2, metadata !15, metadata !DIExpression()), !dbg !16
David Blaikiea79ac142015-02-27 21:17:42 +000032 %0 = load i32, i32* %k.addr, align 4, !dbg !16
Adrian Prantl09416382013-04-30 17:08:16 +000033 %call = call i32 @_Z8test_exti(i32 %0), !dbg !16
34 store i32 %call, i32* %k2, align 4, !dbg !16
David Blaikiea79ac142015-02-27 21:17:42 +000035 %1 = load i32, i32* %k2, align 4, !dbg !17
Adrian Prantl09416382013-04-30 17:08:16 +000036 %cmp = icmp sgt i32 %1, 100, !dbg !17
37 br i1 %cmp, label %if.then, label %if.end, !dbg !17
38
39if.then: ; preds = %entry
David Blaikiea79ac142015-02-27 21:17:42 +000040 %2 = load i32, i32* %k2, align 4, !dbg !18
Adrian Prantl09416382013-04-30 17:08:16 +000041 store i32 %2, i32* %retval, !dbg !18
42 br label %return, !dbg !18
43
44if.end: ; preds = %entry
45 store i32 0, i32* %retval, !dbg !19
David Blaikiea79ac142015-02-27 21:17:42 +000046 %3 = load i32, i32* %retval, !dbg !20 ; hand-edited
Adrian Prantl09416382013-04-30 17:08:16 +000047 ret i32 %3, !dbg !20 ; hand-edited
48
49return: ; preds = %if.end, %if.then
David Blaikiea79ac142015-02-27 21:17:42 +000050 %4 = load i32, i32* %retval, !dbg !20
Adrian Prantl09416382013-04-30 17:08:16 +000051 ret i32 %4, !dbg !20
52}
53
54
55; Function Attrs: nounwind readnone
Adrian Prantl87b7eb92014-10-01 18:55:02 +000056declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
Adrian Prantl09416382013-04-30 17:08:16 +000057
58declare i32 @_Z8test_exti(i32)
59
Peter Collingbourned4bff302015-11-05 22:03:56 +000060define i32 @_Z5test2v() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !dbg !10 {
Adrian Prantl09416382013-04-30 17:08:16 +000061entry:
62 %exn.slot = alloca i8*
63 %ehselector.slot = alloca i32
64 %e = alloca i32, align 4
David Blaikiea79ac142015-02-27 21:17:42 +000065 %0 = load i32, i32* @global_var, align 4, !dbg !21
Adrian Prantl09416382013-04-30 17:08:16 +000066 %call = invoke i32 @_Z4testi(i32 %0)
67 to label %invoke.cont unwind label %lpad, !dbg !21
68
69invoke.cont: ; preds = %entry
70 br label %try.cont, !dbg !23
71
72lpad: ; preds = %entry
David Majnemer7fddecc2015-06-17 20:52:32 +000073 %1 = landingpad { i8*, i32 }
Adrian Prantl09416382013-04-30 17:08:16 +000074 catch i8* bitcast (i8** @_ZTIi to i8*), !dbg !21
75 %2 = extractvalue { i8*, i32 } %1, 0, !dbg !21
76 store i8* %2, i8** %exn.slot, !dbg !21
77 %3 = extractvalue { i8*, i32 } %1, 1, !dbg !21
78 store i32 %3, i32* %ehselector.slot, !dbg !21
79 br label %catch.dispatch, !dbg !21
80
81catch.dispatch: ; preds = %lpad
David Blaikiea79ac142015-02-27 21:17:42 +000082 %sel = load i32, i32* %ehselector.slot, !dbg !23
Adrian Prantl09416382013-04-30 17:08:16 +000083 %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #2, !dbg !23
84 %matches = icmp eq i32 %sel, %4, !dbg !23
85 br i1 %matches, label %catch, label %eh.resume, !dbg !23
86
87catch: ; preds = %catch.dispatch
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000088 call void @llvm.dbg.declare(metadata i32* %e, metadata !24, metadata !DIExpression()), !dbg !25
David Blaikiea79ac142015-02-27 21:17:42 +000089 %exn = load i8*, i8** %exn.slot, !dbg !23
Adrian Prantl09416382013-04-30 17:08:16 +000090 %5 = call i8* @__cxa_begin_catch(i8* %exn) #2, !dbg !23
91 %6 = bitcast i8* %5 to i32*, !dbg !23
David Blaikiea79ac142015-02-27 21:17:42 +000092 %7 = load i32, i32* %6, align 4, !dbg !23
Adrian Prantl09416382013-04-30 17:08:16 +000093 store i32 %7, i32* %e, align 4, !dbg !23
94 store i32 0, i32* @global_var, align 4, !dbg !26
95 call void @__cxa_end_catch() #2, !dbg !28
96 br label %try.cont, !dbg !28
97
98try.cont: ; preds = %catch, %invoke.cont
99 store i32 1, i32* @global_var, align 4, !dbg !29
100 ret i32 0, !dbg !30
101
102eh.resume: ; preds = %catch.dispatch
David Blaikiea79ac142015-02-27 21:17:42 +0000103 %exn1 = load i8*, i8** %exn.slot, !dbg !23
104 %sel2 = load i32, i32* %ehselector.slot, !dbg !23
Adrian Prantl09416382013-04-30 17:08:16 +0000105 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn1, 0, !dbg !23
106 %lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %sel2, 1, !dbg !23
107 resume { i8*, i32 } %lpad.val3, !dbg !23
108}
109
110declare i32 @__gxx_personality_v0(...)
111
112; Function Attrs: nounwind readnone
113declare i32 @llvm.eh.typeid.for(i8*) #1
114
115declare i8* @__cxa_begin_catch(i8*)
116
117declare void @__cxa_end_catch()
118
119attributes #1 = { nounwind readnone }
120attributes #2 = { nounwind }
121
122!llvm.dbg.cu = !{!0}
Manman Ren409558f2013-11-22 21:49:45 +0000123!llvm.module.flags = !{!31}
Adrian Prantl09416382013-04-30 17:08:16 +0000124
Adrian Prantl75819ae2016-04-15 15:57:41 +0000125!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 Smitha9308c42015-04-29 16:38:44 +0000126!1 = !DIFile(filename: "<unknown>", directory: "")
Duncan P. N. Exon Smith988a7f82015-03-27 20:46:33 +0000127!2 = !{}
Adrian Prantl75819ae2016-04-15 15:57:41 +0000128!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 Smitha9308c42015-04-29 16:38:44 +0000129!5 = !DIFile(filename: "test.cpp", directory: "")
130!6 = !DIFile(filename: "test.cpp", directory: "")
131!7 = !DISubroutineType(types: !8)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000132!8 = !{!9, !9}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000133!9 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
Adrian Prantl75819ae2016-04-15 15:57:41 +0000134!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 Smitha9308c42015-04-29 16:38:44 +0000135!11 = !DISubroutineType(types: !12)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000136!12 = !{!9}
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000137!13 = !DILocalVariable(name: "k", line: 4, arg: 1, scope: !4, file: !6, type: !9)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000138!14 = !DILocation(line: 4, scope: !4)
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000139!15 = !DILocalVariable(name: "k2", line: 5, scope: !4, file: !6, type: !9)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000140!16 = !DILocation(line: 5, scope: !4)
141!17 = !DILocation(line: 6, scope: !4)
142!18 = !DILocation(line: 7, scope: !4)
143!19 = !DILocation(line: 8, scope: !4)
144!20 = !DILocation(line: 9, scope: !4)
145!21 = !DILocation(line: 14, scope: !22)
146!22 = distinct !DILexicalBlock(line: 13, column: 0, file: !5, scope: !10)
147!23 = !DILocation(line: 15, scope: !22)
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000148!24 = !DILocalVariable(name: "e", line: 16, scope: !10, file: !6, type: !9)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000149!25 = !DILocation(line: 16, scope: !10)
150!26 = !DILocation(line: 17, scope: !27)
151!27 = distinct !DILexicalBlock(line: 16, column: 0, file: !5, scope: !10)
152!28 = !DILocation(line: 18, scope: !27)
153!29 = !DILocation(line: 19, scope: !10)
154!30 = !DILocation(line: 20, scope: !10)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000155!31 = !{i32 1, !"Debug Info Version", i32 3}