Fix bugs section.
[llvm-complete.git] / test / Bindings / Ocaml / analysis.ml
blob9c61295d455c1f1e27efd7601fc259c49e1e684f
1 (* RUN: %ocamlc -warn-error A llvm.cma llvm_analysis.cma %s -o %t
2 * RUN: ./%t %t.bc
3 *)
5 open Llvm
6 open Llvm_analysis
8 (* Note that this takes a moment to link, so it's best to keep the number of
9 individual tests low. *)
11 let test x = if not x then exit 1 else ()
13 let bomb msg =
14 prerr_endline msg;
15 exit 2
17 let _ =
18 let fty = function_type void_type [| |] in
19 let m = create_module "valid_m" in
20 let fn = define_function "valid_fn" fty m in
21 let at_entry = builder_at_end (entry_block fn) in
22 ignore (build_ret_void at_entry);
25 (* Test that valid constructs verify. *)
26 begin match verify_module m with
27 Some msg -> bomb "valid module failed verification!"
28 | None -> ()
29 end;
31 if not (verify_function fn) then bomb "valid function failed verification!";
34 (* Test that invalid constructs do not verify.
35 A basic block can contain only one terminator instruction. *)
36 ignore (build_ret_void at_entry);
38 begin match verify_module m with
39 Some msg -> ()
40 | None -> bomb "invalid module passed verification!"
41 end;
43 if verify_function fn then bomb "invalid function passed verification!";
46 dispose_module m
48 (* Don't bother to test assert_valid_{module,function}. *)