Index: ncal.pas
===================================================================
--- ncal.pas	(revision 9857)
+++ ncal.pas	(working copy)
@@ -71,6 +71,7 @@
           procedure order_parameters;
           procedure check_inlining;
           function  pass1_normal:tnode;
+          function  check_params(targetsym: tsym): boolean;
 
           { inlining support }
           inlinelocals            : TFPObjectList;
@@ -1653,6 +1654,28 @@
         result:=vmttree;
       end;
 
+function tcallnode.check_params(targetsym: tsym): boolean;
+var
+  hp, hp2: tnode;
+begin
+  result := false;
+  hp := left;
+  while assigned(hp) and (hp.nodetype = callparan) do
+  begin
+    if hp.resultdef = resultdef then
+    begin
+      hp2 := tcallparanode(hp).left;
+      if (hp2.nodetype = loadn) and
+         (tloadnode(hp2).symtableentry = targetsym) and
+         (tcallparanode(hp).parasym.varspez <> vs_value) and
+  { allow optimization for copy(), etc. that handle arguments in a known way }
+         (symtableproc <> systemunit) then
+        Exit;
+    end;
+    hp := tcallparanode(hp).right;
+  end;
+  result := true;
+end;
 
     procedure tcallnode.maybe_create_funcret_node;
       var
@@ -1709,6 +1732,8 @@
                 ) or
                 (
                  (realassignmenttarget.nodetype=loadn) and
+                 { check that assignment target is not passed as function argument }
+                 check_params(tloadnode(realassignmenttarget).symtableentry) and
                  { nested procedures may access the current procedure's locals }
                  (procdefinition.parast.symtablelevel=normal_function_level) and
                  { must be a local variable, a value para or a hidden function result }
