mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-07 01:48:00 +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/tw16700.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/tw1696.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1699.pp svneol=native#text/plain
|
||||
|
@ -394,8 +394,6 @@ implementation
|
||||
else
|
||||
{$endif not cpu64bitalu}
|
||||
cg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,location.size,1,location.register);
|
||||
|
||||
cg.g_rangecheck(current_asmdata.CurrAsmList,location,resultdef,resultdef);
|
||||
end;
|
||||
|
||||
|
||||
|
@ -2661,6 +2661,50 @@ implementation
|
||||
in_succ_x:
|
||||
begin
|
||||
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;
|
||||
|
||||
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