* AArch64: overflow checking for abs

* tabs adapted: also abs(longint) must overflow check on 64 bit platforms
This commit is contained in:
florian 2024-03-24 12:46:44 +01:00
parent 1fccfd3ee1
commit 20f9b82543
2 changed files with 11 additions and 7 deletions

View File

@ -61,7 +61,7 @@ implementation
uses
globtype,verbose,globals,
compinnr,
cpuinfo, defutil,symdef,aasmdata,aasmcpu,
cpuinfo, defutil,symdef,aasmbase,aasmdata,aasmcpu,
cgbase,cgutils,pass_1,pass_2,
procinfo,
ncal,nutils,
@ -183,6 +183,7 @@ implementation
procedure taarch64inlinenode.second_abs_long;
var
opsize : tcgsize;
hl: TAsmLabel;
begin
secondpass(left);
opsize:=def_cgsize(left.resultdef);
@ -190,6 +191,15 @@ implementation
location:=left.location;
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(taicpu.op_reg_reg_reg_cond(A_CSEL,location.register,location.register,left.location.register,C_GE));
end;

View File

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