* propagate constants into the header of a for loop

+ test which avoids this so we do not miss regressions on for loops with variable boundaries

git-svn-id: trunk@26339 -
This commit is contained in:
florian 2013-12-31 13:16:09 +00:00
parent b0441e1d64
commit f393c3ff37
3 changed files with 36 additions and 1 deletions

1
.gitattributes vendored
View File

@ -14370,6 +14370,7 @@ tests/webtbs/tw8847.pp svneol=native#text/plain
tests/webtbs/tw8861.pp svneol=native#text/plain
tests/webtbs/tw8870.pp svneol=native#text/plain
tests/webtbs/tw8883.pp svneol=native#text/plain
tests/webtbs/tw8883b.pp svneol=native#text/pascal
tests/webtbs/tw8919.pp svneol=native#text/plain
tests/webtbs/tw8930.pp svneol=native#text/plain
tests/webtbs/tw8935.pp svneol=native#text/plain

View File

@ -93,7 +93,7 @@ unit optconstprop;
iterate manually here so we have full controll how all nodes are processed }
{ We cannot analyze beyond those nodes, so we terminate to be on the safe side }
if (n.nodetype in [addrn,derefn,dataconstn,asmn,withn,casen,whilerepeatn,forn,labeln,continuen,breakn,
if (n.nodetype in [addrn,derefn,dataconstn,asmn,withn,casen,whilerepeatn,labeln,continuen,breakn,
tryexceptn,raisen,tryfinallyn,onn,loadparentfpn,loadvmtaddrn,guidconstn,rttin,addoptn,asn,goton,
objcselectorn,objcprotocoln]) then
exit(false)
@ -123,6 +123,15 @@ unit optconstprop;
end
else if n.nodetype=statementn then
result:=replaceBasicAssign(tstatementnode(n).left, arg, tree_modified)
else if n.nodetype=forn then
begin
result:=replaceBasicAssign(tfornode(n).right, arg, tree_modified);
if result then
replaceBasicAssign(tfornode(n).t1, arg, tree_modified2);
tree_modified:=tree_modified or tree_modified2;
{ after a for node we cannot continue with our simple approach }
result:=false;
end
else if n.nodetype=blockn then
begin
changed:=false;

25
tests/webtbs/tw8883b.pp Normal file
View File

@ -0,0 +1,25 @@
{ %OPT=-Oonoconstprop }
procedure DoTest;
var
i, j, cnt: longint;
begin
cnt:=0;
j:=1;
for i:=0 to j do
begin
Inc(cnt);
Dec(j);
end;
writeln(cnt);
if cnt <> 2 then
begin
writeln('Test failed!');
Halt(1);
end;
writeln('Test OK.');
end;
begin
dotest;
end.