Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Invalid reads from complex bigarrays (#1755)
The following function can raise an Assert_failure in trunk: let bug_example () = let open Bigarray in let work = Array1.create complex64 c_layout 1 in work.{0} <- { Complex. re=0.; im=0. }; let result = work.{0}.Complex.re in (* alloc *) assert (result = 0.) because the Complex.t value (corresponding to work.{0} on line "alloc" ) is allocated after the address inside the bigarray has been computed but before the reads actually occur. The allocation can trigger a collection that then deallocates the bigarray. This commit moves the allocation of the Complex.t value so that it occurs after the reads from the bigarray. Our understanding is that only complex reads can allocate: non-complex reads do not allocate, and writes never allocate. It also changes the Cmm type for bigarray addressing from Int to Addr, marking the fact that the returned pointer is a derived pointer that may not survive a GC.
- Loading branch information