Browse Source

* inherit nf_write/nf_modify in tcallnode.replaceparaload also when replacing parameters

git-svn-id: trunk@22075 -
florian 13 years ago
parent
commit
5b90a02e75
3 changed files with 27 additions and 2 deletions
  1. 1 0
      .gitattributes
  2. 5 2
      compiler/ncal.pas
  3. 21 0
      tests/test/opt/tcse5.pp

+ 1 - 0
.gitattributes

@@ -10258,6 +10258,7 @@ tests/test/opt/tcse1.pp svneol=native#text/plain
 tests/test/opt/tcse2.pp svneol=native#text/plain
 tests/test/opt/tcse3.pp svneol=native#text/plain
 tests/test/opt/tcse4.pp svneol=native#text/pascal
+tests/test/opt/tcse5.pp svneol=native#text/pascal
 tests/test/opt/tdfa1.pp svneol=native#text/pascal
 tests/test/opt/tdfa2.pp svneol=native#text/pascal
 tests/test/opt/tgotoreg.pp svneol=native#text/plain

+ 5 - 2
compiler/ncal.pas

@@ -3623,8 +3623,11 @@ implementation
                     paras := tcallparanode(paras.right);
                   if assigned(paras) then
                     begin
+                      temp:=paras.left.getcopy;
+                      { inherit modification information, this is needed by the dfa/cse }
+                      temp.flags:=temp.flags+(n.flags*[nf_modify,nf_write]);
                       n.free;
-                      n := paras.left.getcopy;
+                      n:=temp;
                       typecheckpass(n);
                       result := fen_true;
                     end;
@@ -3642,7 +3645,7 @@ implementation
                   { inherit modification information, this is needed by the dfa/cse }
                   temp.flags:=temp.flags+(n.flags*[nf_modify,nf_write]);
                   n.free;
-                  n := temp;
+                  n:=temp;
                   typecheckpass(n);
                   result := fen_true;
                 end;

+ 21 - 0
tests/test/opt/tcse5.pp

@@ -0,0 +1,21 @@
+{ %OPT=-Ooautoinline -Oocse }
+{$mode objfpc}
+type
+  trec = record
+    b : byte;
+  end;
+
+procedure p(var b : byte);
+  begin
+    b:=b*2;
+  end;
+
+var
+  rec : trec;
+begin
+  rec.b:=12;
+  p(rec.b);
+  if rec.b<>24 then
+    halt(1);
+  writeln('ok');
+end.