fix #454: work around a weird miscompilation

This commit is contained in:
Simon Cruanes 2024-09-17 12:51:07 -04:00
parent 6ab811f79b
commit c959e396b3
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 19 additions and 3 deletions

View file

@ -176,7 +176,8 @@ let append a b =
let[@inline] get v i =
if i < 0 || i >= v.size then invalid_arg "CCVector.get";
Array.unsafe_get v.vec i
(* NOTE: over eager inlining seems to miscompile for int32 at least (#454) *)
Sys.opaque_identity (Array.unsafe_get v.vec i)
let[@inline] set v i x =
if i < 0 || i >= v.size then invalid_arg "CCVector.set";
@ -282,7 +283,8 @@ let[@inline] top v =
let[@inline] top_exn v =
if v.size = 0 then raise Empty;
Array.unsafe_get v.vec (v.size - 1)
(* NOTE: over eager inlining seems to miscompile for int32 at least (#454) *)
Sys.opaque_identity (Array.unsafe_get v.vec (v.size - 1))
let[@inline] copy v = { size = v.size; vec = Array.sub v.vec 0 v.size }

View file

@ -1,6 +1,8 @@
module T = (val Containers_testlib.make ~__FILE__ ())
include T
open CCVector;;
open CCVector
let spf = Printf.sprintf;;
t @@ fun () -> create_with ~capacity:200 1 |> capacity >= 200;;
t @@ fun () -> return 42 |> to_list = [ 42 ];;
@ -751,3 +753,15 @@ push v 0;
push v 0;
push v 0;
6 = foldi (fun i acc _ -> acc + i) 0 v
;;
t ~name:"reg454" @@ fun () ->
let arr : Int32.t vector = create () in
CCVector.push arr (Int32.of_int 123456);
let s = spf "%d\n" (Int32.to_int (CCVector.get arr 0)) in
Printf.eprintf "%d\n" (Int32.to_int (CCVector.get arr 0));
let x = CCVector.get arr 0 in
let s2 = spf "%d\n" (Int32.to_int x) in
Printf.eprintf "%d\n" (Int32.to_int x);
assert_equal ~printer:(spf "%S") s s2;
true