]> granicus.if.org Git - llvm/commitdiff
[OCaml] Fix undefined reference to LLVMDumpType() with NDEBUG
authorMichal Gorny <mgorny@gentoo.org>
Thu, 27 Jul 2017 21:13:25 +0000 (21:13 +0000)
committerMichal Gorny <mgorny@gentoo.org>
Thu, 27 Jul 2017 21:13:25 +0000 (21:13 +0000)
Account for the possibility of LLVMDumpType() not being available with
NDEBUG in the OCaml bindings. If it is not built into LLVM, make
the dump function raise an exception.

Since rL293359, the dump functions are built only if either NDEBUG is
not defined, or LLVM_ENABLE_DUMP is defined. As a result, if the dump
functions are not built in LLVM, the dynamic OCaml libraries fail to
load due to undefined LLVMDumpType symbol.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309321 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/ocaml/llvm/llvm.ml
bindings/ocaml/llvm/llvm.mli
bindings/ocaml/llvm/llvm_ocaml.c

index 6e8ca662ef67ea45e4b34b788271644c54ed5d23..59f0f178c288165aaa67d41cdaaf7b340edc7c00 100644 (file)
@@ -20,6 +20,10 @@ type llattribute
 type llmemorybuffer
 type llmdkind
 
+exception FeatureDisabled of string
+
+let () = Callback.register_exception "Llvm.FeatureDisabled" (FeatureDisabled "")
+
 module TypeKind = struct
   type t =
   | Void
index c422e78f5d2dd0c770becfede3db37b49504399b..3387c1ec52fe96bd60bd9457fbe1446b21e32dbc 100644 (file)
@@ -371,6 +371,8 @@ type ('a, 'b) llrev_pos =
 
 (** {6 Exceptions} *)
 
+exception FeatureDisabled of string
+
 exception IoError of string
 
 
index 4b6d1c5072bc50917268ca10f18683b65bec0b27..137b17f26bfb2316086896f315edfb876168e60e 100644 (file)
@@ -336,7 +336,12 @@ CAMLprim LLVMContextRef llvm_type_context(LLVMTypeRef Ty) {
 
 /* lltype -> unit */
 CAMLprim value llvm_dump_type(LLVMTypeRef Val) {
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   LLVMDumpType(Val);
+#else
+  caml_raise_with_arg(*caml_named_value("Llvm.FeatureDisabled"),
+      caml_copy_string("dump"));
+#endif
   return Val_unit;
 }