aboutsummaryrefslogtreecommitdiffstats
path: root/test/Bindings
diff options
context:
space:
mode:
Diffstat (limited to 'test/Bindings')
-rw-r--r--test/Bindings/Ocaml/ipo_opts.ml73
-rw-r--r--test/Bindings/Ocaml/scalar_opts.ml10
-rw-r--r--test/Bindings/Ocaml/target.ml1
-rw-r--r--test/Bindings/Ocaml/vmcore.ml165
4 files changed, 232 insertions, 17 deletions
diff --git a/test/Bindings/Ocaml/ipo_opts.ml b/test/Bindings/Ocaml/ipo_opts.ml
new file mode 100644
index 0000000..3a36231
--- /dev/null
+++ b/test/Bindings/Ocaml/ipo_opts.ml
@@ -0,0 +1,73 @@
+(* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_ipo.cmxa llvm_target.cmxa %s -o %t
+ * RUN: %t %t.bc
+ * XFAIL: vg_leak
+ *)
+
+(* Note: It takes several seconds for ocamlopt to link an executable with
+ libLLVMCore.a, so it's better to write a big test than a bunch of
+ little ones. *)
+
+open Llvm
+open Llvm_ipo
+open Llvm_target
+
+let context = global_context ()
+let void_type = Llvm.void_type context
+let i8_type = Llvm.i8_type context
+
+(* Tiny unit test framework - really just to help find which line is busted *)
+let print_checkpoints = false
+
+let suite name f =
+ if print_checkpoints then
+ prerr_endline (name ^ ":");
+ f ()
+
+
+(*===-- Fixture -----------------------------------------------------------===*)
+
+let filename = Sys.argv.(1)
+let m = create_module context filename
+
+
+(*===-- Transforms --------------------------------------------------------===*)
+
+let test_transforms () =
+ let (++) x f = ignore (f x); x in
+
+ let fty = function_type i8_type [| |] in
+ let fn = define_function "fn" fty m in
+ let fn2 = define_function "fn2" fty m in begin
+ ignore (build_ret (const_int i8_type 4) (builder_at_end context (entry_block fn)));
+ let b = builder_at_end context (entry_block fn2) in
+ ignore (build_ret (build_call fn [| |] "" b) b);
+ end;
+
+ let td = TargetData.create (target_triple m) in
+
+ ignore (PassManager.create ()
+ ++ TargetData.add td
+ ++ add_argument_promotion
+ ++ add_constant_merge
+ ++ add_dead_arg_elimination
+ ++ add_function_attrs
+ ++ add_function_inlining
+ ++ add_global_dce
+ ++ add_global_optimizer
+ ++ add_ipc_propagation
+ ++ add_prune_eh
+ ++ add_ipsccp
+ ++ add_internalize
+ ++ add_strip_dead_prototypes
+ ++ add_strip_symbols
+ ++ PassManager.run_module m
+ ++ PassManager.dispose);
+
+ TargetData.dispose td
+
+
+(*===-- Driver ------------------------------------------------------------===*)
+
+let _ =
+ suite "transforms" test_transforms;
+ dispose_module m
diff --git a/test/Bindings/Ocaml/scalar_opts.ml b/test/Bindings/Ocaml/scalar_opts.ml
index 1ea9785..34a7a6a 100644
--- a/test/Bindings/Ocaml/scalar_opts.ml
+++ b/test/Bindings/Ocaml/scalar_opts.ml
@@ -42,11 +42,14 @@ let test_transforms () =
ignore (PassManager.create_function m
++ TargetData.add td
+ ++ add_verifier
++ add_constant_propagation
++ add_sccp
++ add_dead_store_elimination
++ add_aggressive_dce
++ add_scalar_repl_aggregation
+ ++ add_scalar_repl_aggregation_ssa
+ ++ add_scalar_repl_aggregation_with_threshold 4
++ add_ind_var_simplification
++ add_instruction_combination
++ add_licm
@@ -62,7 +65,14 @@ let test_transforms () =
++ add_gvn
++ add_memcpy_opt
++ add_loop_deletion
+ ++ add_loop_idiom
++ add_lib_call_simplification
+ ++ add_correlated_value_propagation
+ ++ add_early_cse
+ ++ add_lower_expect_intrinsic
+ ++ add_type_based_alias_analysis
+ ++ add_basic_alias_analysis
+ ++ add_verifier
++ PassManager.initialize
++ PassManager.run_function fn
++ PassManager.finalize
diff --git a/test/Bindings/Ocaml/target.ml b/test/Bindings/Ocaml/target.ml
index 5e3ab4b..1b6b71e 100644
--- a/test/Bindings/Ocaml/target.ml
+++ b/test/Bindings/Ocaml/target.ml
@@ -37,7 +37,6 @@ let test_target_data () =
let sty = struct_type context [| i32_type; i64_type |] in
ignore (TargetData.as_string td);
- ignore (TargetData.invalidate_struct_layout td sty);
ignore (byte_order td);
ignore (pointer_size td);
ignore (intptr_type td);
diff --git a/test/Bindings/Ocaml/vmcore.ml b/test/Bindings/Ocaml/vmcore.ml
index bff04a1..9329286 100644
--- a/test/Bindings/Ocaml/vmcore.ml
+++ b/test/Bindings/Ocaml/vmcore.ml
@@ -337,6 +337,16 @@ let test_constants () =
"{cx},{ax},{di},~{dirflag},~{fpsr},~{flags},~{edi},~{ecx}"
true
false)
+ end;
+
+ group "recursive struct"; begin
+ let nsty = named_struct_type context "rec" in
+ let pty = pointer_type nsty in
+ struct_set_body nsty [| i32_type; pty |] false;
+ let elts = [| const_int i32_type 4; const_pointer_null pty |] in
+ let grec_init = const_named_struct nsty elts in
+ ignore (define_global "grec" grec_init m);
+ ignore (string_of_lltype nsty);
end
@@ -822,6 +832,18 @@ let test_builder () =
let b = builder_at_end context (append_block context "Bb01" fn) in
ignore (build_ret_void b)
end;
+
+ group "ret aggregate";
+ begin
+ (* RUN: grep {ret \{ i8, i64 \} \{ i8 4, i64 5 \}} < %t.ll
+ *)
+ let sty = struct_type context [| i8_type; i64_type |] in
+ let fty = function_type sty [| |] in
+ let fn = declare_function "XA6" fty m in
+ let b = builder_at_end context (append_block context "Bb01" fn) in
+ let agg = [| const_int i8_type 4; const_int i64_type 5 |] in
+ ignore (build_aggregate_ret agg b)
+ end;
(* The rest of the tests will use one big function. *)
let fty = function_type i32_type [| i32_type; i32_type |] in
@@ -834,7 +856,44 @@ let test_builder () =
let bb00 = append_block context "Bb00" fn in
ignore (build_unreachable (builder_at_end context bb00));
-
+
+ group "function attribute";
+ begin
+ ignore (add_function_attr fn Attribute.UWTable);
+ (* RUN: grep "X7.*uwtable" < %t.ll
+ *)
+ insist ([Attribute.UWTable] = function_attr fn);
+ end;
+
+ (* see test/Feature/exception.ll *)
+ let bblpad = append_block context "Bblpad" fn in
+ let rt = struct_type context [| pointer_type i8_type; i32_type |] in
+ let ft = var_arg_function_type i32_type [||] in
+ let personality = declare_function "__gxx_personality_v0" ft m in
+ let ztic = declare_global (pointer_type i8_type) "_ZTIc" m in
+ let ztid = declare_global (pointer_type i8_type) "_ZTId" m in
+ let ztipkc = declare_global (pointer_type i8_type) "_ZTIPKc" m in
+ begin
+ set_global_constant true ztic;
+ set_global_constant true ztid;
+ set_global_constant true ztipkc;
+ let lp = build_landingpad rt personality 0 "lpad"
+ (builder_at_end context bblpad) in begin
+ set_cleanup lp true;
+ add_clause lp ztic;
+ insist((pointer_type (pointer_type i8_type)) = type_of ztid);
+ let ety = pointer_type (pointer_type i8_type) in
+ add_clause lp (const_array ety [| ztipkc; ztid |]);
+ ignore (build_resume lp (builder_at_end context bblpad));
+ end;
+ (* RUN: grep "landingpad.*personality.*__gxx_personality_v0" < %t.ll
+ * RUN: grep "cleanup" < %t.ll
+ * RUN: grep "catch.*i8\*\*.*@_ZTIc" < %t.ll
+ * RUN: grep "filter.*@_ZTIPKc.*@_ZTId" < %t.ll
+ * RUN: grep "resume " < %t.ll
+ * *)
+ end;
+
group "ret"; begin
(* RUN: grep {ret.*P1} < %t.ll
*)
@@ -868,8 +927,23 @@ let test_builder () =
ignore (build_unreachable (builder_at_end context bb2));
let bb3 = append_block context "SwiBlock3" fn in
ignore (build_unreachable (builder_at_end context bb3));
- let si = build_switch p1 bb3 1 (builder_at_end context bb1) in
- ignore (add_case si (const_int i32_type 2) bb2)
+ let si = build_switch p1 bb3 1 (builder_at_end context bb1) in begin
+ ignore (add_case si (const_int i32_type 2) bb2);
+ insist (switch_default_dest si = bb3);
+ end;
+ end;
+
+ group "malloc/free"; begin
+ (* RUN: grep {call.*@malloc(i32 ptrtoint} < %t.ll
+ * RUN: grep {call.*@free(i8\*} < %t.ll
+ * RUN: grep {call.*@malloc(i32 %} < %t.ll
+ *)
+ let bb1 = append_block context "MallocBlock1" fn in
+ let m1 = (build_malloc (pointer_type i32_type) "m1"
+ (builder_at_end context bb1)) in
+ ignore (build_free m1 (builder_at_end context bb1));
+ ignore (build_array_malloc i32_type p1 "m2" (builder_at_end context bb1));
+ ignore (build_unreachable (builder_at_end context bb1));
end;
group "indirectbr"; begin
@@ -891,19 +965,11 @@ let test_builder () =
group "invoke"; begin
(* RUN: grep {build_invoke.*invoke.*P1.*P2} < %t.ll
- * RUN: grep {to.*Bb04.*unwind.*Bb00} < %t.ll
+ * RUN: grep {to.*Bb04.*unwind.*Bblpad} < %t.ll
*)
let bb04 = append_block context "Bb04" fn in
let b = builder_at_end context bb04 in
- ignore (build_invoke fn [| p1; p2 |] bb04 bb00 "build_invoke" b)
- end;
-
- group "unwind"; begin
- (* RUN: grep {unwind} < %t.ll
- *)
- let bb05 = append_block context "Bb05" fn in
- let b = builder_at_end context bb05 in
- ignore (build_unwind b)
+ ignore (build_invoke fn [| p1; p2 |] bb04 bblpad "build_invoke" b)
end;
group "unreachable"; begin
@@ -991,30 +1057,63 @@ let test_builder () =
* RUN: grep {%build_load = load i32\\* %build_array_alloca} < %t.ll
* RUN: grep {store i32 %P2, i32\\* %build_alloca} < %t.ll
* RUN: grep {%build_gep = getelementptr i32\\* %build_array_alloca, i32 %P2} < %t.ll
+ * RUN: grep {%build_in_bounds_gep = getelementptr inbounds i32\\* %build_array_alloca, i32 %P2} < %t.ll
+ * RUN: grep {%build_struct_gep = getelementptr inbounds.*%build_alloca2, i32 0, i32 1} < %t.ll
*)
let alloca = build_alloca i32_type "build_alloca" b in
let array_alloca = build_array_alloca i32_type p2 "build_array_alloca" b in
ignore(build_load array_alloca "build_load" b);
ignore(build_store p2 alloca b);
ignore(build_gep array_alloca [| p2 |] "build_gep" b);
+ ignore(build_in_bounds_gep array_alloca [| p2 |] "build_in_bounds_gep" b);
+
+ let sty = struct_type context [| i32_type; i8_type |] in
+ let alloca2 = build_alloca sty "build_alloca2" b in
+ ignore(build_struct_gep alloca2 1 "build_struct_gep" b);
+
ignore(build_unreachable b)
end;
-
+
+ group "string"; begin
+ let bb09 = append_block context "Bb09" fn in
+ let b = builder_at_end context bb09 in
+ let p = build_alloca (pointer_type i8_type) "p" b in
+ (* RUN: grep "build_global_string.*stringval" < %t.ll
+ * RUN: grep "store.*build_global_string1.*p" < %t.ll
+ * *)
+ ignore (build_global_string "stringval" "build_global_string" b);
+ let g = build_global_stringptr "stringval" "build_global_string1" b in
+ ignore (build_store g p b);
+ ignore(build_unreachable b);
+ end;
+
group "casts"; begin
let void_ptr = pointer_type i8_type in
(* RUN: grep {%build_trunc = trunc i32 %P1 to i8} < %t.ll
+ * RUN: grep {%build_trunc2 = trunc i32 %P1 to i8} < %t.ll
+ * RUN: grep {%build_trunc3 = trunc i32 %P1 to i8} < %t.ll
* RUN: grep {%build_zext = zext i8 %build_trunc to i32} < %t.ll
+ * RUN: grep {%build_zext2 = zext i8 %build_trunc to i32} < %t.ll
* RUN: grep {%build_sext = sext i32 %build_zext to i64} < %t.ll
+ * RUN: grep {%build_sext2 = sext i32 %build_zext to i64} < %t.ll
+ * RUN: grep {%build_sext3 = sext i32 %build_zext to i64} < %t.ll
* RUN: grep {%build_uitofp = uitofp i64 %build_sext to float} < %t.ll
* RUN: grep {%build_sitofp = sitofp i32 %build_zext to double} < %t.ll
* RUN: grep {%build_fptoui = fptoui float %build_uitofp to i32} < %t.ll
* RUN: grep {%build_fptosi = fptosi double %build_sitofp to i64} < %t.ll
* RUN: grep {%build_fptrunc = fptrunc double %build_sitofp to float} < %t.ll
+ * RUN: grep {%build_fptrunc2 = fptrunc double %build_sitofp to float} < %t.ll
* RUN: grep {%build_fpext = fpext float %build_fptrunc to double} < %t.ll
+ * RUN: grep {%build_fpext2 = fpext float %build_fptrunc to double} < %t.ll
* RUN: grep {%build_inttoptr = inttoptr i32 %P1 to i8\\*} < %t.ll
* RUN: grep {%build_ptrtoint = ptrtoint i8\\* %build_inttoptr to i64} < %t.ll
+ * RUN: grep {%build_ptrtoint2 = ptrtoint i8\\* %build_inttoptr to i64} < %t.ll
* RUN: grep {%build_bitcast = bitcast i64 %build_ptrtoint to double} < %t.ll
+ * RUN: grep {%build_bitcast2 = bitcast i64 %build_ptrtoint to double} < %t.ll
+ * RUN: grep {%build_bitcast3 = bitcast i64 %build_ptrtoint to double} < %t.ll
+ * RUN: grep {%build_bitcast4 = bitcast i64 %build_ptrtoint to double} < %t.ll
+ * RUN: grep {%build_pointercast = bitcast i8\\* %build_inttoptr to i16\\*} < %t.ll
*)
let inst28 = build_trunc p1 i8_type "build_trunc" atentry in
let inst29 = build_zext inst28 i32_type "build_zext" atentry in
@@ -1027,7 +1126,20 @@ let test_builder () =
ignore(build_fpext inst35 double_type "build_fpext" atentry);
let inst37 = build_inttoptr p1 void_ptr "build_inttoptr" atentry in
let inst38 = build_ptrtoint inst37 i64_type "build_ptrtoint" atentry in
- ignore(build_bitcast inst38 double_type "build_bitcast" atentry)
+ ignore(build_bitcast inst38 double_type "build_bitcast" atentry);
+ ignore(build_zext_or_bitcast inst38 double_type "build_bitcast2" atentry);
+ ignore(build_sext_or_bitcast inst38 double_type "build_bitcast3" atentry);
+ ignore(build_trunc_or_bitcast inst38 double_type "build_bitcast4" atentry);
+ ignore(build_pointercast inst37 (pointer_type i16_type) "build_pointercast" atentry);
+
+ ignore(build_zext_or_bitcast inst28 i32_type "build_zext2" atentry);
+ ignore(build_sext_or_bitcast inst29 i64_type "build_sext2" atentry);
+ ignore(build_trunc_or_bitcast p1 i8_type "build_trunc2" atentry);
+ ignore(build_pointercast inst37 i64_type "build_ptrtoint2" atentry);
+ ignore(build_intcast inst29 i64_type "build_sext3" atentry);
+ ignore(build_intcast p1 i8_type "build_trunc3" atentry);
+ ignore(build_fpcast inst35 double_type "build_fpext2" atentry);
+ ignore(build_fpcast inst32 float_type "build_fptrunc2" atentry);
end;
group "comparisons"; begin
@@ -1035,11 +1147,21 @@ let test_builder () =
* RUN: grep {%build_icmp_sle = icmp sle i32 %P2, %P1} < %t.ll
* RUN: grep {%build_fcmp_false = fcmp false float %F1, %F2} < %t.ll
* RUN: grep {%build_fcmp_true = fcmp true float %F2, %F1} < %t.ll
+ * RUN: grep {%build_is_null.*= icmp eq.*%X0,.*null} < %t.ll
+ * RUN: grep {%build_is_not_null = icmp ne i8\\* %X1, null} < %t.ll
+ * RUN: grep {%build_ptrdiff} < %t.ll
*)
ignore (build_icmp Icmp.Ne p1 p2 "build_icmp_ne" atentry);
ignore (build_icmp Icmp.Sle p2 p1 "build_icmp_sle" atentry);
ignore (build_fcmp Fcmp.False f1 f2 "build_fcmp_false" atentry);
- ignore (build_fcmp Fcmp.True f2 f1 "build_fcmp_true" atentry)
+ ignore (build_fcmp Fcmp.True f2 f1 "build_fcmp_true" atentry);
+ let g0 = declare_global (pointer_type i8_type) "g0" m in
+ let g1 = declare_global (pointer_type i8_type) "g1" m in
+ let p0 = build_load g0 "X0" atentry in
+ let p1 = build_load g1 "X1" atentry in
+ ignore (build_is_null p0 "build_is_null" atentry);
+ ignore (build_is_not_null p1 "build_is_not_null" atentry);
+ ignore (build_ptrdiff p1 p0 "build_ptrdiff" atentry);
end;
group "miscellaneous"; begin
@@ -1049,6 +1171,8 @@ let test_builder () =
* RUN: grep {%build_extractelement = extractelement <4 x i32> %Vec1, i32 %P2} < %t.ll
* RUN: grep {%build_insertelement = insertelement <4 x i32> %Vec1, i32 %P1, i32 %P2} < %t.ll
* RUN: grep {%build_shufflevector = shufflevector <4 x i32> %Vec1, <4 x i32> %Vec2, <4 x i32> <i32 1, i32 1, i32 0, i32 0>} < %t.ll
+ * RUN: grep {%build_insertvalue0 = insertvalue.*%bl, i32 1, 0} < %t.ll
+ * RUN: grep {%build_extractvalue = extractvalue.*%build_insertvalue1, 1} < %t.ll
*)
let ci = build_call fn [| p2; p1 |] "build_call" atentry in
insist (CallConv.c = instruction_call_conv ci);
@@ -1075,10 +1199,19 @@ let test_builder () =
let t3 = const_vector [| one; one; zero; zero |] in
let vec1 = build_insertelement t1 p1 p2 "Vec1" atentry in
let vec2 = build_insertelement t2 p1 p2 "Vec2" atentry in
+ let sty = struct_type context [| i32_type; i8_type |] in
ignore (build_extractelement vec1 p2 "build_extractelement" atentry);
ignore (build_insertelement vec1 p1 p2 "build_insertelement" atentry);
ignore (build_shufflevector vec1 vec2 t3 "build_shufflevector" atentry);
+
+ let p = build_alloca sty "ba" atentry in
+ let agg = build_load p "bl" atentry in
+ let agg0 = build_insertvalue agg (const_int i32_type 1) 0
+ "build_insertvalue0" atentry in
+ let agg1 = build_insertvalue agg0 (const_int i8_type 2) 1
+ "build_insertvalue1" atentry in
+ ignore (build_extractvalue agg1 1 "build_extractvalue" atentry)
end;
group "metadata"; begin