浏览代码

* also allow by-value open array parameters for the tail recursion optimization
* adjusted test

git-svn-id: trunk@44012 -

svenbarth 5 年之前
父节点
当前提交
9a42625cfb
共有 2 个文件被更改,包括 23 次插入1 次删除
  1. 3 1
      compiler/opttail.pas
  2. 20 0
      tests/tbs/tb0667.pp

+ 3 - 1
compiler/opttail.pas

@@ -123,7 +123,9 @@ unit opttail;
                       begin
                         useaddr:=(paranode.parasym.varspez in [vs_var,vs_constref]) or
                           ((paranode.parasym.varspez=vs_const) and
-                          paramanager.push_addr_param(paranode.parasym.varspez,paranode.parasym.vardef,p.proccalloption));
+                          paramanager.push_addr_param(paranode.parasym.varspez,paranode.parasym.vardef,p.proccalloption)) or
+                          ((paranode.parasym.varspez=vs_value) and
+                          is_open_array(paranode.parasym.vardef));
                         if useaddr then
                           begin
                             tempnode:=ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);

+ 20 - 0
tests/tbs/tb0667.pp

@@ -56,6 +56,23 @@ begin
   Test3 := Test3(Values, 0);
 end;
 
+function Test4(Values: array of LongInt; Res: LongInt): LongInt;
+begin
+  if not Assigned(stack) then
+    stack := get_frame
+  else if stack <> get_frame then
+    Halt(7);
+  if Length(Values) = 0 then
+    Test4 := Res
+  else
+    Test4 := Test4(Values[0..High(Values) - 1], Res + Values[High(Values)]);
+end;
+
+function Test4(Values: array of LongInt): LongInt;
+begin
+  Test4 := Test4(Values, 0);
+end;
+
 begin
   if Test1([1, 2, 3, 4]) <> 10 then
     Halt(2);
@@ -65,5 +82,8 @@ begin
   stack := Nil;
   if Test3([1, 2, 3, 4]) <> 10 then
     Halt(6);
+  stack := Nil;
+  if Test4([1, 2, 3, 4]) <> 10 then
+    Halt(8);
   writeln('ok');
 end.