diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2015-11-09 17:03:47 +0100 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 2015-11-09 17:03:47 +0100 |
commit | 35e3f39bf967c4ed2ba3390b488604554306065d (patch) | |
tree | 6ec4f40aab63e818693786145de937ef7a2870eb /cfrontend/C2C.ml | |
parent | e79e6fe5e4da4cf4c9852456f5ad82e633551cc9 (diff) | |
download | compcert-35e3f39bf967c4ed2ba3390b488604554306065d.tar.gz compcert-35e3f39bf967c4ed2ba3390b488604554306065d.zip |
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.
Diffstat (limited to 'cfrontend/C2C.ml')
-rw-r--r-- | cfrontend/C2C.ml | 10 |
1 files changed, 5 insertions, 5 deletions
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 |