[PATCH] D99471: [OCaml] Fix unsafe uses of Store_field

Josh Berdine via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 28 15:28:20 PDT 2021


jberdine created this revision.
jberdine added a reviewer: vaivaswatha.
Herald added a reviewer: whitequark.
Herald added a subscriber: mgorny.
jberdine requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Using `Store_field` to initialize fields of blocks allocated with
`caml_alloc_small` is unsafe. The fields of blocks allocated by
`caml_alloc_small` are not initialized, and `Store_field` calls the
OCaml GC write barrier. If the uninitialized value of a field happens
to point into the OCaml heap, then it will e.g. be added to a conflict
set or followed and have what the GC thinks are color bits
changed. This leads to crashes or memory corruption.

This diff fixes a few (I think all) instances of this problem. Some of
these are creating option values. OCaml 4.12 has a dedicated
`caml_alloc_some` function for this, so this diff adds a compatible
function with a version check to avoid conflict. With that, macros for
accessing option values are also added.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99471

Files:
  llvm/bindings/ocaml/analysis/CMakeLists.txt
  llvm/bindings/ocaml/analysis/analysis_ocaml.c
  llvm/bindings/ocaml/llvm/llvm_ocaml.c
  llvm/bindings/ocaml/llvm/llvm_ocaml.h
  llvm/bindings/ocaml/target/CMakeLists.txt
  llvm/bindings/ocaml/target/target_ocaml.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99471.333738.patch
Type: text/x-patch
Size: 5563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210328/b8d6c09a/attachment.bin>


More information about the llvm-commits mailing list