@@ -352,14 +352,14 @@ let can_apply_primitive p pmode pos args =
352
352
353
353
let zero_alloc_of_application ~num_args annotation funct =
354
354
let zero_alloc =
355
- match annotation with
356
- | Assume _ ->
355
+ match annotation, funct.exp_desc with
356
+ | Assume _ , _ ->
357
357
(* The user wrote a zero_alloc attribute on the application - keep it. *)
358
358
annotation
359
- | Ignore_assert_all | Check _ ->
359
+ | ( Ignore_assert_all | Check _ ), _ ->
360
360
(* These are rejected in typecore *)
361
361
Misc. fatal_error " Translcore.zero_alloc_of_application: illegal attr"
362
- | Default_zero_alloc ->
362
+ | Default_zero_alloc , Texp_ident ( _ , _ , { val_zero_alloc; _ } , _ , _ ) ->
363
363
(* We assume the call is zero_alloc if the function is known to be
364
364
zero_alloc. If the function is zero_alloc opt, then we need to be sure
365
365
that the opt checks were run to license this assumption. We judge
@@ -370,18 +370,19 @@ let zero_alloc_of_application ~num_args annotation funct =
370
370
| Check_default | No_check -> false
371
371
| Check_all | Check_opt_only -> true
372
372
in
373
- match funct.exp_desc with
374
- | Texp_ident (_, _, { val_zero_alloc = (Check c); _ }, _, _)
375
- when c.arity = num_args && (use_opt || not c.opt) ->
373
+ begin match Zero_alloc. get_defaulting val_zero_alloc with
374
+ | Check c when c.arity = num_args && (use_opt || not c.opt) ->
376
375
Builtin_attributes. Assume {
377
376
strict = c.strict;
378
377
never_returns_normally = false ;
379
378
never_raises = false ;
380
379
arity = c.arity;
381
380
loc = c.loc
382
381
}
383
- | _ -> Builtin_attributes. Default_zero_alloc
384
-
382
+ | Check _ | Default_zero_alloc | Ignore_assert_all | Assume _ ->
383
+ Builtin_attributes. Default_zero_alloc
384
+ end
385
+ | Default_zero_alloc , _ -> Builtin_attributes. Default_zero_alloc
385
386
in
386
387
Builtin_attributes. assume_zero_alloc zero_alloc
387
388
@@ -1618,6 +1619,7 @@ and transl_function ~in_new_scope ~scopes e params body
1618
1619
~zero_alloc =
1619
1620
let attrs = e.exp_attributes in
1620
1621
let mode = transl_alloc_mode_r alloc_mode in
1622
+ let zero_alloc = Zero_alloc. get_defaulting zero_alloc in
1621
1623
let assume_zero_alloc = Builtin_attributes. assume_zero_alloc zero_alloc in
1622
1624
let scopes =
1623
1625
if in_new_scope then
0 commit comments