mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 05:49:23 +02:00
* more fixes (to the optimizations) for range check code generation
git-svn-id: trunk@2803 -
This commit is contained in:
parent
23fda6dc1c
commit
cb807cb2af
@ -1673,6 +1673,7 @@ implementation
|
|||||||
if (todef.deftype = arraydef) then
|
if (todef.deftype = arraydef) then
|
||||||
todef := tarraydef(todef).rangetype.def;
|
todef := tarraydef(todef).rangetype.def;
|
||||||
{ no range check if from and to are equal and are both longint/dword }
|
{ no range check if from and to are equal and are both longint/dword }
|
||||||
|
{ no range check if from and to are equal and are both longint/dword }
|
||||||
{ (if we have a 32bit processor) or int64/qword, since such }
|
{ (if we have a 32bit processor) or int64/qword, since such }
|
||||||
{ operations can at most cause overflows (JM) }
|
{ operations can at most cause overflows (JM) }
|
||||||
{ Note that these checks are mostly processor independent, they only }
|
{ Note that these checks are mostly processor independent, they only }
|
||||||
@ -1685,7 +1686,10 @@ implementation
|
|||||||
(hfrom = high(int64))) or
|
(hfrom = high(int64))) or
|
||||||
((torddef(fromdef).typ = u64bit) and
|
((torddef(fromdef).typ = u64bit) and
|
||||||
(lfrom = low(qword)) and
|
(lfrom = low(qword)) and
|
||||||
(hfrom = high(qword)))))) then
|
(hfrom = high(qword))) or
|
||||||
|
((torddef(fromdef).typ = scurrency) and
|
||||||
|
(lfrom = low(int64)) and
|
||||||
|
(hfrom = high(int64)))))) then
|
||||||
exit;
|
exit;
|
||||||
{$else cpu64bit}
|
{$else cpu64bit}
|
||||||
if (fromdef = todef) and
|
if (fromdef = todef) and
|
||||||
@ -1723,14 +1727,20 @@ implementation
|
|||||||
{$endif}
|
{$endif}
|
||||||
if to_signed then
|
if to_signed then
|
||||||
begin
|
begin
|
||||||
if (lto = (-(int64(1) << (tosize * 4)))) and
|
{ calculation of the low/high ranges must not overflow 64 bit
|
||||||
(hto = (int64(1) << (tosize * 4) - 1)) then
|
otherwise we end up comparing with zero for 64 bit data types on
|
||||||
|
64 bit processors }
|
||||||
|
if (lto = (int64(-1) << (tosize * 8 - 1))) and
|
||||||
|
(hto = (-((int64(-1) << (tosize * 8 - 1))+1))) then
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
{ calculation of the low/high ranges must not overflow 64 bit
|
||||||
|
otherwise we end up having all zeros for 64 bit data types on
|
||||||
|
64 bit processors }
|
||||||
if (lto = 0) and
|
if (lto = 0) and
|
||||||
(qword(hto) = qword((int64(1) << (tosize * 8)) - 1)) then
|
(qword(hto) = (qword(-1) >> (64-(tosize * 8))) ) then
|
||||||
exit
|
exit
|
||||||
end;
|
end;
|
||||||
{$ifdef overflowon}
|
{$ifdef overflowon}
|
||||||
|
Loading…
Reference in New Issue
Block a user