From 5defdf86ba8de0f0de26bd1be7a8885bb2f0e3eb Mon Sep 17 00:00:00 2001
From: florian <florian@freepascal.org>
Date: Fri, 30 Dec 2011 10:54:08 +0000
Subject: [PATCH] * handle for-loops correctly if the limits contain the
 counter variable

git-svn-id: trunk@19918 -
---
 compiler/optdfa.pas | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/compiler/optdfa.pas b/compiler/optdfa.pas
index cfedccca16..28f2f6fd46 100644
--- a/compiler/optdfa.pas
+++ b/compiler/optdfa.pas
@@ -276,7 +276,7 @@ unit optdfa;
                     foreachnodestatic(pm_postprocess,twhilerepeatnode(node).left,@AddDefUse,@dfainfo);
                   end;
 
-                { NB: this node should typically have empty def set }                  
+                { NB: this node should typically have empty def set }
                 if assigned(node.successor) then
                   DFASetDiff(l,node.successor.optinfo^.life,node.optinfo^.def)
                 else if assigned(resultnode) then
@@ -344,10 +344,14 @@ unit optdfa;
                 { update for node }
                 { life:=life+use+body }
                 l:=copy(node.optinfo^.life);
-                DFASetIncludeSet(l,node.optinfo^.use);
                 DFASetIncludeSet(l,tfornode(node).t2.optinfo^.life);
                 { the for loop always updates its control variable }
                 DFASetDiff(l,l,node.optinfo^.def);
+
+                { ... but it could be that left/right use it, so do it after
+                  removing def }
+                DFASetIncludeSet(l,node.optinfo^.use);
+
                 UpdateLifeInfo(node,l);
 
                 { ... and a second iteration for fast convergence }