Skip to content

Commit 71702fa

Browse files
vouillonhhugo
authored andcommitted
Global flow analysis: bug fix
We were not correctly propagating the information that a block is possibly mutated.
1 parent 18b1cbc commit 71702fa

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* Test: use dune test stanzas (#1631)
66
* Merged Wasm_of_ocaml (#1724)
77

8+
## Bug fixes
9+
* Fix small bug in global data flow analysis (#1768)
10+
811
# 5.9.1 (02-12-2024) - Lille
912

1013
## Features/Changes

compiler/lib/global_flow.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,11 @@ let propagate st ~update approx x =
436436
| Some tags -> List.memq t ~set:tags
437437
| None -> true ->
438438
let t = a.(n) in
439+
let m = Var.ISet.mem st.possibly_mutable z in
440+
if not m then add_dep st x z;
439441
add_dep st x t;
440442
let a = Var.Tbl.get approx t in
441-
if Var.ISet.mem st.possibly_mutable z
442-
then Domain.join ~update ~st ~approx Domain.others a
443-
else a
443+
if m then Domain.join ~update ~st ~approx Domain.others a else a
444444
| Expr (Block _ | Closure _) -> Domain.bot
445445
| Phi _ | Expr _ -> assert false)
446446
known
@@ -464,6 +464,8 @@ let propagate st ~update approx x =
464464
(fun z ->
465465
match st.defs.(Var.idx z) with
466466
| Expr (Block (_, lst, _, _)) ->
467+
let m = Var.ISet.mem st.possibly_mutable z in
468+
if not m then add_dep st x z;
467469
Array.iter ~f:(fun t -> add_dep st x t) lst;
468470
let a =
469471
Array.fold_left
@@ -472,9 +474,7 @@ let propagate st ~update approx x =
472474
~init:Domain.bot
473475
lst
474476
in
475-
if Var.ISet.mem st.possibly_mutable z
476-
then Domain.join ~update ~st ~approx Domain.others a
477-
else a
477+
if m then Domain.join ~update ~st ~approx Domain.others a else a
478478
| Expr (Closure _) -> Domain.bot
479479
| Phi _ | Expr _ -> assert false)
480480
known

compiler/tests-compiler/gh1768.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ let () =
6464
}];
6565
}
6666
var x = f();
67-
function g(param){return x[1].call(null);}
67+
function g(param){return caml_call1(x[1], 7);}
6868
h(x);
69-
if(10 !== caml_call1(g(), dummy))
69+
if(10 !== caml_call1(g(), 3))
7070
throw caml_maybe_attach_backtrace([0, Assert_failure, _b_], 1);
7171
var Test = [0];
7272
runtime.caml_register_global(3, Test, "Test");

0 commit comments

Comments
 (0)