brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.6 KiB · 13bbdc4 Raw
143 lines · plain
1; RUN: opt < %s -passes=always-inline -S | FileCheck %s2;3; Generated from the following C++ source with:4; clang -cc1 -disable-llvm-optzns -emit-llvm -g -stack-protector 2 test.cpp5;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 information28; are attributed with the call site's DebugLoc. After inlining, inlined static29; allocas are moved to the caller's entry block, adjacent to the caller's original30; static alloca instructions. By retaining the call site's DebugLoc, these instructions31; may cause instructions that are subsequently inserted at the entry block to pick32; up the same DebugLoc.33;34; In the offending case stack protection inserts an instruction at the caller's35; entry block, which inadvertently picks up the inlined call's DebugLoc, because36; 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 the39; result that the line number that is associated with the stack protection instruction40; is deemed to be the end of the function prologue. Since this line number is the41; call site's line number, setting a breakpoint at the function in the debugger42; 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 occur45; because the allocas all get collapsed into a single instruction that reserves46; 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's50; DebugLoc.51 52; At some point in the future, it may be desirable to describe the inlining53; in the alloca instructions, but then the code that handles prologues must54; be able to handle this correctly, including the late insertion of instructions55; into it.56 57; In this context it is also important to distingush between functions58; with the "nodebug" attribute and those without it. Alloca instructions from59; nodebug functions should continue to have no DebugLoc, whereas those from60; non-nodebug functions (i.e. functions with debug information) may want to61; have their DebugLocs augmented with inlining information.62 63 64; Make sure that after inlining the call to foo() the alloca instructions for65; 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'72target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"73target triple = "x86_64-unknown-linux-gnu"74 75; Function Attrs: alwaysinline nounwind sspstrong76define i32 @_Z3foov() #0 {77entry:78  %arr = alloca [10 x i32], align 1679  %sum = alloca i32, align 480  call void @llvm.dbg.declare(metadata ptr %arr, metadata !14), !dbg !1881  store i32 5, ptr %arr, align 4, !dbg !1982  call void @llvm.dbg.declare(metadata ptr %sum, metadata !20), !dbg !2183  store i32 4, ptr %sum, align 4, !dbg !2184  %0 = load i32, ptr %sum, align 4, !dbg !2285  ret i32 %0, !dbg !2286}87 88; Function Attrs: nounwind readnone89declare void @llvm.dbg.declare(metadata, metadata) #190 91; Function Attrs: nounwind sspstrong92define i32 @main() #2 {93entry:94  %retval = alloca i32, align 495  %i = alloca i32, align 496  store i32 0, ptr %retval97  call void @_Z3barv(), !dbg !2398  call void @llvm.dbg.declare(metadata ptr %i, metadata !24), !dbg !2599  %call = call i32 @_Z3foov(), !dbg !25100  store i32 %call, ptr %i, align 4, !dbg !25101  %0 = load i32, ptr %i, align 4, !dbg !26102  ret i32 %0, !dbg !26103}104 105declare void @_Z3barv() #3106 107attributes #0 = { alwaysinline nounwind sspstrong "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "use-soft-float"="false" }108attributes #1 = { nounwind readnone }109attributes #2 = { nounwind sspstrong "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "use-soft-float"="false" }110attributes #3 = { "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "use-soft-float"="false" }111 112!llvm.dbg.cu = !{!0}113!llvm.module.flags = !{!11, !12}114!llvm.ident = !{!13}115 116!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]117!1 = !{!"<stdin>", !"/home/user/test"}118!2 = !{}119!3 = !{!4, !10}120!4 = !{i32 786478, !5, !6, !"foo", !"foo", !"_Z3foov", i32 1, !7, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, ptr @_Z3foov, null, null, !2, i32 2} ; [ DW_TAG_subprogram ] [line 1] [def] [scope 2] [foo]121!5 = !{!"test.cpp", !"/home/user/test"}122!6 = !{i32 786473, !5}          ; [ DW_TAG_file_type ] [/home/user/test/test.cpp]123!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 ]124!8 = !{!9}125!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]126!10 = !{i32 786478, !5, !6, !"main", !"main", !"", i32 11, !7, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, ptr @main, null, null, !2, i32 12} ; [ DW_TAG_subprogram ] [line 11] [def] [scope 12] [main]127!11 = !{i32 2, !"Dwarf Version", i32 4}128!12 = !{i32 2, !"Debug Info Version", i32 1}129!13 = !{!"clang version 3.6.0 (217844)"}130!14 = !{i32 786688, !4, !"arr", !6, i32 3, !15, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [arr] [line 3]131!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]132!16 = !{!17}133!17 = !{i32 786465, i64 0, i64 10}       ; [ DW_TAG_subrange_type ] [0, 9]134!18 = !DILocation(line: 3, scope: !4)135!19 = !DILocation(line: 4, scope: !4)136!20 = !{i32 786688, !4, !"sum", !6, i32 5, !9, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [sum] [line 5]137!21 = !DILocation(line: 5, scope: !4)138!22 = !DILocation(line: 6, scope: !4)139!23 = !DILocation(line: 13, scope: !10)140!24 = !{i32 786688, !10, !"i", !6, i32 14, !9, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [i] [line 14]141!25 = !DILocation(line: 14, scope: !10)142!26 = !DILocation(line: 15, scope: !10)143