From 417195eef5d019d3ca4f26ab7f04063a8a6fdfce Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Sat, 21 Mar 2015 05:29:17 +0100 Subject: ortho_llvm: fix new_alloca when first instruction of a basic block. --- src/ortho/llvm/ortho_llvm.adb | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ortho/llvm/ortho_llvm.adb b/src/ortho/llvm/ortho_llvm.adb index be0c60f7c..a1c85dbe1 100644 --- a/src/ortho/llvm/ortho_llvm.adb +++ b/src/ortho/llvm/ortho_llvm.adb @@ -1670,11 +1670,25 @@ package body Ortho_LLVM is and then Cur_Declare_Block.Prev /= null then -- Save stack pointer at entry of block - PositionBuilderBefore - (Extra_Builder, GetFirstInstruction (Cur_Declare_Block.Stmt_Bb)); - Cur_Declare_Block.Stack_Value := - BuildCall (Extra_Builder, Stacksave_Fun, - (1 .. 0 => Null_ValueRef), 0, Empty_Cstring); + declare + First_Insn : ValueRef; + Bld : BuilderRef; + begin + First_Insn := GetFirstInstruction (Cur_Declare_Block.Stmt_Bb); + if First_Insn = Null_ValueRef then + -- Alloca is the first instruction, save the stack now. + Bld := Builder; + else + -- There are instructions before alloca, insert the save + -- at the beginning. + PositionBuilderBefore (Extra_Builder, First_Insn); + Bld := Extra_Builder; + end if; + + Cur_Declare_Block.Stack_Value := + BuildCall (Bld, Stacksave_Fun, + (1 .. 0 => Null_ValueRef), 0, Empty_Cstring); + end; end if; Res := BuildArrayAlloca -- cgit v1.2.3