Hi all,

Sven Hartrumpf reported a problem with the generated C code being
invalid in some cases.  I haven't been able to come up with a proper
test case and don't expect to have a lot of time to work on this the
coming weeks, so I wanted to post this patch already.

Sven confirmed that this patch fixes the issue.  His code now compiles
and also works as expected.

I think the solution is a bit hacky, but I don't know of a better way
to do this.  Suggestions welcome!

Cheers,
Peter
From 8b20b9adffa556b18d1a8a805754094ffe53ea77 Mon Sep 17 00:00:00 2001
From: Peter Bex <pe...@more-magic.net>
Date: Fri, 17 Jan 2020 11:30:31 +0100
Subject: [PATCH] Fix C codegen issue of assigning a call to void function

Instead of allowing the "result" of C_rest_arg_out_of_bounds_error
to be assigned to a variable, we add a macro that returns undefined
to make the C compiler happy.
---
 chicken.h   | 1 +
 support.scm | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/chicken.h b/chicken.h
index a46c2428..de3d8bfe 100644
--- a/chicken.h
+++ b/chicken.h
@@ -1246,6 +1246,7 @@ typedef void (C_ccall *C_proc)(C_word, C_word *) C_noret;
 #define C_do_apply(c, av)               ((C_proc)(void *)C_block_item((av)[0], 0))((c), (av))
 #define C_kontinue(k, r)                do { C_word avk[ 2 ]; avk[ 0 ] = (k); avk[ 1 ] = (r); ((C_proc)(void *)C_block_item((k),0))(2, avk); } while(0)
 #define C_get_rest_arg(c, n, av, ka, cl)((n) >= (c) ? (C_rest_arg_out_of_bounds_error_2(C_fix(c), C_fix(n), C_fix(ka), (cl)), C_SCHEME_UNDEFINED) : (av)[(n)])
+#define C_rest_arg_out_of_bounds_error_value(c, n, ka) (C_rest_arg_out_of_bounds_error((c),(n),(ka)), C_SCHEME_UNDEFINED)
 #define C_rest_nullp(c, n)              (C_mk_bool((n) >= (c)))
 #define C_fetch_byte(x, p)              (((unsigned C_byte *)C_data_pointer(x))[ p ])
 #define C_poke_integer(x, i, n)         (C_set_block_item(x, C_unfix(i), C_num_to_int(n)), C_SCHEME_UNDEFINED)
diff --git a/support.scm b/support.scm
index 48f3970d..c9f03e8e 100644
--- a/support.scm
+++ b/support.scm
@@ -760,7 +760,7 @@
 	       (if (> len depth)
 		   (copy-node! (varnode (list-ref rest-args depth)) n)
 		   (copy-node! (make-node '##core#inline
-					  (list "C_rest_arg_out_of_bounds_error")
+					  (list "C_rest_arg_out_of_bounds_error_value")
 					  (list (qnode len) (qnode depth) (qnode 0)))
 			       n)))
 	     n))
-- 
2.20.1

Attachment: signature.asc
Description: PGP signature

Reply via email to