blob: 9c61295d455c1f1e27efd7601fc259c49e1e684f [file] [log] [blame]
Gordon Henriksen874c7862007-12-22 19:41:30 +00001(* RUN: %ocamlc -warn-error A llvm.cma llvm_analysis.cma %s -o %t
Gordon Henriksen3ed72362007-10-06 21:00:36 +00002 * RUN: ./%t %t.bc
3 *)
4
5open Llvm
6open Llvm_analysis
7
8(* Note that this takes a moment to link, so it's best to keep the number of
9 individual tests low. *)
10
11let test x = if not x then exit 1 else ()
12
13let bomb msg =
14 prerr_endline msg;
15 exit 2
16
17let _ =
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);
23
24
25 (* Test that valid constructs verify. *)
Gordon Henriksen63a180b2007-12-01 20:59:23 +000026 begin match verify_module m with
Gordon Henriksen3ed72362007-10-06 21:00:36 +000027 Some msg -> bomb "valid module failed verification!"
Gordon Henriksen63a180b2007-12-01 20:59:23 +000028 | None -> ()
29 end;
Gordon Henriksen3ed72362007-10-06 21:00:36 +000030
31 if not (verify_function fn) then bomb "valid function failed verification!";
32
33
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);
37
Gordon Henriksen63a180b2007-12-01 20:59:23 +000038 begin match verify_module m with
Gordon Henriksen3ed72362007-10-06 21:00:36 +000039 Some msg -> ()
Gordon Henriksen63a180b2007-12-01 20:59:23 +000040 | None -> bomb "invalid module passed verification!"
41 end;
Gordon Henriksen3ed72362007-10-06 21:00:36 +000042
43 if verify_function fn then bomb "invalid function passed verification!";
44
45
46 dispose_module m
47
48 (* Don't bother to test assert_valid_{module,function}. *)