2013-06-10 20:36:52 +00:00
; RUN: opt -inline -S < %s | FileCheck %s
; Created from source
;
;
; 1 // test.cpp
; 2 extern int global_var;
; 3 extern int test_ext(int k);
; 4 int test (int k) {
; 5 int k2 = test_ext(k);
; 6 if (k2 > 100)
; 7 return k2;
; 8 return 0;
; 9 }
; 10
; 11 int test2() {
; 12 try
; 13 {
; 14 test(global_var);
; 15 }
; 16 catch (int e) {
; 17 global_var = 0;
; 18 }
; 19 global_var = 1;
; 20 return 0;
; 21 }
; CHECK: _Z4testi.exit:
; Make sure the branch instruction created during inlining has a debug location,
; so the range of the inlined function is correct.
2015-05-27 18:44:32 +00:00
; CHECK: br label %invoke.cont, !dbg [[MD:![0-9]+]]
2013-06-10 20:36:52 +00:00
; The branch instruction has the source location of line 9 and its inlined location
; has the source location of line 14.
2015-05-27 18:44:32 +00:00
; CHECK: [[INL:![0-9]*]] = distinct !DILocation(line: 14, scope: {{.*}})
; CHECK: [[MD]] = !DILocation(line: 9, scope: {{.*}}, inlinedAt: [[INL]])
2013-06-10 20:36:52 +00:00
; ModuleID = 'test.cpp'
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"
target triple = "x86_64-apple-darwin12.0.0"
@_ZTIi = external constant i8 *
@global_var = external global i32
define i32 @_Z4testi ( i32 %k ) {
entry:
%retval = alloca i32 , align 4
%k.addr = alloca i32 , align 4
%k2 = alloca i32 , align 4
store i32 %k , i32 * %k.addr , align 4
2015-05-27 18:44:32 +00:00
call void @llvm.dbg.declare ( metadata i32 * %k.addr , metadata !13 , metadata !DIExpression ( ) ) , !dbg !14
call void @llvm.dbg.declare ( metadata i32 * %k2 , metadata !15 , metadata !DIExpression ( ) ) , !dbg !16
%0 = load i32 , i32 * %k.addr , align 4 , !dbg !16
2013-06-10 20:36:52 +00:00
%call = call i32 @_Z8test_exti ( i32 %0 ) , !dbg !16
store i32 %call , i32 * %k2 , align 4 , !dbg !16
2015-05-27 18:44:32 +00:00
%1 = load i32 , i32 * %k2 , align 4 , !dbg !17
2013-06-10 20:36:52 +00:00
%cmp = icmp sgt i32 %1 , 100 , !dbg !17
br i1 %cmp , label %if.then , label %if.end , !dbg !17
if.then: ; preds = %entry
2015-05-27 18:44:32 +00:00
%2 = load i32 , i32 * %k2 , align 4 , !dbg !18
2013-06-10 20:36:52 +00:00
store i32 %2 , i32 * %retval , !dbg !18
br label %return , !dbg !18
if.end: ; preds = %entry
store i32 0 , i32 * %retval , !dbg !19
br label %return , !dbg !19
return: ; preds = %if.end, %if.then
2015-05-27 18:44:32 +00:00
%3 = load i32 , i32 * %retval , !dbg !20
2013-06-10 20:36:52 +00:00
ret i32 %3 , !dbg !20
}
; Function Attrs: nounwind readnone
2015-01-18 16:17:27 +00:00
declare void @llvm.dbg.declare ( metadata , metadata , metadata ) #1
2013-06-10 20:36:52 +00:00
declare i32 @_Z8test_exti ( i32 )
2015-06-21 13:59:01 +00:00
define i32 @_Z5test2v ( ) personality i8 * bitcast ( i32 ( . . . ) * @__gxx_personality_v0 to i8 * ) {
2013-06-10 20:36:52 +00:00
entry:
%exn.slot = alloca i8 *
%ehselector.slot = alloca i32
%e = alloca i32 , align 4
2015-05-27 18:44:32 +00:00
%0 = load i32 , i32 * @global_var , align 4 , !dbg !21
2013-06-10 20:36:52 +00:00
%call = invoke i32 @_Z4testi ( i32 %0 )
to label %invoke.cont unwind label %lpad , !dbg !21
invoke.cont: ; preds = %entry
br label %try.cont , !dbg !23
lpad: ; preds = %entry
2015-06-21 13:59:01 +00:00
%1 = landingpad { i8 * , i32 }
2013-06-10 20:36:52 +00:00
catch i8 * bitcast ( i8 * * @_ZTIi to i8 * ) , !dbg !21
%2 = extractvalue { i8 * , i32 } %1 , 0 , !dbg !21
store i8 * %2 , i8 * * %exn.slot , !dbg !21
%3 = extractvalue { i8 * , i32 } %1 , 1 , !dbg !21
store i32 %3 , i32 * %ehselector.slot , !dbg !21
br label %catch.dispatch , !dbg !21
catch.dispatch: ; preds = %lpad
2015-05-27 18:44:32 +00:00
%sel = load i32 , i32 * %ehselector.slot , !dbg !23
2013-06-10 20:36:52 +00:00
%4 = call i32 @llvm.eh.typeid.for ( i8 * bitcast ( i8 * * @_ZTIi to i8 * ) ) #2 , !dbg !23
%matches = icmp eq i32 %sel , %4 , !dbg !23
br i1 %matches , label %catch , label %eh.resume , !dbg !23
catch: ; preds = %catch.dispatch
2015-05-27 18:44:32 +00:00
call void @llvm.dbg.declare ( metadata i32 * %e , metadata !24 , metadata !DIExpression ( ) ) , !dbg !25
%exn = load i8 * , i8 * * %exn.slot , !dbg !23
2013-06-10 20:36:52 +00:00
%5 = call i8 * @__cxa_begin_catch ( i8 * %exn ) #2 , !dbg !23
%6 = bitcast i8 * %5 to i32 * , !dbg !23
2015-05-27 18:44:32 +00:00
%7 = load i32 , i32 * %6 , align 4 , !dbg !23
2013-06-10 20:36:52 +00:00
store i32 %7 , i32 * %e , align 4 , !dbg !23
store i32 0 , i32 * @global_var , align 4 , !dbg !26
call void @__cxa_end_catch ( ) #2 , !dbg !28
br label %try.cont , !dbg !28
try.cont: ; preds = %catch, %invoke.cont
store i32 1 , i32 * @global_var , align 4 , !dbg !29
ret i32 0 , !dbg !30
eh.resume: ; preds = %catch.dispatch
2015-05-27 18:44:32 +00:00
%exn1 = load i8 * , i8 * * %exn.slot , !dbg !23
%sel2 = load i32 , i32 * %ehselector.slot , !dbg !23
2013-06-10 20:36:52 +00:00
%lpad.val = insertvalue { i8 * , i32 } undef , i8 * %exn1 , 0 , !dbg !23
%lpad.val3 = insertvalue { i8 * , i32 } %lpad.val , i32 %sel2 , 1 , !dbg !23
resume { i8 * , i32 } %lpad.val3 , !dbg !23
}
declare i32 @__gxx_personality_v0 ( . . . )
; Function Attrs: nounwind readnone
declare i32 @llvm.eh.typeid.for ( i8 * ) #1
declare i8 * @__cxa_begin_catch ( i8 * )
declare void @__cxa_end_catch ( )
attributes #1 = { nounwind readnone }
attributes #2 = { nounwind }
!llvm.dbg.cu = ! { !0 }
2013-12-22 00:04:03 +00:00
!llvm.module.flags = ! { !31 }
2013-06-10 20:36:52 +00:00
2015-05-27 18:44:32 +00:00
!0 = !DICompileUnit ( language: D W _ L A N G _ C _ p l u s _ p l u s , producer: "clang version 3.3 " , isOptimized: false , emissionKind: 0 , file: !1 , enums: !2 , retainedTypes: !2 , subprograms: !3 , globals: !2 , imports: !2 )
!1 = !DIFile ( filename: "<unknown>" , directory: "" )
!2 = ! { }
2015-01-18 16:17:27 +00:00
!3 = ! { !4 , !10 }
2015-05-27 18:44:32 +00:00
!4 = !DISubprogram ( name: "test" , linkageName: "_Z4testi" , line: 4 , isLocal: false , isDefinition: true , virtualIndex: 6 , flags: D I F l a g P r o t o t y p e d , isOptimized: false , scopeLine: 4 , file: !5 , scope: !6 , type: !7 , function: i32 ( i32 ) * @_Z4testi , variables: !2 )
!5 = !DIFile ( filename: "test.cpp" , directory: "" )
!6 = !DIFile ( filename: "test.cpp" , directory: "" )
!7 = !DISubroutineType ( types: !8 )
2015-01-18 16:17:27 +00:00
!8 = ! { !9 , !9 }
2015-05-27 18:44:32 +00:00
!9 = !DIBasicType ( tag: D W _ T A G _ b a s e _ type , name: "int" , size: 32 , align: 32 , encoding: D W _ A T E _ s i g n e d )
!10 = !DISubprogram ( name: "test2" , linkageName: "_Z5test2v" , line: 11 , isLocal: false , isDefinition: true , virtualIndex: 6 , flags: D I F l a g P r o t o t y p e d , isOptimized: false , scopeLine: 11 , file: !5 , scope: !6 , type: !11 , function: i32 ( ) * @_Z5test2v , variables: !2 )
!11 = !DISubroutineType ( types: !12 )
2015-01-18 16:17:27 +00:00
!12 = ! { !9 }
2015-05-27 18:44:32 +00:00
!13 = !DILocalVariable ( tag: D W _ T A G _ a r g _ v a r i a b l e , name: "k" , line: 4 , arg: 1 , scope: !4 , file: !6 , type: !9 )
!14 = !DILocation ( line: 4 , scope: !4 )
!15 = !DILocalVariable ( tag: D W _ T A G _ a u t o _ v a r i a b l e , name: "k2" , line: 5 , scope: !4 , file: !6 , type: !9 )
!16 = !DILocation ( line: 5 , scope: !4 )
!17 = !DILocation ( line: 6 , scope: !4 )
!18 = !DILocation ( line: 7 , scope: !4 )
!19 = !DILocation ( line: 8 , scope: !4 )
!20 = !DILocation ( line: 9 , scope: !4 )
!21 = !DILocation ( line: 14 , scope: !22 )
!22 = distinct !DILexicalBlock ( line: 13 , column: 0 , file: !5 , scope: !10 )
!23 = !DILocation ( line: 15 , scope: !22 )
!24 = !DILocalVariable ( tag: D W _ T A G _ a u t o _ v a r i a b l e , name: "e" , line: 16 , scope: !10 , file: !6 , type: !9 )
!25 = !DILocation ( line: 16 , scope: !10 )
!26 = !DILocation ( line: 17 , scope: !27 )
!27 = distinct !DILexicalBlock ( line: 16 , column: 0 , file: !5 , scope: !10 )
!28 = !DILocation ( line: 18 , scope: !27 )
!29 = !DILocation ( line: 19 , scope: !10 )
!30 = !DILocation ( line: 20 , scope: !10 )
!31 = ! { i32 1 , !"Debug Info Version" , i32 3 }