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