From dc5a39649116c7fd76a024d069707f8b3aa7e201 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Fri, 15 May 2020 09:43:12 +0100 Subject: Also make the letbinding C variables static I was getting run-time failures when code generate from cheri128 and cheri64 in the same process. This was caused because my compiler defaults to -fcommon so it merged multiple variables (with conflicting types!). When initializing the second set of letbindings, the first one was overwritten (first variable was lbits, the other was uint64_t). Compiling with -fno-common exposes this problem. --- src/jib/c_backend.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/jib/c_backend.ml b/src/jib/c_backend.ml index e6610e93..080be248 100644 --- a/src/jib/c_backend.ml +++ b/src/jib/c_backend.ml @@ -2127,7 +2127,8 @@ let codegen_def' ctx = function let cleanup = List.concat (List.map (fun (id, ctyp) -> [iclear ctyp (name id)]) bindings) in - separate_map hardline (fun (id, ctyp) -> string (Printf.sprintf "%s %s;" (sgen_ctyp ctyp) (sgen_id id))) bindings + let static = if !opt_static then "static " else "" in + separate_map hardline (fun (id, ctyp) -> string (Printf.sprintf "%s%s %s;" static (sgen_ctyp ctyp) (sgen_id id))) bindings ^^ hardline ^^ string (Printf.sprintf "static void create_letbind_%d(void) " number) ^^ string "{" ^^ jump 0 2 (separate_map hardline codegen_alloc setup) ^^ hardline -- cgit v1.2.3