Explorar o código

* Fixed the parentfp optimization for some cases when nested procvars are used.

git-svn-id: trunk@45664 -
yury %!s(int64=5) %!d(string=hai) anos
pai
achega
c15b6f4516
Modificáronse 3 ficheiros con 37 adicións e 0 borrados
  1. 1 0
      .gitattributes
  2. 3 0
      compiler/nld.pas
  3. 33 0
      tests/test/tnest3.pp

+ 1 - 0
.gitattributes

@@ -15228,6 +15228,7 @@ tests/test/tmt1.pp svneol=native#text/plain
 tests/test/tmul1.pp svneol=native#text/pascal
 tests/test/tnest1.pp svneol=native#text/plain
 tests/test/tnest2.pp svneol=native#text/plain
+tests/test/tnest3.pp svneol=native#text/plain
 tests/test/tnoext1.pp svneol=native#text/plain
 tests/test/tnoext2.pp svneol=native#text/plain
 tests/test/tnoext3.pp svneol=native#text/plain

+ 3 - 0
compiler/nld.pas

@@ -389,6 +389,9 @@ implementation
                  that the address needs to be returned }
                resultdef:=fprocdef;
 
+               if is_nested_pd(fprocdef) and is_nested_pd(current_procinfo.procdef) then
+                 current_procinfo.set_needs_parentfp(tprocdef(fprocdef.owner.defowner).parast.symtablelevel);
+
                { process methodpointer/framepointer }
                if assigned(left) then
                  begin

+ 33 - 0
tests/test/tnest3.pp

@@ -0,0 +1,33 @@
+{$mode objfpc}
+{$modeswitch nestedprocvars}
+
+type
+  tnestedfunc = function (i: longint): longint is nested;
+
+function test: longint;
+var
+  i: longint;
+
+  function func3(aa: longint): longint;
+  begin
+    result:=i+aa;
+  end;
+
+  function func(aa: integer): integer;
+  var
+    nf: tnestedfunc;
+  begin
+    nf:=@func3;
+    result:=nf(aa);
+  end;
+
+begin
+  i:=100;
+  result:=func(10);
+end;
+
+begin
+  if test <> 110 then
+    halt(1);
+  writeln('OK');
+end.