Skip to content

Commit

Permalink
Merge pull request #11587 from lthls/poly-variant-pointer-comparison
Browse files Browse the repository at this point in the history
Stop using integer comparison on potential pointers
  • Loading branch information
gasche committed Oct 4, 2022
2 parents dd5e82d + f7041e9 commit 457ed4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ Working version
by leaf functions.
(Tom Kelly and Xavier Leroy, review by Mark Shinwell)

- #11587: Prevent integer comparison from being used on pointers
(Vincent Laviron, review by Gabriel Scherer)

OCaml 5.0
---------

Expand Down
11 changes: 8 additions & 3 deletions lambda/matching.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2946,9 +2946,14 @@ let combine_variant loc row arg partial ctx def (tag_lambda_list, total1, _pats)
match (consts, nonconsts) with
| [ (_, act1) ], [ (_, act2) ] when fail = None ->
test_int_or_block arg act1 act2
| _, [] ->
(* One can compare integers and pointers *)
make_test_sequence_variant_constant fail arg consts
| _, [] -> (
let lam = make_test_sequence_variant_constant fail arg consts in
(* PR#11587: Switcher.test_sequence expects integer inputs, so
if the type allows pointers we must filter them away. *)
match fail with
| None -> lam
| Some fail -> test_int_or_block arg lam fail
)
| [], _ -> (
let lam = call_switcher_variant_constr loc fail arg nonconsts in
(* One must not dereference integers *)
Expand Down

0 comments on commit 457ed4e

Please sign in to comment.