mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-08 02:27:56 +02:00
* AArch64: overflow checking for abs
* tabs adapted: also abs(longint) must overflow check on 64 bit platforms
This commit is contained in:
parent
1fccfd3ee1
commit
20f9b82543
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user