Просмотр исходного кода

* optimize also tail calls, if it is a simple procedure

git-svn-id: trunk@25688 -
florian 11 лет назад
Родитель
Сommit
6391fd39aa
2 измененных файлов с 7 добавлено и 2 удалено
  1. 4 2
      compiler/opttail.pas
  2. 3 0
      tests/test/units/system/teststk.pp

+ 4 - 2
compiler/opttail.pas

@@ -97,10 +97,12 @@ unit opttail;
                 { avoid short bool eval here }
                 result:=find_and_replace_tailcalls(tifnode(n).t1) or result;
               end;
+            calln,
             assignn:
               begin
-                if is_resultassignment(tbinarynode(n).left) and
-                   is_recursivecall(tbinarynode(n).right) then
+                if ((n.nodetype=calln) and is_recursivecall(n)) or
+                   ((n.nodetype=assignn) and is_resultassignment(tbinarynode(n).left) and
+                   is_recursivecall(tbinarynode(n).right)) then
                   begin
                     { found one! }
                     {

+ 3 - 0
tests/test/units/system/teststk.pp

@@ -1,4 +1,7 @@
 { %RESULT=202 }
+{ %OPT=-O- }
+{ do not optimize because the code below would cause an endless loop due to tail recursion elimination }
+
 {$ifdef unix}
   {$define nocheck}
 {$endif}