Browse Source

* Pass NR_FUNCTION_RESULT_REG to FPC_SAFECALLCHECK in target-independent way.
* Added missing call to paramanager.freecgpara.
* Handle safecall stuff after deallocating registers of the main call in order to keep allocations balanced.

git-svn-id: trunk@21021 -

sergei 13 years ago
parent
commit
13e513fdf7
1 changed files with 11 additions and 14 deletions
  1. 11 14
      compiler/ncgcal.pas

+ 11 - 14
compiler/ncgcal.pas

@@ -646,9 +646,9 @@ implementation
 {$ifdef vtentry}
         sym : tasmsymbol;
 {$endif vtentry}
-{$ifdef x86_64}
+{$if defined(x86) or defined(arm)}
         cgpara : tcgpara;
-{$endif x86_64}
+{$endif}
       begin
          if not assigned(procdefinition) or
             not(procdefinition.has_paraloc_info in [callerside,callbothsides]) then
@@ -907,28 +907,25 @@ implementation
                end;
            end;
 
+         if cg.uses_registers(R_MMREGISTER) then
+           cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
+         if cg.uses_registers(R_FPUREGISTER) then
+           cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
+         cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
+
 {$if defined(x86) or defined(arm)}
          if (procdefinition.proccalloption=pocall_safecall) and
             (tf_safecall_exceptions in target_info.flags) then
            begin
-{$ifdef x86_64}
              cgpara.init;
              paramanager.getintparaloc(pocall_default,1,cgpara);
-             cg.a_load_reg_cgpara(current_asmdata.CurrAsmList,OS_ADDR,NR_RAX,cgpara);
+             cg.a_load_reg_cgpara(current_asmdata.CurrAsmList,OS_INT,NR_FUNCTION_RESULT_REG,cgpara);
+             paramanager.freecgpara(current_asmdata.CurrAsmList,cgpara);
              cgpara.done;
-{$endif x86_64}
-             cg.allocallcpuregisters(current_asmdata.CurrAsmList);
-             cg.a_call_name(current_asmdata.CurrAsmList,'FPC_SAFECALLCHECK',false);
-             cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
+             cg.g_call(current_asmdata.CurrAsmList,'FPC_SAFECALLCHECK');
            end;
 {$endif}
 
-         if cg.uses_registers(R_MMREGISTER) then
-           cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
-         if cg.uses_registers(R_FPUREGISTER) then
-           cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
-         cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
-
          { handle function results }
          if (not is_void(resultdef)) then
            handle_return_value