mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-22 02:49:28 +02:00
* fixed range/overflow checking for succ/pred (mantis #16770)
git-svn-id: trunk@15474 -
This commit is contained in:
parent
138c5d1570
commit
04a63ea278
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -10508,6 +10508,7 @@ tests/webtbs/tw1658.pp svneol=native#text/plain
|
|||||||
tests/webtbs/tw16668.pp svneol=native#text/plain
|
tests/webtbs/tw16668.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw16700.pp svneol=native#text/plain
|
tests/webtbs/tw16700.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw1677.pp svneol=native#text/plain
|
tests/webtbs/tw1677.pp svneol=native#text/plain
|
||||||
|
tests/webtbs/tw16770.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw1681.pp svneol=native#text/plain
|
tests/webtbs/tw1681.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw1696.pp svneol=native#text/plain
|
tests/webtbs/tw1696.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw1699.pp svneol=native#text/plain
|
tests/webtbs/tw1699.pp svneol=native#text/plain
|
||||||
|
@ -394,8 +394,6 @@ implementation
|
|||||||
else
|
else
|
||||||
{$endif not cpu64bitalu}
|
{$endif not cpu64bitalu}
|
||||||
cg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,location.size,1,location.register);
|
cg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,location.size,1,location.register);
|
||||||
|
|
||||||
cg.g_rangecheck(current_asmdata.CurrAsmList,location,resultdef,resultdef);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -2661,6 +2661,50 @@ implementation
|
|||||||
in_succ_x:
|
in_succ_x:
|
||||||
begin
|
begin
|
||||||
expectloc:=LOC_REGISTER;
|
expectloc:=LOC_REGISTER;
|
||||||
|
{ in case of range/overflow checking, use a regular addnode
|
||||||
|
because it's too complex to handle correctly otherwise }
|
||||||
|
if ([cs_check_overflow,cs_check_range]*current_settings.localswitches)<>[] then
|
||||||
|
begin
|
||||||
|
{ create constant 1 }
|
||||||
|
hp:=cordconstnode.create(1,left.resultdef,false);
|
||||||
|
typecheckpass(hp);
|
||||||
|
if not is_integer(hp.resultdef) then
|
||||||
|
inserttypeconv_internal(hp,sinttype);
|
||||||
|
|
||||||
|
{ avoid type errors from the addn/subn }
|
||||||
|
if not is_integer(left.resultdef) then
|
||||||
|
inserttypeconv_internal(left,sinttype);
|
||||||
|
|
||||||
|
{ addition/substraction depending on succ/pred }
|
||||||
|
if inlinenumber=in_succ_x then
|
||||||
|
hp:=caddnode.create(addn,left,hp)
|
||||||
|
else
|
||||||
|
hp:=caddnode.create(subn,left,hp);
|
||||||
|
{ assign result of addition }
|
||||||
|
if not(is_integer(resultdef)) then
|
||||||
|
inserttypeconv(hp,torddef.create(
|
||||||
|
{$ifdef cpu64bitaddr}
|
||||||
|
s64bit,
|
||||||
|
{$else cpu64bitaddr}
|
||||||
|
s32bit,
|
||||||
|
{$endif cpu64bitaddr}
|
||||||
|
get_min_value(resultdef),
|
||||||
|
get_max_value(resultdef)))
|
||||||
|
else
|
||||||
|
inserttypeconv(hp,resultdef);
|
||||||
|
|
||||||
|
{ avoid any possible errors/warnings }
|
||||||
|
inserttypeconv_internal(hp,resultdef);
|
||||||
|
|
||||||
|
{ firstpass it }
|
||||||
|
firstpass(hp);
|
||||||
|
|
||||||
|
{ left is reused }
|
||||||
|
left:=nil;
|
||||||
|
|
||||||
|
{ return new node }
|
||||||
|
result:=hp;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
in_setlength_x,
|
in_setlength_x,
|
||||||
|
23
tests/webtbs/tw16770.pp
Normal file
23
tests/webtbs/tw16770.pp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{ %result=201 }
|
||||||
|
|
||||||
|
{$mode delphi}
|
||||||
|
{$r+}
|
||||||
|
procedure Test;
|
||||||
|
var
|
||||||
|
Count: Word;
|
||||||
|
I: Integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Count := 0;
|
||||||
|
|
||||||
|
for I := 0 to Pred(Count) do
|
||||||
|
begin
|
||||||
|
WriteLn(I);
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
test;
|
||||||
|
end.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user