Skip to content

Commit f3ce1a8

Browse files
Gburylthls
authored andcommitted
Stop generating allocs of size 0
1 parent c3e84be commit f3ce1a8

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

asmcomp/cmm_helpers.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,8 @@ let call_cached_method obj tag cache pos args dbg =
787787
(* Allocation *)
788788

789789
let make_alloc_generic set_fn dbg tag wordsize args =
790+
(* allocs of size 0 must be statically allocated else the Gc will bug *)
791+
assert (List.compare_length_with args 0 > 0);
790792
if wordsize <= Config.max_young_wosize then
791793
Cop(Calloc, Cblockheader(block_header tag wordsize, dbg) :: args, dbg)
792794
else begin

middle_end/flambda2.0/to_cmm/un_cps_helper.ml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
214231
let 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

228249
let 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

Comments
 (0)