(* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_analysis.cmxa llvm_bitwriter.cmxa %s -o %t
* RUN: %t %t.bc
* RUN: llvm-dis < %t.bc > %t.ll
+ * XFAIL: vg_leak
*)
(* Note: It takes several seconds for ocamlopt to link an executable with
insist (layout = data_layout m)
end
-(*===-- Types -------------------------------------------------------------===*)
-
-let test_types () =
- (* RUN: grep {void_type.*void} < %t.ll
- *)
- group "void";
- insist (define_type_name "void_type" void_type m);
- insist (TypeKind.Void == classify_type void_type);
-
- (* RUN: grep {i1_type.*i1} < %t.ll
- *)
- group "i1";
- insist (define_type_name "i1_type" i1_type m);
- insist (TypeKind.Integer == classify_type i1_type);
-
- (* RUN: grep {i32_type.*i32} < %t.ll
- *)
- group "i32";
- insist (define_type_name "i32_type" i32_type m);
-
- (* RUN: grep {i42_type.*i42} < %t.ll
- *)
- group "i42";
- let ty = integer_type context 42 in
- insist (define_type_name "i42_type" ty m);
-
- (* RUN: grep {float_type.*float} < %t.ll
- *)
- group "float";
- insist (define_type_name "float_type" float_type m);
- insist (TypeKind.Float == classify_type float_type);
-
- (* RUN: grep {double_type.*double} < %t.ll
- *)
- group "double";
- insist (define_type_name "double_type" double_type m);
- insist (TypeKind.Double == classify_type double_type);
-
- (* RUN: grep {function_type.*i32.*i1, double} < %t.ll
- *)
- group "function";
- let ty = function_type i32_type [| i1_type; double_type |] in
- insist (define_type_name "function_type" ty m);
- insist (TypeKind.Function = classify_type ty);
- insist (not (is_var_arg ty));
- insist (i32_type == return_type ty);
- insist (double_type == (param_types ty).(1));
-
- (* RUN: grep {var_arg_type.*\.\.\.} < %t.ll
- *)
- group "var arg function";
- let ty = var_arg_function_type void_type [| i32_type |] in
- insist (define_type_name "var_arg_type" ty m);
- insist (is_var_arg ty);
-
- (* RUN: grep {array_type.*\\\[7 x i8\\\]} < %t.ll
- *)
- group "array";
- let ty = array_type i8_type 7 in
- insist (define_type_name "array_type" ty m);
- insist (7 = array_length ty);
- insist (i8_type == element_type ty);
- insist (TypeKind.Array == classify_type ty);
-
- begin group "pointer";
- (* RUN: grep {pointer_type.*float\*} < %t.ll
- *)
- let ty = pointer_type float_type in
- insist (define_type_name "pointer_type" ty m);
- insist (float_type == element_type ty);
- insist (0 == address_space ty);
- insist (TypeKind.Pointer == classify_type ty)
- end;
-
- begin group "qualified_pointer";
- (* RUN: grep {qualified_pointer_type.*i8.*3.*\*} < %t.ll
- *)
- let ty = qualified_pointer_type i8_type 3 in
- insist (define_type_name "qualified_pointer_type" ty m);
- insist (i8_type == element_type ty);
- insist (3 == address_space ty)
- end;
-
- (* RUN: grep {vector_type.*\<4 x i16\>} < %t.ll
- *)
- group "vector";
- let ty = vector_type i16_type 4 in
- insist (define_type_name "vector_type" ty m);
- insist (i16_type == element_type ty);
- insist (4 = vector_size ty);
-
- (* RUN: grep {opaque_type.*opaque} < %t.ll
- *)
- group "opaque";
- let ty = opaque_type context in
- insist (define_type_name "opaque_type" ty m);
- insist (ty == ty);
- insist (ty <> opaque_type context);
-
- (* RUN: grep -v {delete_type} < %t.ll
- *)
- group "delete";
- let ty = opaque_type context in
- insist (define_type_name "delete_type" ty m);
- delete_type_name "delete_type" m;
-
- (* RUN: grep {type_name.*opaque} < %t.ll
- *)
- group "type_name"; begin
- let ty = opaque_type context in
- insist (define_type_name "type_name" ty m);
- insist ((type_by_name m "type_name") = Some ty)
- end;
-
- (* RUN: grep -v {recursive_type.*recursive_type} < %t.ll
- *)
- group "recursive";
- let ty = opaque_type context in
- let th = handle_to_type ty in
- refine_type ty (pointer_type ty);
- let ty = type_of_handle th in
- insist (define_type_name "recursive_type" ty m);
- insist (ty == element_type ty)
-
(*===-- 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
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
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
*)
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
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
* 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
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
* 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
* 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);
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
let _ =
suite "target" test_target;
- suite "types" test_types;
suite "constants" test_constants;
suite "global values" test_global_values;
suite "global variables" test_global_variables;