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

* adjusted test

git-svn-id: trunk@44012 -
This commit is contained in:
svenbarth 2020-01-21 21:30:10 +00:00
parent 4fc02d3d09
commit 9a42625cfb
2 changed files with 23 additions and 1 deletions

View File

@ -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);

View File

@ -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.