@@ -211,21 +211,43 @@ let unreachable =
211211
212212(* Block creation *)
213213
214+ let static_atom_table = symbol " caml_atom_table"
215+
216+ let static_atom ?(dbg =Debuginfo. none) tag =
217+ if tag = 0 then
218+ static_atom_table
219+ else
220+ Cmm. Cop (Cmm. Caddv , [static_atom_table;
221+ int ~dbg (tag * Arch. size_addr)], dbg)
222+
223+ let make_alloc_safe ?(dbg =Debuginfo. none) tag = function
224+ | [] -> static_atom ~dbg tag
225+ | args -> make_alloc dbg tag args
226+
227+ let make_float_alloc_safe ?(dbg =Debuginfo. none) tag = function
228+ | [] -> static_atom ~dbg tag
229+ | args -> make_float_alloc dbg tag args
230+
214231let make_block ?(dbg =Debuginfo. none) kind args =
215232 match (kind : Flambda_primitive.make_block_kind ) with
216233 | Full_of_values (tag , _ ) ->
217- make_alloc dbg (Tag.Scannable. to_int tag) args
234+ make_alloc_safe ~ dbg (Tag.Scannable. to_int tag) args
218235 | Full_of_naked_floats
219236 | Generic_array Full_of_naked_floats ->
220- make_float_alloc dbg (Tag. to_int Tag. double_array_tag) args
237+ make_float_alloc_safe ~ dbg (Tag. to_int Tag. double_array_tag) args
221238 | Generic_array No_specialisation ->
222- extcall ~dbg ~alloc: true
223- " caml_make_array" Cmm. typ_val
224- [make_alloc dbg 0 args]
239+ begin match args with
240+ | [] -> static_atom ~dbg 0
241+ | _ ->
242+ extcall ~dbg ~alloc: true
243+ " caml_make_array" Cmm. typ_val
244+ [make_alloc dbg 0 args]
245+ end
225246 | _ ->
226- make_alloc dbg 0 args
247+ make_alloc_safe ~ dbg 0 args
227248
228249let make_closure_block ?(dbg =Debuginfo. none) l =
250+ assert (List. compare_length_with l 0 > 0 );
229251 let tag = Tag. (to_int closure_tag) in
230252 make_alloc dbg tag l
231253
0 commit comments