Skip to content

Commit 6ec8c8f

Browse files
stedolanmshinwell
authored andcommitted
Ensure allocations are initialised, even dead ones (#405)
1 parent 6e543be commit 6ec8c8f

File tree

6 files changed

+50
-8
lines changed

6 files changed

+50
-8
lines changed

backend/comballoc.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ let rec combine i allocstate =
6363
i.arg i.res i.dbg next, allocstate)
6464
end
6565
| Iop(Icall_ind | Icall_imm _ | Iextcall _ |
66-
Itailcall_ind | Itailcall_imm _ | Iprobe _) ->
66+
Itailcall_ind | Itailcall_imm _ | Iprobe _ |
67+
Iintop Icheckbound | Iintop_imm (Icheckbound, _)) ->
6768
let newnext = combine_restart i.next in
6869
(instr_cons_debug i.desc i.arg i.res i.dbg newnext,
6970
allocstate)

backend/selectgen.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,15 +417,16 @@ method is_simple_expr = function
417417
| Cextcall { effects = No_effects; coeffects = No_coeffects; } ->
418418
List.for_all self#is_simple_expr args
419419
(* The following may have side effects *)
420-
| Capply _ | Cextcall _ | Calloc | Cstore _ | Craise _ | Cprobe _
421-
| Cprobe_is_enabled _ | Copaque -> false
420+
| Capply _ | Cextcall _ | Calloc | Cstore _
421+
| Craise _ | Ccheckbound
422+
| Cprobe _ | Cprobe_is_enabled _ | Copaque -> false
422423
| Cprefetch _ -> false (* avoid reordering *)
423424
(* The remaining operations are simple if their args are *)
424425
| Cload _ | Caddi | Csubi | Cmuli | Cmulhi _ | Cdivi | Cmodi | Cand | Cor
425426
| Cxor | Clsl | Clsr | Casr | Ccmpi _ | Caddv | Cadda | Ccmpa _ | Cnegf
426427
| Cclz _ | Cctz _ | Cpopcnt
427428
| Cabsf | Caddf | Csubf | Cmulf | Cdivf | Cfloatofint | Cintoffloat
428-
| Ccmpf _ | Ccheckbound -> List.for_all self#is_simple_expr args
429+
| Ccmpf _ -> List.for_all self#is_simple_expr args
429430
end
430431
| Cassign _ | Cifthenelse _ | Cswitch _ | Ccatch _ | Cexit _
431432
| Ctrywith _ -> false

ocaml/asmcomp/comballoc.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ let rec combine i allocstate =
6363
i.arg i.res i.dbg next, allocstate)
6464
end
6565
| Iop(Icall_ind | Icall_imm _ | Iextcall _ |
66-
Itailcall_ind | Itailcall_imm _ | Iprobe _) ->
66+
Itailcall_ind | Itailcall_imm _ | Iprobe _ |
67+
Iintop Icheckbound | Iintop_imm (Icheckbound, _)) ->
6768
let newnext = combine_restart i.next in
6869
(instr_cons_debug i.desc i.arg i.res i.dbg newnext,
6970
allocstate)

ocaml/asmcomp/selectgen.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,14 @@ method is_simple_expr = function
324324
| Cop(op, args, _) ->
325325
begin match op with
326326
(* The following may have side effects *)
327-
| Capply _ | Cextcall _ | Calloc | Cstore _ | Craise _ | Cprobe _
328-
| Cprobe_is_enabled _ -> false
327+
| Capply _ | Cextcall _ | Calloc | Cstore _
328+
| Craise _ | Ccheckbound
329+
| Cprobe _ | Cprobe_is_enabled _ -> false
329330
(* The remaining operations are simple if their args are *)
330331
| Cload _ | Caddi | Csubi | Cmuli | Cmulhi | Cdivi | Cmodi | Cand | Cor
331332
| Cxor | Clsl | Clsr | Casr | Ccmpi _ | Caddv | Cadda | Ccmpa _ | Cnegf
332333
| Cabsf | Caddf | Csubf | Cmulf | Cdivf | Cfloatofint | Cintoffloat
333-
| Ccmpf _ | Ccheckbound -> List.for_all self#is_simple_expr args
334+
| Ccmpf _ -> List.for_all self#is_simple_expr args
334335
end
335336
| Cassign _ | Cifthenelse _ | Cswitch _ | Ccatch _ | Cexit _
336337
| Ctrywith _ -> false
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
(* TEST
2+
* native *)
3+
4+
let glob = ref (1, 2)
5+
let[@inline never] combine1 x a =
6+
begin try
7+
glob := (2, x);
8+
glob := (3, a.(4));
9+
with
10+
| Invalid_argument _ -> ()
11+
end;
12+
!glob
13+
14+
let[@inline never] combine2 x a =
15+
let loc = ref (1, 2) in
16+
begin try
17+
loc := (2, x);
18+
loc := (3, a.(4));
19+
with
20+
| Invalid_argument _ -> ()
21+
end;
22+
!loc
23+
24+
let[@inline never] measure f =
25+
let empty_array = [| |] in
26+
let prebefore = Gc.minor_words () in
27+
let before = Gc.minor_words () in
28+
let r = f 42 empty_array in
29+
assert (r = (2, 42));
30+
let after = Gc.minor_words () in
31+
((after -. before) -. (before -. prebefore))
32+
33+
34+
let () =
35+
Printf.printf "%10s: %.0f\n" "combine1" (measure combine1);
36+
Printf.printf "%10s: %.0f\n" "combine2" (measure combine2)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
combine1: 3
2+
combine2: 3

0 commit comments

Comments
 (0)