~ chicken-core (chicken-5) eefcc20fe757e73dd27009814953c28137983dab


commit eefcc20fe757e73dd27009814953c28137983dab
Author:     Peter Bex <peter@more-magic.net>
AuthorDate: Sat Sep 24 11:41:41 2016 +0200
Commit:     Evan Hanson <evhan@foldling.org>
CommitDate: Mon Sep 26 21:30:21 2016 +1300

    Copy temp arg values back into argvector on loop
    
    This would prevent the procedure from starting from scratch after GC.
    With this change, we continue the calculation, as it should be.
    
    Fixes #1317
    
    Signed-off-by: Evan Hanson <evhan@foldling.org>

diff --git a/NEWS b/NEWS
index c7210dd5..d27b9973 100644
--- a/NEWS
+++ b/NEWS
@@ -55,6 +55,9 @@
 
 4.11.2
 
+- Compiler:
+  - Fixed incorrect argvector restoration after GC in directly
+    recursive functions (#1317).
 
 4.11.1
 
diff --git a/c-backend.scm b/c-backend.scm
index e3958c25..c4cd6b37 100644
--- a/c-backend.scm
+++ b/c-backend.scm
@@ -866,6 +866,11 @@
 			(else
 			 (gen #\{)))))
 	   (cond ((and (not (eq? 'toplevel id)) (not direct))
+		  (when (and looping (not customizable))
+		    ;; Loop will update t_n copy of av[n]; refresh av.
+		    (do ((i 0 (add1 i)))
+			((>= i n))
+		      (gen #t "av[" i "]=t" i ";")))
 		  (cond (rest
 			 (gen #t "C_save_and_reclaim((void*)" id ",c,av);}"
 			      #t "a=C_alloc((c-" n ")*C_SIZEOF_PAIR+" demand ");")
@@ -880,7 +885,7 @@
 				(apply gen arglist)
 				(gen ");}"))
 			       (else
-				(gen "C_save_and_reclaim((void *)" id #\, n ",av);}")))
+				(gen #t "C_save_and_reclaim((void *)" id #\, n ",av);}")))
 			 (when (> demand 0)
 			   (gen #t "a=C_alloc(" demand ");")))))
 		 (else (gen #\})))
Trap