OCaml bindings: fix infinite recursion on string_of_lltype
[oota-llvm.git] / test / Bindings / Ocaml / analysis.ml
1 (* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_analysis.cmxa %s -o %t
2  * RUN: %t
3  * XFAIL: vg_leak
4  *)
5
6 open Llvm
7 open Llvm_analysis
8
9 (* Note that this takes a moment to link, so it's best to keep the number of
10    individual tests low. *)
11
12 let context = global_context ()
13
14 let test x = if not x then exit 1 else ()
15
16 let bomb msg =
17   prerr_endline msg;
18   exit 2
19
20 let _ =
21   let fty = function_type (void_type context) [| |] in
22   let m = create_module context "valid_m" in
23   let fn = define_function "valid_fn" fty m in
24   let at_entry = builder_at_end context (entry_block fn) in
25   ignore (build_ret_void at_entry);
26   
27   
28   (* Test that valid constructs verify. *)
29   begin match verify_module m with
30     Some msg -> bomb "valid module failed verification!"
31   | None -> ()
32   end;
33   
34   if not (verify_function fn) then bomb "valid function failed verification!";
35   
36   
37   (* Test that invalid constructs do not verify.
38      A basic block can contain only one terminator instruction. *)
39   ignore (build_ret_void at_entry);
40   
41   begin match verify_module m with
42     Some msg -> ()
43   | None -> bomb "invalid module passed verification!"
44   end;
45   
46   if verify_function fn then bomb "invalid function passed verification!";
47   
48   
49   dispose_module m
50   
51   (* Don't bother to test assert_valid_{module,function}. *)