[PATCH] D136537: [llvm-ocaml] Assume pointers are at least 2-bit aligned
Alan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 22 12:56:00 PDT 2022
alan created this revision.
Herald added a project: All.
alan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D136537
Files:
llvm/bindings/ocaml/llvm/llvm_ocaml.c
llvm/bindings/ocaml/llvm/llvm_ocaml.h
Index: llvm/bindings/ocaml/llvm/llvm_ocaml.h
===================================================================
--- llvm/bindings/ocaml/llvm/llvm_ocaml.h
+++ llvm/bindings/ocaml/llvm/llvm_ocaml.h
@@ -33,6 +33,8 @@
value caml_alloc_some(value);
#endif
+/* ASSUME: Pointer is at least 2-bit aligned! Does not allocate on the OCaml
+ heap. */
value to_val(void *ptr);
void *from_val(value v);
Index: llvm/bindings/ocaml/llvm/llvm_ocaml.c
===================================================================
--- llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -32,23 +32,9 @@
}
#endif
-value to_val(void *ptr) {
- if ((((value)ptr) & 1) == 0) {
- return ((value)ptr) + 1;
- } else {
- value v = caml_alloc(1, Abstract_tag);
- *((void **)Data_abstract_val(v)) = ptr;
- return v;
- }
-}
+value to_val(void *ptr) { return ((value)ptr) + 1; }
-void *from_val(value v) {
- if (Is_long(v)) {
- return (void *)(v - 1);
- } else {
- return *((void **)Data_abstract_val(v));
- }
-}
+void *from_val(value v) { return (void *)(v - 1); }
value llvm_string_of_message(char *Message) {
value String = caml_copy_string(Message);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136537.469923.patch
Type: text/x-patch
Size: 1191 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221022/c8883c06/attachment.bin>
More information about the llvm-commits
mailing list