Home | History | Annotate | Download | only in Generic
      1 ; RUN: opt < %s -always-inline -S | FileCheck %s
      2 ;
      3 ; Generated from the following C++ source with:
      4 ; clang -cc1 -disable-llvm-optzns -emit-llvm -g -stack-protector 2 test.cpp
      5 ;
      6 ; /* BEGIN SOURCE */
      7 ; int __attribute__((always_inline)) foo()
      8 ; {
      9 ;    int arr[10];
     10 ;    arr[0] = 5;
     11 ;    int sum = 4;
     12 ;    return sum;
     13 ; }
     14 ; 
     15 ; extern void bar();
     16 ; 
     17 ; int main()
     18 ; {
     19 ;   bar();
     20 ;   int i = foo();
     21 ;   return i;
     22 ; }
     23 ; /* END SOURCE */
     24 
     25 ; The patch that includes this test case, is addressing the following issue:
     26 ; 
     27 ; When functions are inlined, instructions without debug information 
     28 ; are attributed with the call site's DebugLoc. After inlining, inlined static
     29 ; allocas are moved to the caller's entry block, adjacent to the caller's original
     30 ; static alloca instructions. By retaining the call site's DebugLoc, these instructions
     31 ; may cause instructions that are subsequently inserted at the entry block to pick
     32 ; up the same DebugLoc.
     33 ;
     34 ; In the offending case stack protection inserts an instruction at the caller's
     35 ; entry block, which inadvertently picks up the inlined call's DebugLoc, because
     36 ; the entry block's first instruction is the recently moved inlined alloca instruction. 
     37 ;
     38 ; The stack protection instruction then becomes part of the function prologue, with the
     39 ; result that the line number that is associated with the stack protection instruction
     40 ; is deemed to be the end of the function prologue. Since this line number is the
     41 ; call site's line number, setting a breakpoint at the function in the debugger
     42 ; will make the user stop at the line of the inlined call.
     43 
     44 ; Note that without the stack protection instruction this effect would not occur
     45 ; because the allocas all get collapsed into a single instruction that reserves
     46 ; stack space and have no further influence on the prologue's line number information.
     47 
     48 
     49 ; The selected solution is to not attribute static allocas with the call site's
     50 ; DebugLoc. 
     51 
     52 ; At some point in the future, it may be desirable to describe the inlining 
     53 ; in the alloca instructions, but then the code that handles prologues must
     54 ; be able to handle this correctly, including the late insertion of instructions
     55 ; into it.
     56 
     57 ; In this context it is also important to distingush between functions
     58 ; with the "nodebug" attribute and those without it. Alloca instructions from
     59 ; nodebug functions should continue to have no DebugLoc, whereas those from
     60 ; non-nodebug functions (i.e. functions with debug information) may want to
     61 ; have their DebugLocs augmented with inlining information.
     62 
     63 
     64 ; Make sure that after inlining the call to foo() the alloca instructions for
     65 ; arr.i and sum.i do not retain debug information.
     66 
     67 ; CHECK: %arr.i = alloca [10 x i32], align {{[0-9]*$}}
     68 ; CHECK: %sum.i = alloca i32, align {{[0-9]*$}}
     69 
     70 
     71 ; ModuleID = 'test.cpp'
     72 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
     73 target triple = "x86_64-unknown-linux-gnu"
     74 
     75 ; Function Attrs: alwaysinline nounwind sspstrong
     76 define i32 @_Z3foov() #0 {
     77 entry:
     78   %arr = alloca [10 x i32], align 16
     79   %sum = alloca i32, align 4
     80   call void @llvm.dbg.declare(metadata [10 x i32]* %arr, metadata !14), !dbg !18
     81   %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %arr, i32 0, i64 0, !dbg !19
     82   store i32 5, i32* %arrayidx, align 4, !dbg !19
     83   call void @llvm.dbg.declare(metadata i32* %sum, metadata !20), !dbg !21
     84   store i32 4, i32* %sum, align 4, !dbg !21
     85   %0 = load i32, i32* %sum, align 4, !dbg !22
     86   ret i32 %0, !dbg !22
     87 }
     88 
     89 ; Function Attrs: nounwind readnone
     90 declare void @llvm.dbg.declare(metadata, metadata) #1
     91 
     92 ; Function Attrs: nounwind sspstrong
     93 define i32 @main() #2 {
     94 entry:
     95   %retval = alloca i32, align 4
     96   %i = alloca i32, align 4
     97   store i32 0, i32* %retval
     98   call void @_Z3barv(), !dbg !23
     99   call void @llvm.dbg.declare(metadata i32* %i, metadata !24), !dbg !25
    100   %call = call i32 @_Z3foov(), !dbg !25
    101   store i32 %call, i32* %i, align 4, !dbg !25
    102   %0 = load i32, i32* %i, align 4, !dbg !26
    103   ret i32 %0, !dbg !26
    104 }
    105 
    106 declare void @_Z3barv() #3
    107 
    108 attributes #0 = { alwaysinline nounwind sspstrong "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
    109 attributes #1 = { nounwind readnone }
    110 attributes #2 = { nounwind sspstrong "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
    111 attributes #3 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
    112 
    113 !llvm.dbg.cu = !{!0}
    114 !llvm.module.flags = !{!11, !12}
    115 !llvm.ident = !{!13}
    116 
    117 !0 = !{i32 786449, !1, i32 4, !"clang version 3.6.0 (217844)", i1 false, !"", i32 0, !2, !2, !3, !2, !2, !"", i32 1} ; [ DW_TAG_compile_unit ] [/home/user/test/<stdin>] [DW_LANG_C_plus_plus]
    118 !1 = !{!"<stdin>", !"/home/user/test"}
    119 !2 = !{}
    120 !3 = !{!4, !10}
    121 !4 = !{i32 786478, !5, !6, !"foo", !"foo", !"_Z3foov", i32 1, !7, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @_Z3foov, null, null, !2, i32 2} ; [ DW_TAG_subprogram ] [line 1] [def] [scope 2] [foo]
    122 !5 = !{!"test.cpp", !"/home/user/test"}
    123 !6 = !{i32 786473, !5}          ; [ DW_TAG_file_type ] [/home/user/test/test.cpp]
    124 !7 = !{i32 786453, i32 0, null, !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, !8, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
    125 !8 = !{!9}
    126 !9 = !{i32 786468, null, null, !"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]
    127 !10 = !{i32 786478, !5, !6, !"main", !"main", !"", i32 11, !7, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @main, null, null, !2, i32 12} ; [ DW_TAG_subprogram ] [line 11] [def] [scope 12] [main]
    128 !11 = !{i32 2, !"Dwarf Version", i32 4}
    129 !12 = !{i32 2, !"Debug Info Version", i32 1}
    130 !13 = !{!"clang version 3.6.0 (217844)"}
    131 !14 = !{i32 786688, !4, !"arr", !6, i32 3, !15, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [arr] [line 3]
    132 !15 = !{i32 786433, null, null, !"", i32 0, i64 320, i64 32, i32 0, i32 0, !9, !16, i32 0, null, null, null} ; [ DW_TAG_array_type ] [line 0, size 320, align 32, offset 0] [from int]
    133 !16 = !{!17}
    134 !17 = !{i32 786465, i64 0, i64 10}       ; [ DW_TAG_subrange_type ] [0, 9]
    135 !18 = !DILocation(line: 3, scope: !4)
    136 !19 = !DILocation(line: 4, scope: !4)
    137 !20 = !{i32 786688, !4, !"sum", !6, i32 5, !9, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [sum] [line 5]
    138 !21 = !DILocation(line: 5, scope: !4)
    139 !22 = !DILocation(line: 6, scope: !4)
    140 !23 = !DILocation(line: 13, scope: !10)
    141 !24 = !{i32 786688, !10, !"i", !6, i32 14, !9, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [i] [line 14]
    142 !25 = !DILocation(line: 14, scope: !10)
    143 !26 = !DILocation(line: 15, scope: !10)
    144