Skip to content

Commit

Permalink
Global dead code: regression test for bug fixed in #1681 (before fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon authored and hhugo committed Oct 18, 2024
1 parent 1e54c94 commit ebc6c4c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions compiler/tests-compiler/global_deadcode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,30 @@ let%expect_test "Omit unused return expressions" =
function f(x){caml_call1(Stdlib[44], x);}
//end
|}]

let%expect_test "Bug fix in PR #1681" =
let program =
compile_and_parse_whole_program
{|
type t = {mutable a : int; b : int};;
let f b =
let x = {a = 1; b = 2} in
if b then (
x
) else (
x.a <- 1; (* This has to be handled after [x] is returned *)
{a = 3; b = 4}
)
let g = ref (fun _ -> assert false)
let _ =
(* We should not track that [f] is used below *)
g := f; prerr_int ((!g true).b + (!g false).b)
|}
in
print_fun_decl program (Some "f");
(* No field of record x should be eliminated. *)
[%expect
{|
function f(b){var x = [0, 1]; return b ? x : (x[1] = 1, [0, 3, 4]);}
//end
|}]

0 comments on commit ebc6c4c

Please sign in to comment.