[PATCH] D136535: [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:08:55 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/D136535

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,7 @@
 value caml_alloc_some(value);
 #endif
 
+/* ASSUME: Pointer is at least 2-bit aligned! */
 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: D136535.469918.patch
Type: text/x-patch
Size: 1150 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221022/3fdbc4e8/attachment.bin>


More information about the llvm-commits mailing list