Home | History | Annotate | Download | only in DebugInfo
      1 ; RUN: opt -inline -S < %s | FileCheck %s
      2 
      3 ; Created from source
      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 }
     27 
     28 ; CHECK: _Z4testi.exit:
     29 ; Make sure the branch instruction created during inlining has a debug location,
     30 ; so the range of the inlined function is correct.
     31 ; CHECK: br label %invoke.cont, !dbg ![[MD:[0-9]+]]
     32 ; The branch instruction has the source location of line 9 and its inlined location
     33 ; has the source location of line 14.
     34 ; CHECK: ![[INL:[0-9]+]] = metadata !{i32 14, i32 0, metadata {{.*}}, null}
     35 ; CHECK: ![[MD]] = metadata !{i32 9, i32 0, metadata {{.*}}, metadata ![[INL]]}
     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"
     40 
     41 @_ZTIi = external constant i8*
     42 @global_var = external global i32
     43 
     44 define i32 @_Z4testi(i32 %k)  {
     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
     50   call void @llvm.dbg.declare(metadata !{i32* %k.addr}, metadata !13), !dbg !14
     51   call void @llvm.dbg.declare(metadata !{i32* %k2}, metadata !15), !dbg !16
     52   %0 = load i32* %k.addr, align 4, !dbg !16
     53   %call = call i32 @_Z8test_exti(i32 %0), !dbg !16
     54   store i32 %call, i32* %k2, align 4, !dbg !16
     55   %1 = load i32* %k2, align 4, !dbg !17
     56   %cmp = icmp sgt i32 %1, 100, !dbg !17
     57   br i1 %cmp, label %if.then, label %if.end, !dbg !17
     58 
     59 if.then:                                          ; preds = %entry
     60   %2 = load i32* %k2, align 4, !dbg !18
     61   store i32 %2, i32* %retval, !dbg !18
     62   br label %return, !dbg !18
     63 
     64 if.end:                                           ; preds = %entry
     65   store i32 0, i32* %retval, !dbg !19
     66   br label %return, !dbg !19
     67 
     68 return:                                           ; preds = %if.end, %if.then
     69   %3 = load i32* %retval, !dbg !20
     70   ret i32 %3, !dbg !20
     71 }
     72 
     73 ; Function Attrs: nounwind readnone
     74 declare void @llvm.dbg.declare(metadata, metadata) #1
     75 
     76 declare i32 @_Z8test_exti(i32)
     77 
     78 define i32 @_Z5test2v()  {
     79 entry:
     80   %exn.slot = alloca i8*
     81   %ehselector.slot = alloca i32
     82   %e = alloca i32, align 4
     83   %0 = load i32* @global_var, align 4, !dbg !21
     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
     91   %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
     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
    100   %sel = load i32* %ehselector.slot, !dbg !23
    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
    106   call void @llvm.dbg.declare(metadata !{i32* %e}, metadata !24), !dbg !25
    107   %exn = load i8** %exn.slot, !dbg !23
    108   %5 = call i8* @__cxa_begin_catch(i8* %exn) #2, !dbg !23
    109   %6 = bitcast i8* %5 to i32*, !dbg !23
    110   %7 = load i32* %6, align 4, !dbg !23
    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
    121   %exn1 = load i8** %exn.slot, !dbg !23
    122   %sel2 = load i32* %ehselector.slot, !dbg !23
    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
    126 }
    127 
    128 declare i32 @__gxx_personality_v0(...)
    129 
    130 ; Function Attrs: nounwind readnone
    131 declare i32 @llvm.eh.typeid.for(i8*) #1
    132 
    133 declare i8* @__cxa_begin_catch(i8*)
    134 
    135 declare void @__cxa_end_catch()
    136 
    137 attributes #1 = { nounwind readnone }
    138 attributes #2 = { nounwind }
    139 
    140 !llvm.dbg.cu = !{!0}
    141 !llvm.module.flags = !{!31}
    142 
    143 !0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.3 ", i1 false, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !2, metadata !2, metadata !""} ; [ DW_TAG_compile_unit ] [<unknown>] [DW_LANG_C_plus_plus]
    144 !1 = metadata !{metadata !"<unknown>", metadata !""}
    145 !2 = metadata !{i32 0}
    146 !3 = metadata !{metadata !4, metadata !10}
    147 !4 = metadata !{i32 786478, metadata !5, metadata !6, metadata !"test", metadata !"test", metadata !"_Z4testi", i32 4, metadata !7, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 (i32)* @_Z4testi, null, null, metadata !2, i32 4} ; [ DW_TAG_subprogram ] [line 4] [def] [test]
    148 !5 = metadata !{metadata !"test.cpp", metadata !""}
    149 !6 = metadata !{i32 786473, metadata !5}          ; [ DW_TAG_file_type ] [test.cpp]
    150 !7 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !8, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
    151 !8 = metadata !{metadata !9, metadata !9}
    152 !9 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
    153 !10 = metadata !{i32 786478, metadata !5, metadata !6, metadata !"test2", metadata !"test2", metadata !"_Z5test2v", i32 11, metadata !11, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @_Z5test2v, null, null, metadata !2, i32 11} ; [ DW_TAG_subprogram ] [line 11] [def] [test2]
    154 !11 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !12, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
    155 !12 = metadata !{metadata !9}
    156 !13 = metadata !{i32 786689, metadata !4, metadata !"k", metadata !6, i32 16777220, metadata !9, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [k] [line 4]
    157 !14 = metadata !{i32 4, i32 0, metadata !4, null}
    158 !15 = metadata !{i32 786688, metadata !4, metadata !"k2", metadata !6, i32 5, metadata !9, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [k2] [line 5]
    159 !16 = metadata !{i32 5, i32 0, metadata !4, null}
    160 !17 = metadata !{i32 6, i32 0, metadata !4, null}
    161 !18 = metadata !{i32 7, i32 0, metadata !4, null}
    162 !19 = metadata !{i32 8, i32 0, metadata !4, null}
    163 !20 = metadata !{i32 9, i32 0, metadata !4, null}
    164 !21 = metadata !{i32 14, i32 0, metadata !22, null}
    165 !22 = metadata !{i32 786443, metadata !5, metadata !10, i32 13, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [test.cpp]
    166 !23 = metadata !{i32 15, i32 0, metadata !22, null}
    167 !24 = metadata !{i32 786688, metadata !10, metadata !"e", metadata !6, i32 16, metadata !9, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [e] [line 16]
    168 !25 = metadata !{i32 16, i32 0, metadata !10, null}
    169 !26 = metadata !{i32 17, i32 0, metadata !27, null}
    170 !27 = metadata !{i32 786443, metadata !5, metadata !10, i32 16, i32 0, i32 1} ; [ DW_TAG_lexical_block ] [test.cpp]
    171 !28 = metadata !{i32 18, i32 0, metadata !27, null}
    172 !29 = metadata !{i32 19, i32 0, metadata !10, null}
    173 !30 = metadata !{i32 20, i32 0, metadata !10, null}
    174 !31 = metadata !{i32 1, metadata !"Debug Info Version", i32 1}
    175