Skip to content

Ensure allocations are initialised, even dead ones #405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/comballoc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ let rec combine i allocstate =
i.arg i.res i.dbg next, allocstate)
end
| Iop(Icall_ind | Icall_imm _ | Iextcall _ |
Itailcall_ind | Itailcall_imm _ | Iprobe _) ->
Itailcall_ind | Itailcall_imm _ | Iprobe _ |
Iintop Icheckbound | Iintop_imm (Icheckbound, _)) ->
let newnext = combine_restart i.next in
(instr_cons_debug i.desc i.arg i.res i.dbg newnext,
allocstate)
Expand Down
7 changes: 4 additions & 3 deletions backend/selectgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,16 @@ method is_simple_expr = function
| Cextcall { effects = No_effects; coeffects = No_coeffects; } ->
List.for_all self#is_simple_expr args
(* The following may have side effects *)
| Capply _ | Cextcall _ | Calloc | Cstore _ | Craise _ | Cprobe _
| Cprobe_is_enabled _ | Copaque -> false
| Capply _ | Cextcall _ | Calloc | Cstore _
| Craise _ | Ccheckbound
| Cprobe _ | Cprobe_is_enabled _ | Copaque -> false
| Cprefetch _ -> false (* avoid reordering *)
(* The remaining operations are simple if their args are *)
| Cload _ | Caddi | Csubi | Cmuli | Cmulhi _ | Cdivi | Cmodi | Cand | Cor
| Cxor | Clsl | Clsr | Casr | Ccmpi _ | Caddv | Cadda | Ccmpa _ | Cnegf
| Cclz _ | Cctz _ | Cpopcnt
| Cabsf | Caddf | Csubf | Cmulf | Cdivf | Cfloatofint | Cintoffloat
| Ccmpf _ | Ccheckbound -> List.for_all self#is_simple_expr args
| Ccmpf _ -> List.for_all self#is_simple_expr args
end
| Cassign _ | Cifthenelse _ | Cswitch _ | Ccatch _ | Cexit _
| Ctrywith _ -> false
Expand Down
3 changes: 2 additions & 1 deletion ocaml/asmcomp/comballoc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ let rec combine i allocstate =
i.arg i.res i.dbg next, allocstate)
end
| Iop(Icall_ind | Icall_imm _ | Iextcall _ |
Itailcall_ind | Itailcall_imm _ | Iprobe _) ->
Itailcall_ind | Itailcall_imm _ | Iprobe _ |
Iintop Icheckbound | Iintop_imm (Icheckbound, _)) ->
let newnext = combine_restart i.next in
(instr_cons_debug i.desc i.arg i.res i.dbg newnext,
allocstate)
Expand Down
7 changes: 4 additions & 3 deletions ocaml/asmcomp/selectgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,14 @@ method is_simple_expr = function
| Cop(op, args, _) ->
begin match op with
(* The following may have side effects *)
| Capply _ | Cextcall _ | Calloc | Cstore _ | Craise _ | Cprobe _
| Cprobe_is_enabled _ -> false
| Capply _ | Cextcall _ | Calloc | Cstore _
| Craise _ | Ccheckbound
| Cprobe _ | Cprobe_is_enabled _ -> false
(* The remaining operations are simple if their args are *)
| Cload _ | Caddi | Csubi | Cmuli | Cmulhi | Cdivi | Cmodi | Cand | Cor
| Cxor | Clsl | Clsr | Casr | Ccmpi _ | Caddv | Cadda | Ccmpa _ | Cnegf
| Cabsf | Caddf | Csubf | Cmulf | Cdivf | Cfloatofint | Cintoffloat
| Ccmpf _ | Ccheckbound -> List.for_all self#is_simple_expr args
| Ccmpf _ -> List.for_all self#is_simple_expr args
end
| Cassign _ | Cifthenelse _ | Cswitch _ | Ccatch _ | Cexit _
| Ctrywith _ -> false
Expand Down
36 changes: 36 additions & 0 deletions ocaml/testsuite/tests/basic/combine_checkbound.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(* TEST
* native *)

let glob = ref (1, 2)
let[@inline never] combine1 x a =
begin try
glob := (2, x);
glob := (3, a.(4));
with
| Invalid_argument _ -> ()
end;
!glob

let[@inline never] combine2 x a =
let loc = ref (1, 2) in
begin try
loc := (2, x);
loc := (3, a.(4));
with
| Invalid_argument _ -> ()
end;
!loc

let[@inline never] measure f =
let empty_array = [| |] in
let prebefore = Gc.minor_words () in
let before = Gc.minor_words () in
let r = f 42 empty_array in
assert (r = (2, 42));
let after = Gc.minor_words () in
((after -. before) -. (before -. prebefore))


let () =
Printf.printf "%10s: %.0f\n" "combine1" (measure combine1);
Printf.printf "%10s: %.0f\n" "combine2" (measure combine2)
2 changes: 2 additions & 0 deletions ocaml/testsuite/tests/basic/combine_checkbound.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
combine1: 3
combine2: 3