From 35e3f39bf967c4ed2ba3390b488604554306065d Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Mon, 9 Nov 2015 17:03:47 +0100 Subject: Handle large static initializers for global arrays Use tail-recursive operations to implement transformations on initializers for global arrays. This way, very large static initializers no longer cause stack overflows at compile-time. --- cfrontend/C2C.ml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'cfrontend/C2C.ml') diff --git a/cfrontend/C2C.ml b/cfrontend/C2C.ml index 6b3426b2..8c7ec6d8 100644 --- a/cfrontend/C2C.ml +++ b/cfrontend/C2C.ml @@ -1108,16 +1108,16 @@ let rec convertInit env init = | C.Init_single e -> Init_single (convertExpr env e) | C.Init_array il -> - Init_array (convertInitList env il) + Init_array (convertInitList env (List.rev il) Init_nil) | C.Init_struct(_, flds) -> - Init_struct (convertInitList env (List.map snd flds)) + Init_struct (convertInitList env (List.rev_map snd flds) Init_nil) | C.Init_union(_, fld, i) -> Init_union (intern_string fld.fld_name, convertInit env i) -and convertInitList env il = +and convertInitList env il accu = match il with - | [] -> Init_nil - | i :: il' -> Init_cons(convertInit env i, convertInitList env il') + | [] -> accu + | i :: il' -> convertInitList env il' (Init_cons(convertInit env i, accu)) let convertInitializer env ty i = match Initializers.transl_init -- cgit