[llvm] b06c669 - [NFC][OCaml] Simplify llvm_global_initializer using ptr_to_option

Josh Berdine via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 26 05:01:39 PDT 2021


Author: Josh Berdine
Date: 2021-03-26T11:49:13Z
New Revision: b06c669114e2e903ca3941e3ec738f868c863eee

URL: https://github.com/llvm/llvm-project/commit/b06c669114e2e903ca3941e3ec738f868c863eee
DIFF: https://github.com/llvm/llvm-project/commit/b06c669114e2e903ca3941e3ec738f868c863eee.diff

LOG: [NFC][OCaml] Simplify llvm_global_initializer using ptr_to_option

This diff uses ptr_to_option to convert a nullable C pointer to an
OCaml option instead of the redundant implementation in
llvm_global_initializer.

Differential Revision: https://reviews.llvm.org/D99391

Added: 
    

Modified: 
    llvm/bindings/ocaml/llvm/llvm_ocaml.c

Removed: 
    


################################################################################
diff  --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index 04f9796baf0c..af655f94eb28 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -1349,14 +1349,7 @@ CAMLprim value llvm_delete_global(LLVMValueRef GlobalVar) {
 
 /* llvalue -> llvalue option */
 CAMLprim value llvm_global_initializer(LLVMValueRef GlobalVar) {
-  CAMLparam0();
-  LLVMValueRef Init;
-  if ((Init = LLVMGetInitializer(GlobalVar))) {
-    value Option = alloc(1, 0);
-    Field(Option, 0) = (value) Init;
-    CAMLreturn(Option);
-  }
-  CAMLreturn(Val_int(0));
+  return ptr_to_option(LLVMGetInitializer(GlobalVar));
 }
 
 /* llvalue -> llvalue -> unit */


        


More information about the llvm-commits mailing list