Browse Source

* AArch64: overflow checking for abs
* tabs adapted: also abs(longint) must overflow check on 64 bit platforms

florian 1 year ago
parent
commit
20f9b82543
2 changed files with 11 additions and 7 deletions
  1. 11 1
      compiler/aarch64/ncpuinl.pas
  2. 0 6
      tests/test/units/system/tabs.pp

+ 11 - 1
compiler/aarch64/ncpuinl.pas

@@ -61,7 +61,7 @@ implementation
     uses
     uses
       globtype,verbose,globals,
       globtype,verbose,globals,
       compinnr,
       compinnr,
-      cpuinfo, defutil,symdef,aasmdata,aasmcpu,
+      cpuinfo, defutil,symdef,aasmbase,aasmdata,aasmcpu,
       cgbase,cgutils,pass_1,pass_2,
       cgbase,cgutils,pass_1,pass_2,
       procinfo,
       procinfo,
       ncal,nutils,
       ncal,nutils,
@@ -183,6 +183,7 @@ implementation
     procedure taarch64inlinenode.second_abs_long;
     procedure taarch64inlinenode.second_abs_long;
       var
       var
         opsize : tcgsize;
         opsize : tcgsize;
+        hl: TAsmLabel;
       begin
       begin
         secondpass(left);
         secondpass(left);
         opsize:=def_cgsize(left.resultdef);
         opsize:=def_cgsize(left.resultdef);
@@ -190,6 +191,15 @@ implementation
         location:=left.location;
         location:=left.location;
         location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
         location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
 
 
+        if cs_check_overflow in current_settings.localswitches then
+          begin
+            current_asmdata.getjumplabel(hl);
+            hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,resultdef,OC_NE,torddef(resultdef).low.svalue,left.location.register,hl);
+            hlcg.a_reg_dealloc(current_asmdata.CurrAsmList, NR_DEFAULTFLAGS);
+            hlcg.g_call_system_proc(current_asmdata.CurrAsmList,'fpc_overflow',[],nil).resetiftemp;
+            hlcg.a_label(current_asmdata.CurrAsmList,hl);
+          end;
+
         current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_NEG,location.register,left.location.register),PF_S));
         current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_NEG,location.register,left.location.register),PF_S));
         current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg_cond(A_CSEL,location.register,location.register,left.location.register,C_GE));
         current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg_cond(A_CSEL,location.register,location.register,left.location.register,C_GE));
       end;
       end;

+ 0 - 6
tests/test/units/system/tabs.pp

@@ -167,8 +167,6 @@ procedure fail;
     except
     except
       on EIntOverflow do
       on EIntOverflow do
         ; // no error, result is -2147483648
         ; // no error, result is -2147483648
-      on ERangeError do
-        ; // no error, result is -2147483648
       on Exception do
       on Exception do
         _result := false;
         _result := false;
     end;
     end;
@@ -256,8 +254,6 @@ procedure fail;
    { test overflow checking }
    { test overflow checking }
 {$PUSH}
 {$PUSH}
 {$Q+}
 {$Q+}
-{ allow also range check errors as 64 bit CPUs might have only an abs(<int64>) }
-{$R+}
     value := Longint.MinValue+Random(0);
     value := Longint.MinValue+Random(0);
     try
     try
       value := Abs(value);
       value := Abs(value);
@@ -265,8 +261,6 @@ procedure fail;
     except
     except
       on EIntOverflow do
       on EIntOverflow do
         ; // no error, result is -2147483648
         ; // no error, result is -2147483648
-      on ERangeError do
-        ; // no error, result is -2147483648
       on Exception do
       on Exception do
         _result := false;
         _result := false;
     end;
     end;