X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=test%2FBindings%2FOcaml%2Fvmcore.ml;h=53e0553b0d599ecc50b3d22768d48b2fa03a3bcf;hp=44cdd84ac186e30c1fd37a48df11b4ed6ac4e292;hb=acdcb3773d085eef413385a1c24ea78f01657bcd;hpb=5b0a7741ad262315d6365250a2da2edb8ba37e69 diff --git a/test/Bindings/Ocaml/vmcore.ml b/test/Bindings/Ocaml/vmcore.ml index 44cdd84ac18..53e0553b0d5 100644 --- a/test/Bindings/Ocaml/vmcore.ml +++ b/test/Bindings/Ocaml/vmcore.ml @@ -1,6 +1,13 @@ -(* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_analysis.cmxa llvm_bitwriter.cmxa %s -o %t - * RUN: ./%t %t.bc +(* RUN: rm -rf %t.builddir + * RUN: mkdir -p %t.builddir + * RUN: cp %s %t.builddir + * RUN: %ocamlopt -warn-error A llvm.cmxa llvm_analysis.cmxa llvm_bitwriter.cmxa %t.builddir/vmcore.ml -o %t + * RUN: %t %t.bc * RUN: llvm-dis < %t.bc > %t.ll + * RUN: FileCheck %s < %t.ll + * Do a second pass for things that shouldn't be anywhere. + * RUN: FileCheck -check-prefix=CHECK-NOWHERE %s < %t.ll + * XFAIL: vg_leak *) (* Note: It takes several seconds for ocamlopt to link an executable with @@ -58,157 +65,39 @@ let suite name f = let filename = Sys.argv.(1) let m = create_module context filename -let mp = ModuleProvider.create m + + +(*===-- Conversion --------------------------------------------------------===*) + +let test_conversion () = + insist ("i32" = (string_of_lltype i32_type)); + let c = const_int i32_type 42 in + insist ("i32 42" = (string_of_llvalue c)) (*===-- Target ------------------------------------------------------------===*) let test_target () = begin group "triple"; - (* RUN: grep "i686-apple-darwin8" < %t.ll - *) let trip = "i686-apple-darwin8" in set_target_triple trip m; insist (trip = target_triple m) end; begin group "layout"; - (* RUN: grep "bogus" < %t.ll - *) - let layout = "bogus" in + let layout = "e" in set_data_layout layout m; 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 + (* CHECK: target datalayout = "e" + * CHECK: target triple = "i686-apple-darwin8" *) - 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 ---------------------------------------------------------===*) let test_constants () = - (* RUN: grep {const_int.*i32.*-1} < %t.ll + (* CHECK: const_int{{.*}}i32{{.*}}-1 *) group "int"; let c = const_int i32_type (-1) in @@ -216,44 +105,50 @@ let test_constants () = insist (i32_type = type_of c); insist (is_constant c); - (* RUN: grep {const_sext_int.*i64.*-1} < %t.ll + (* CHECK: const_sext_int{{.*}}i64{{.*}}-1 *) group "sext int"; let c = const_int i64_type (-1) in ignore (define_global "const_sext_int" c m); insist (i64_type = type_of c); - (* RUN: grep {const_zext_int64.*i64.*4294967295} < %t.ll + (* CHECK: const_zext_int64{{.*}}i64{{.*}}4294967295 *) group "zext int64"; let c = const_of_int64 i64_type (Int64.of_string "4294967295") false in ignore (define_global "const_zext_int64" c m); insist (i64_type = type_of c); - (* RUN: grep {const_int_string.*i32.*-1} < %t.ll + (* CHECK: const_int_string{{.*}}i32{{.*}}-1 *) group "int string"; let c = const_int_of_string i32_type "-1" 10 in ignore (define_global "const_int_string" c m); insist (i32_type = type_of c); - (* RUN: grep {const_string.*"cruel\\\\00world"} < %t.ll + if Sys.word_size = 64; then begin + group "long int"; + let c = const_int i64_type (1 lsl 61) in + insist (c = const_of_int64 i64_type (Int64.of_int (1 lsl 61)) false) + end; + + (* CHECK: @const_string = global {{.*}}c"cruel\00world" *) group "string"; let c = const_string context "cruel\000world" in ignore (define_global "const_string" c m); insist ((array_type i8_type 11) = type_of c); - (* RUN: grep {const_stringz.*"hi\\\\00again\\\\00"} < %t.ll + (* CHECK: const_stringz{{.*}}"hi\00again\00" *) group "stringz"; let c = const_stringz context "hi\000again" in ignore (define_global "const_stringz" c m); insist ((array_type i8_type 9) = type_of c); - (* RUN: grep {const_single.*2.75} < %t.ll - * RUN: grep {const_double.*3.1459} < %t.ll - * RUN: grep {const_double_string.*1.25} < %t.ll + (* CHECK: const_single{{.*}}2.75 + * CHECK: const_double{{.*}}3.1459 + * CHECK: const_double_string{{.*}}1.25 *) begin group "real"; let cs = const_float float_type 2.75 in @@ -274,14 +169,14 @@ let test_constants () = let three = const_int i32_type 3 in let four = const_int i32_type 4 in - (* RUN: grep {const_array.*\\\[i32 3, i32 4\\\]} < %t.ll + (* CHECK: const_array{{.*}}[i32 3, i32 4] *) group "array"; let c = const_array i32_type [| three; four |] in ignore (define_global "const_array" c m); insist ((array_type i32_type 2) = (type_of c)); - (* RUN: grep {const_vector.*} < %t.ll + (* CHECK: const_vector{{.*}} *) group "vector"; let c = const_vector [| one; two; one; two; @@ -289,7 +184,7 @@ let test_constants () = ignore (define_global "const_vector" c m); insist ((vector_type i16_type 8) = (type_of c)); - (* RUN: grep {const_structure.*.i16 1, i16 2, i32 3, i32 4} < %t.ll + (* CHECK: const_structure{{.*.}}i16 1, i16 2, i32 3, i32 4 *) group "structure"; let c = const_struct context [| one; two; three; four |] in @@ -297,33 +192,27 @@ let test_constants () = insist ((struct_type context [| i16_type; i16_type; i32_type; i32_type |]) = (type_of c)); - group "union"; - let t = union_type context [| i1_type; i16_type; i64_type; double_type |] in - let c = const_union t one in - ignore (define_global "const_union" c m); - insist (t = (type_of c)); - - (* RUN: grep {const_null.*zeroinit} < %t.ll + (* CHECK: const_null{{.*}}zeroinit *) group "null"; let c = const_null (packed_struct_type context [| i1_type; i8_type; i64_type; double_type |]) in ignore (define_global "const_null" c m); - (* RUN: grep {const_all_ones.*-1} < %t.ll + (* CHECK: const_all_ones{{.*}}-1 *) group "all ones"; let c = const_all_ones i64_type in ignore (define_global "const_all_ones" c m); group "pointer null"; begin - (* RUN: grep {const_pointer_null = global i64\\* null} < %t.ll + (* CHECK: const_pointer_null = global i64* null *) let c = const_pointer_null (pointer_type i64_type) in ignore (define_global "const_pointer_null" c m); end; - (* RUN: grep {const_undef.*undef} < %t.ll + (* CHECK: const_undef{{.*}}undef *) group "undef"; let c = undef i1_type in @@ -332,35 +221,35 @@ let test_constants () = insist (is_undef c); group "constant arithmetic"; - (* RUN: grep {@const_neg = global i64 sub} < %t.ll - * RUN: grep {@const_nsw_neg = global i64 sub nsw } < %t.ll - * RUN: grep {@const_nuw_neg = global i64 sub nuw } < %t.ll - * RUN: grep {@const_fneg = global double fsub } < %t.ll - * RUN: grep {@const_not = global i64 xor } < %t.ll - * RUN: grep {@const_add = global i64 add } < %t.ll - * RUN: grep {@const_nsw_add = global i64 add nsw } < %t.ll - * RUN: grep {@const_nuw_add = global i64 add nuw } < %t.ll - * RUN: grep {@const_fadd = global double fadd } < %t.ll - * RUN: grep {@const_sub = global i64 sub } < %t.ll - * RUN: grep {@const_nsw_sub = global i64 sub nsw } < %t.ll - * RUN: grep {@const_nuw_sub = global i64 sub nuw } < %t.ll - * RUN: grep {@const_fsub = global double fsub } < %t.ll - * RUN: grep {@const_mul = global i64 mul } < %t.ll - * RUN: grep {@const_nsw_mul = global i64 mul nsw } < %t.ll - * RUN: grep {@const_nuw_mul = global i64 mul nuw } < %t.ll - * RUN: grep {@const_fmul = global double fmul } < %t.ll - * RUN: grep {@const_udiv = global i64 udiv } < %t.ll - * RUN: grep {@const_sdiv = global i64 sdiv } < %t.ll - * RUN: grep {@const_exact_sdiv = global i64 sdiv exact } < %t.ll - * RUN: grep {@const_fdiv = global double fdiv } < %t.ll - * RUN: grep {@const_urem = global i64 urem } < %t.ll - * RUN: grep {@const_srem = global i64 srem } < %t.ll - * RUN: grep {@const_frem = global double frem } < %t.ll - * RUN: grep {@const_and = global i64 and } < %t.ll - * RUN: grep {@const_or = global i64 or } < %t.ll - * RUN: grep {@const_xor = global i64 xor } < %t.ll - * RUN: grep {@const_icmp = global i1 icmp sle } < %t.ll - * RUN: grep {@const_fcmp = global i1 fcmp ole } < %t.ll + (* CHECK: @const_neg = global i64 sub + * CHECK: @const_nsw_neg = global i64 sub nsw + * CHECK: @const_nuw_neg = global i64 sub nuw + * CHECK: @const_fneg = global double fsub + * CHECK: @const_not = global i64 xor + * CHECK: @const_add = global i64 add + * CHECK: @const_nsw_add = global i64 add nsw + * CHECK: @const_nuw_add = global i64 add nuw + * CHECK: @const_fadd = global double fadd + * CHECK: @const_sub = global i64 sub + * CHECK: @const_nsw_sub = global i64 sub nsw + * CHECK: @const_nuw_sub = global i64 sub nuw + * CHECK: @const_fsub = global double fsub + * CHECK: @const_mul = global i64 mul + * CHECK: @const_nsw_mul = global i64 mul nsw + * CHECK: @const_nuw_mul = global i64 mul nuw + * CHECK: @const_fmul = global double fmul + * CHECK: @const_udiv = global i64 udiv + * CHECK: @const_sdiv = global i64 sdiv + * CHECK: @const_exact_sdiv = global i64 sdiv exact + * CHECK: @const_fdiv = global double fdiv + * CHECK: @const_urem = global i64 urem + * CHECK: @const_srem = global i64 srem + * CHECK: @const_frem = global double frem + * CHECK: @const_and = global i64 and + * CHECK: @const_or = global i64 or + * CHECK: @const_xor = global i64 xor + * CHECK: @const_icmp = global i1 icmp sle + * CHECK: @const_fcmp = global i1 fcmp ole *) let void_ptr = pointer_type i8_type in let five = const_int i64_type 5 in @@ -399,18 +288,19 @@ let test_constants () = ignore (define_global "const_fcmp" (const_fcmp Fcmp.Ole ffoldbomb ffive) m); group "constant casts"; - (* RUN: grep {const_trunc.*trunc} < %t.ll - * RUN: grep {const_sext.*sext} < %t.ll - * RUN: grep {const_zext.*zext} < %t.ll - * RUN: grep {const_fptrunc.*fptrunc} < %t.ll - * RUN: grep {const_fpext.*fpext} < %t.ll - * RUN: grep {const_uitofp.*uitofp} < %t.ll - * RUN: grep {const_sitofp.*sitofp} < %t.ll - * RUN: grep {const_fptoui.*fptoui} < %t.ll - * RUN: grep {const_fptosi.*fptosi} < %t.ll - * RUN: grep {const_ptrtoint.*ptrtoint} < %t.ll - * RUN: grep {const_inttoptr.*inttoptr} < %t.ll - * RUN: grep {const_bitcast.*bitcast} < %t.ll + (* CHECK: const_trunc{{.*}}trunc + * CHECK: const_sext{{.*}}sext + * CHECK: const_zext{{.*}}zext + * CHECK: const_fptrunc{{.*}}fptrunc + * CHECK: const_fpext{{.*}}fpext + * CHECK: const_uitofp{{.*}}uitofp + * CHECK: const_sitofp{{.*}}sitofp + * CHECK: const_fptoui{{.*}}fptoui + * CHECK: const_fptosi{{.*}}fptosi + * CHECK: const_ptrtoint{{.*}}ptrtoint + * CHECK: const_inttoptr{{.*}}inttoptr + * CHECK: const_bitcast{{.*}}bitcast + * CHECK: const_intcast{{.*}}zext *) let i128_type = integer_type context 128 in ignore (define_global "const_trunc" (const_trunc (const_add foldbomb five) @@ -430,14 +320,16 @@ let test_constants () = ignore (define_global "const_inttoptr" (const_inttoptr (const_add foldbomb five) void_ptr) m); ignore (define_global "const_bitcast" (const_bitcast ffoldbomb i64_type) m); + ignore (define_global "const_intcast" + (const_intcast foldbomb i128_type ~is_signed:false) m); group "misc constants"; - (* RUN: grep {const_size_of.*getelementptr.*null} < %t.ll - * RUN: grep {const_gep.*getelementptr} < %t.ll - * RUN: grep {const_select.*select} < %t.ll - * RUN: grep {const_extractelement.*extractelement} < %t.ll - * RUN: grep {const_insertelement.*insertelement} < %t.ll - * RUN: grep {const_shufflevector.*shufflevector} < %t.ll + (* CHECK: const_size_of{{.*}}getelementptr{{.*}}null + * CHECK: const_gep{{.*}}getelementptr + * CHECK: const_select{{.*}}select + * CHECK: const_extractelement{{.*}}extractelement + * CHECK: const_insertelement{{.*}}insertelement + * CHECK: const_shufflevector = global <4 x i32> *) ignore (define_global "const_size_of" (size_of (pointer_type i8_type)) m); ignore (define_global "const_gep" (const_gep foldbomb_gv [| five |]) m); @@ -456,7 +348,28 @@ let test_constants () = ignore (define_global "const_shufflevector" (const_shufflevector (const_vector [| zero; one |]) (const_vector [| one; zero |]) - (const_bitcast foldbomb (vector_type i32_type 2))) m) + (const_vector [| const_int i32_type 0; const_int i32_type 1; + const_int i32_type 2; const_int i32_type 3 |])) m); + + group "asm"; begin + let ft = function_type void_type [| i32_type; i32_type; i32_type |] in + ignore (const_inline_asm + ft + "" + "{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 (*===-- Global Values -----------------------------------------------------===*) @@ -465,7 +378,7 @@ let test_global_values () = let (++) x f = f x; x in let zero32 = const_null i32_type in - (* RUN: grep {GVal01} < %t.ll + (* CHECK: GVal01 *) group "naming"; let g = define_global "TEMPORARY" zero32 m in @@ -473,28 +386,28 @@ let test_global_values () = set_value_name "GVal01" g; insist ("GVal01" = value_name g); - (* RUN: grep {GVal02.*linkonce} < %t.ll + (* CHECK: GVal02{{.*}}linkonce *) group "linkage"; let g = define_global "GVal02" zero32 m ++ set_linkage Linkage.Link_once in insist (Linkage.Link_once = linkage g); - (* RUN: grep {GVal03.*Hanalei} < %t.ll + (* CHECK: GVal03{{.*}}Hanalei *) group "section"; let g = define_global "GVal03" zero32 m ++ set_section "Hanalei" in insist ("Hanalei" = section g); - (* RUN: grep {GVal04.*hidden} < %t.ll + (* CHECK: GVal04{{.*}}hidden *) group "visibility"; let g = define_global "GVal04" zero32 m ++ set_visibility Visibility.Hidden in insist (Visibility.Hidden = visibility g); - (* RUN: grep {GVal05.*align 128} < %t.ll + (* CHECK: GVal05{{.*}}align 128 *) group "alignment"; let g = define_global "GVal05" zero32 m ++ @@ -506,10 +419,11 @@ let test_global_values () = let test_global_variables () = let (++) x f = f x; x in - let fourty_two32 = const_int i32_type 42 in + let forty_two32 = const_int i32_type 42 in group "declarations"; begin - (* RUN: grep {GVar01.*external} < %t.ll + (* CHECK: @GVar01 = external global i32 + * CHECK: @QGVar01 = external addrspace(3) global i32 *) insist (None == lookup_global "GVar01" m); let g = declare_global i32_type "GVar01" m in @@ -531,41 +445,57 @@ let test_global_variables () = end; group "definitions"; begin - (* RUN: grep {GVar02.*42} < %t.ll - * RUN: grep {GVar03.*42} < %t.ll + (* CHECK: @GVar02 = global i32 42 + * CHECK: @GVar03 = global i32 42 + * CHECK: @QGVar02 = addrspace(3) global i32 42 + * CHECK: @QGVar03 = addrspace(3) global i32 42 *) - let g = define_global "GVar02" fourty_two32 m in + let g = define_global "GVar02" forty_two32 m in let g2 = declare_global i32_type "GVar03" m ++ - set_initializer fourty_two32 in + set_initializer forty_two32 in insist (not (is_declaration g)); insist (not (is_declaration g2)); insist ((global_initializer g) == (global_initializer g2)); - let g = define_qualified_global "QGVar02" fourty_two32 3 m in + let g = define_qualified_global "QGVar02" forty_two32 3 m in let g2 = declare_qualified_global i32_type "QGVar03" 3 m ++ - set_initializer fourty_two32 in + set_initializer forty_two32 in insist (not (is_declaration g)); insist (not (is_declaration g2)); insist ((global_initializer g) == (global_initializer g2)); end; - (* RUN: grep {GVar04.*thread_local} < %t.ll + (* CHECK: GVar04{{.*}}thread_local *) group "threadlocal"; - let g = define_global "GVar04" fourty_two32 m ++ + let g = define_global "GVar04" forty_two32 m ++ set_thread_local true in insist (is_thread_local g); - (* RUN: grep -v {GVar05} < %t.ll + (* CHECK: GVar05{{.*}}thread_local(initialexec) + *) + group "threadlocal_mode"; + let g = define_global "GVar05" forty_two32 m ++ + set_thread_local_mode ThreadLocalMode.InitialExec in + insist ((thread_local_mode g) = ThreadLocalMode.InitialExec); + + (* CHECK: GVar06{{.*}}externally_initialized + *) + group "externally_initialized"; + let g = define_global "GVar06" forty_two32 m ++ + set_externally_initialized true in + insist (is_externally_initialized g); + + (* CHECK-NOWHERE-NOT: GVar07 *) group "delete"; - let g = define_global "GVar05" fourty_two32 m in + let g = define_global "GVar07" forty_two32 m in delete_global g; - (* RUN: grep -v {ConstGlobalVar.*constant} < %t.ll + (* CHECK: ConstGlobalVar{{.*}}constant *) group "constant"; - let g = define_global "ConstGlobalVar" fourty_two32 m in + let g = define_global "ConstGlobalVar" forty_two32 m in insist (not (is_global_constant g)); set_global_constant true g; insist (is_global_constant g); @@ -596,6 +526,71 @@ let test_global_variables () = dispose_module m end +(* String globals built below are emitted here. + * CHECK: build_global_string{{.*}}stringval + *) + + +(*===-- Uses --------------------------------------------------------------===*) + +let test_uses () = + let ty = function_type i32_type [| i32_type; i32_type |] in + let fn = define_function "use_function" ty m in + let b = builder_at_end context (entry_block fn) in + + let p1 = param fn 0 in + let p2 = param fn 1 in + let v1 = build_add p1 p2 "v1" b in + let v2 = build_add p1 v1 "v2" b in + let _ = build_add v1 v2 "v3" b in + + let lf s u = value_name (user u) ^ "->" ^ s in + insist ("v2->v3->" = fold_left_uses lf "" v1); + let rf u s = value_name (user u) ^ "<-" ^ s in + insist ("v3<-v2<-" = fold_right_uses rf v1 ""); + + let lf s u = value_name (used_value u) ^ "->" ^ s in + insist ("v1->v1->" = fold_left_uses lf "" v1); + + let rf u s = value_name (used_value u) ^ "<-" ^ s in + insist ("v1<-v1<-" = fold_right_uses rf v1 ""); + + ignore (build_unreachable b) + + +(*===-- Users -------------------------------------------------------------===*) + +let test_users () = + let ty = function_type i32_type [| i32_type; i32_type |] in + let fn = define_function "user_function" ty m in + let b = builder_at_end context (entry_block fn) in + + let p1 = param fn 0 in + let p2 = param fn 1 in + let a3 = build_alloca i32_type "user_alloca" b in + let p3 = build_load a3 "user_load" b in + let i = build_add p1 p2 "sum" b in + + insist ((num_operands i) = 2); + insist ((operand i 0) = p1); + insist ((operand i 1) = p2); + + set_operand i 1 p3; + insist ((operand i 1) != p2); + insist ((operand i 1) = p3); + + ignore (build_unreachable b) + + +(*===-- Aliases -----------------------------------------------------------===*) + +let test_aliases () = + (* CHECK: @alias = alias i32* @aliasee + *) + let forty_two32 = const_int i32_type 42 in + let v = define_global "aliasee" forty_two32 m in + ignore (add_alias m (pointer_type i32_type) v "alias") + (*===-- Functions ---------------------------------------------------------===*) @@ -603,7 +598,7 @@ let test_functions () = let ty = function_type i32_type [| i32_type; i64_type |] in let ty2 = function_type i8_type [| i8_type; i64_type |] in - (* RUN: grep {declare i32 @Fn1\(i32, i64\)} < %t.ll + (* CHECK: declare i32 @Fn1(i32, i64) *) begin group "declare"; insist (None = lookup_function "Fn1" m); @@ -619,13 +614,13 @@ let test_functions () = insist (m == global_parent fn) end; - (* RUN: grep -v {Fn2} < %t.ll + (* CHECK-NOWHERE-NOT: Fn2 *) group "delete"; let fn = declare_function "Fn2" ty m in delete_function fn; - (* RUN: grep {define.*Fn3} < %t.ll + (* CHECK: define{{.*}}Fn3 *) group "define"; let fn = define_function "Fn3" ty m in @@ -633,7 +628,7 @@ let test_functions () = insist (1 = Array.length (basic_blocks fn)); ignore (build_unreachable (builder_at_end context (entry_block fn))); - (* RUN: grep {define.*Fn4.*Param1.*Param2} < %t.ll + (* CHECK: define{{.*}}Fn4{{.*}}Param1{{.*}}Param2 *) group "params"; let fn = define_function "Fn4" ty m in @@ -647,7 +642,7 @@ let test_functions () = set_value_name "Param2" params.(1); ignore (build_unreachable (builder_at_end context (entry_block fn))); - (* RUN: grep {fastcc.*Fn5} < %t.ll + (* CHECK: fastcc{{.*}}Fn5 *) group "callconv"; let fn = define_function "Fn5" ty m in @@ -657,7 +652,7 @@ let test_functions () = ignore (build_unreachable (builder_at_end context (entry_block fn))); begin group "gc"; - (* RUN: grep {Fn6.*gc.*shadowstack} < %t.ll + (* CHECK: Fn6{{.*}}gc{{.*}}shadowstack *) let fn = define_function "Fn6" ty m in insist (None = gc fn); @@ -743,7 +738,7 @@ let test_params () = let test_basic_blocks () = let ty = function_type void_type [| |] in - (* RUN: grep {Bb1} < %t.ll + (* CHECK: Bb1 *) group "entry"; let fn = declare_function "X" ty m in @@ -751,7 +746,7 @@ let test_basic_blocks () = insist (bb = entry_block fn); ignore (build_unreachable (builder_at_end context bb)); - (* RUN: grep -v Bb2 < %t.ll + (* CHECK-NOWHERE-NOT: Bb2 *) group "delete"; let fn = declare_function "X2" ty m in @@ -766,7 +761,7 @@ let test_basic_blocks () = ignore (build_unreachable (builder_at_end context bba)); ignore (build_unreachable (builder_at_end context bbb)); - (* RUN: grep Bb3 < %t.ll + (* CHECK: Bb3 *) group "name/value"; let fn = define_function "X4" ty m in @@ -874,13 +869,25 @@ let test_builder () = group "ret void"; begin - (* RUN: grep {ret void} < %t.ll + (* CHECK: ret void *) let fty = function_type void_type [| |] in let fn = declare_function "X6" fty m in let b = builder_at_end context (append_block context "Bb01" fn) in ignore (build_ret_void b) end; + + group "ret aggregate"; + begin + (* CHECK: ret { i8, i64 } { i8 4, i64 5 } + *) + 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 @@ -893,16 +900,237 @@ 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); + (* CHECK: X7{{.*}}#0 + * #0 is uwtable, defined at EOF. + *) + insist ([Attribute.UWTable] = function_attr fn); + end; + + group "casts"; begin + let void_ptr = pointer_type i8_type in + + (* CHECK-DAG: %build_trunc = trunc i32 %P1 to i8 + * CHECK-DAG: %build_trunc2 = trunc i32 %P1 to i8 + * CHECK-DAG: %build_trunc3 = trunc i32 %P1 to i8 + * CHECK-DAG: %build_zext = zext i8 %build_trunc to i32 + * CHECK-DAG: %build_zext2 = zext i8 %build_trunc to i32 + * CHECK-DAG: %build_sext = sext i32 %build_zext to i64 + * CHECK-DAG: %build_sext2 = sext i32 %build_zext to i64 + * CHECK-DAG: %build_sext3 = sext i32 %build_zext to i64 + * CHECK-DAG: %build_uitofp = uitofp i64 %build_sext to float + * CHECK-DAG: %build_sitofp = sitofp i32 %build_zext to double + * CHECK-DAG: %build_fptoui = fptoui float %build_uitofp to i32 + * CHECK-DAG: %build_fptosi = fptosi double %build_sitofp to i64 + * CHECK-DAG: %build_fptrunc = fptrunc double %build_sitofp to float + * CHECK-DAG: %build_fptrunc2 = fptrunc double %build_sitofp to float + * CHECK-DAG: %build_fpext = fpext float %build_fptrunc to double + * CHECK-DAG: %build_fpext2 = fpext float %build_fptrunc to double + * CHECK-DAG: %build_inttoptr = inttoptr i32 %P1 to i8* + * CHECK-DAG: %build_ptrtoint = ptrtoint i8* %build_inttoptr to i64 + * CHECK-DAG: %build_ptrtoint2 = ptrtoint i8* %build_inttoptr to i64 + * CHECK-DAG: %build_bitcast = bitcast i64 %build_ptrtoint to double + * CHECK-DAG: %build_bitcast2 = bitcast i64 %build_ptrtoint to double + * CHECK-DAG: %build_bitcast3 = bitcast i64 %build_ptrtoint to double + * CHECK-DAG: %build_bitcast4 = bitcast i64 %build_ptrtoint to double + * CHECK-DAG: %build_pointercast = bitcast i8* %build_inttoptr to i16* + *) + let inst28 = build_trunc p1 i8_type "build_trunc" atentry in + let inst29 = build_zext inst28 i32_type "build_zext" atentry in + let inst30 = build_sext inst29 i64_type "build_sext" atentry in + let inst31 = build_uitofp inst30 float_type "build_uitofp" atentry in + let inst32 = build_sitofp inst29 double_type "build_sitofp" atentry in + ignore(build_fptoui inst31 i32_type "build_fptoui" atentry); + ignore(build_fptosi inst32 i64_type "build_fptosi" atentry); + let inst35 = build_fptrunc inst32 float_type "build_fptrunc" 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_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 + (* CHECK: %build_icmp_ne = icmp ne i32 %P1, %P2 + * CHECK: %build_icmp_sle = icmp sle i32 %P2, %P1 + * CHECK: %build_fcmp_false = fcmp false float %F1, %F2 + * CHECK: %build_fcmp_true = fcmp true float %F2, %F1 + * CHECK: %build_is_null{{.*}}= icmp eq{{.*}}%X0,{{.*}}null + * CHECK: %build_is_not_null = icmp ne i8* %X1, null + * CHECK: %build_ptrdiff + *) + 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); + 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 + (* CHECK: %build_call = tail call cc63 i32 @{{.*}}(i32 signext %P2, i32 %P1) + * CHECK: %build_select = select i1 %build_icmp, i32 %P1, i32 %P2 + * CHECK: %build_va_arg = va_arg i8** null, i32 + * CHECK: %build_extractelement = extractelement <4 x i32> %Vec1, i32 %P2 + * CHECK: %build_insertelement = insertelement <4 x i32> %Vec1, i32 %P1, i32 %P2 + * CHECK: %build_shufflevector = shufflevector <4 x i32> %Vec1, <4 x i32> %Vec2, <4 x i32> + * CHECK: %build_insertvalue0 = insertvalue{{.*}}%bl, i32 1, 0 + * CHECK: %build_extractvalue = extractvalue{{.*}}%build_insertvalue1, 1 + *) + let ci = build_call fn [| p2; p1 |] "build_call" atentry in + insist (CallConv.c = instruction_call_conv ci); + set_instruction_call_conv 63 ci; + insist (63 = instruction_call_conv ci); + insist (not (is_tail_call ci)); + set_tail_call true ci; + insist (is_tail_call ci); + add_instruction_param_attr ci 1 Attribute.Sext; + add_instruction_param_attr ci 2 Attribute.Noalias; + remove_instruction_param_attr ci 2 Attribute.Noalias; + + let inst46 = build_icmp Icmp.Eq p1 p2 "build_icmp" atentry in + ignore (build_select inst46 p1 p2 "build_select" atentry); + ignore (build_va_arg + (const_null (pointer_type (pointer_type i8_type))) + i32_type "build_va_arg" atentry); + + (* Set up some vector vregs. *) + let one = const_int i32_type 1 in + let zero = const_int i32_type 0 in + let t1 = const_vector [| one; zero; one; zero |] in + let t2 = const_vector [| zero; one; zero; one |] in + 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 + (* CHECK: %metadata = add i32 %P1, %P2, !test !1 + * !1 is metadata emitted at EOF. + *) + let i = build_add p1 p2 "metadata" atentry in + insist ((has_metadata i) = false); + + let m1 = const_int i32_type 1 in + let m2 = mdstring context "metadata test" in + let md = mdnode context [| m1; m2 |] in + + let kind = mdkind_id context "test" in + set_metadata i kind md; + + insist ((has_metadata i) = true); + insist ((metadata i kind) = Some md); + + clear_metadata i kind; + + insist ((has_metadata i) = false); + insist ((metadata i kind) = None); + + set_metadata i kind md + end; + + group "named metadata"; begin + (* !llvm.module.flags is emitted at EOF. *) + let n1 = const_int i32_type 1 in + let n2 = mdstring context "Debug Info Version" in + let md = mdnode context [| n1; n2; n1 |] in + add_named_metadata_operand m "llvm.module.flags" md; + + insist ((get_named_metadata m "llvm.module.flags") = [| md |]) + end; + + group "dbg"; begin + (* CHECK: %dbg = add i32 %P1, %P2, !dbg !2 + * !2 is metadata emitted at EOF. + *) + insist ((current_debug_location atentry) = None); + + let m_line = const_int i32_type 2 in + let m_col = const_int i32_type 3 in + let m_scope = mdnode context [| |] in + let m_inlined = mdnode context [| |] in + let md = mdnode context [| m_line; m_col; m_scope; m_inlined |] in + set_current_debug_location atentry md; + + insist ((current_debug_location atentry) = Some md); + + let i = build_add p1 p2 "dbg" atentry in + insist ((has_metadata i) = true); + + clear_current_debug_location atentry + end; + group "ret"; begin - (* RUN: grep {ret.*P1} < %t.ll + (* CHECK: ret{{.*}}P1 *) let ret = build_ret p1 atentry in position_before ret atentry 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; + (* CHECK: landingpad{{.*}}personality{{.*}}__gxx_personality_v0 + * CHECK: cleanup + * CHECK: catch{{.*}}i8**{{.*}}@_ZTIc + * CHECK: filter{{.*}}@_ZTIPKc{{.*}}@_ZTId + * CHECK: resume + * *) + end; + group "br"; begin - (* RUN: grep {br.*Bb02} < %t.ll + (* CHECK: br{{.*}}Bb02 *) let bb02 = append_block context "Bb02" fn in let b = builder_at_end context bb02 in @@ -910,7 +1138,7 @@ let test_builder () = end; group "cond_br"; begin - (* RUN: grep {br.*build_br.*Bb03.*Bb00} < %t.ll + (* CHECK: br{{.*}}build_br{{.*}}Bb03{{.*}}Bb00 *) let bb03 = append_block context "Bb03" fn in let b = builder_at_end context bb03 in @@ -919,20 +1147,35 @@ let test_builder () = end; group "switch"; begin - (* RUN: grep {switch.*P1.*SwiBlock3} < %t.ll - * RUN: grep {2,.*SwiBlock2} < %t.ll + (* CHECK: switch{{.*}}P1{{.*}}SwiBlock3 + * CHECK: 2,{{.*}}SwiBlock2 *) let bb1 = append_block context "SwiBlock1" fn in let bb2 = append_block context "SwiBlock2" fn in 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 + (* CHECK: call{{.*}}@malloc(i32 ptrtoint + * CHECK: call{{.*}}@free(i8* + * CHECK: call{{.*}}@malloc(i32 % + *) + 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 - (* RUN: grep {indirectbr i8\\* blockaddress(@X7, %IBRBlock2), \\\[label %IBRBlock2, label %IBRBlock3\\\]} < %t.ll + (* CHECK: indirectbr i8* blockaddress(@X7, %IBRBlock2), [label %IBRBlock2, label %IBRBlock3] *) let bb1 = append_block context "IBRBlock1" fn in @@ -949,24 +1192,16 @@ let test_builder () = end; group "invoke"; begin - (* RUN: grep {build_invoke.*invoke.*P1.*P2} < %t.ll - * RUN: grep {to.*Bb04.*unwind.*Bb00} < %t.ll + (* CHECK: build_invoke{{.*}}invoke{{.*}}P1{{.*}}P2 + * CHECK: to{{.*}}Bb04{{.*}}unwind{{.*}}Bblpad *) 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 {unreachable} < %t.ll + (* CHECK: unreachable *) let bb06 = append_block context "Bb06" fn in let b = builder_at_end context bb06 in @@ -977,36 +1212,36 @@ let test_builder () = let bb07 = append_block context "Bb07" fn in let b = builder_at_end context bb07 in - (* RUN: grep {%build_add = add i32 %P1, %P2} < %t.ll - * RUN: grep {%build_nsw_add = add nsw i32 %P1, %P2} < %t.ll - * RUN: grep {%build_nuw_add = add nuw i32 %P1, %P2} < %t.ll - * RUN: grep {%build_fadd = fadd float %F1, %F2} < %t.ll - * RUN: grep {%build_sub = sub i32 %P1, %P2} < %t.ll - * RUN: grep {%build_nsw_sub = sub nsw i32 %P1, %P2} < %t.ll - * RUN: grep {%build_nuw_sub = sub nuw i32 %P1, %P2} < %t.ll - * RUN: grep {%build_fsub = fsub float %F1, %F2} < %t.ll - * RUN: grep {%build_mul = mul i32 %P1, %P2} < %t.ll - * RUN: grep {%build_nsw_mul = mul nsw i32 %P1, %P2} < %t.ll - * RUN: grep {%build_nuw_mul = mul nuw i32 %P1, %P2} < %t.ll - * RUN: grep {%build_fmul = fmul float %F1, %F2} < %t.ll - * RUN: grep {%build_udiv = udiv i32 %P1, %P2} < %t.ll - * RUN: grep {%build_sdiv = sdiv i32 %P1, %P2} < %t.ll - * RUN: grep {%build_exact_sdiv = sdiv exact i32 %P1, %P2} < %t.ll - * RUN: grep {%build_fdiv = fdiv float %F1, %F2} < %t.ll - * RUN: grep {%build_urem = urem i32 %P1, %P2} < %t.ll - * RUN: grep {%build_srem = srem i32 %P1, %P2} < %t.ll - * RUN: grep {%build_frem = frem float %F1, %F2} < %t.ll - * RUN: grep {%build_shl = shl i32 %P1, %P2} < %t.ll - * RUN: grep {%build_lshl = lshr i32 %P1, %P2} < %t.ll - * RUN: grep {%build_ashl = ashr i32 %P1, %P2} < %t.ll - * RUN: grep {%build_and = and i32 %P1, %P2} < %t.ll - * RUN: grep {%build_or = or i32 %P1, %P2} < %t.ll - * RUN: grep {%build_xor = xor i32 %P1, %P2} < %t.ll - * RUN: grep {%build_neg = sub i32 0, %P1} < %t.ll - * RUN: grep {%build_nsw_neg = sub nsw i32 0, %P1} < %t.ll - * RUN: grep {%build_nuw_neg = sub nuw i32 0, %P1} < %t.ll - * RUN: grep {%build_fneg = fsub float .*0.*, %F1} < %t.ll - * RUN: grep {%build_not = xor i32 %P1, -1} < %t.ll + (* CHECK: %build_add = add i32 %P1, %P2 + * CHECK: %build_nsw_add = add nsw i32 %P1, %P2 + * CHECK: %build_nuw_add = add nuw i32 %P1, %P2 + * CHECK: %build_fadd = fadd float %F1, %F2 + * CHECK: %build_sub = sub i32 %P1, %P2 + * CHECK: %build_nsw_sub = sub nsw i32 %P1, %P2 + * CHECK: %build_nuw_sub = sub nuw i32 %P1, %P2 + * CHECK: %build_fsub = fsub float %F1, %F2 + * CHECK: %build_mul = mul i32 %P1, %P2 + * CHECK: %build_nsw_mul = mul nsw i32 %P1, %P2 + * CHECK: %build_nuw_mul = mul nuw i32 %P1, %P2 + * CHECK: %build_fmul = fmul float %F1, %F2 + * CHECK: %build_udiv = udiv i32 %P1, %P2 + * CHECK: %build_sdiv = sdiv i32 %P1, %P2 + * CHECK: %build_exact_sdiv = sdiv exact i32 %P1, %P2 + * CHECK: %build_fdiv = fdiv float %F1, %F2 + * CHECK: %build_urem = urem i32 %P1, %P2 + * CHECK: %build_srem = srem i32 %P1, %P2 + * CHECK: %build_frem = frem float %F1, %F2 + * CHECK: %build_shl = shl i32 %P1, %P2 + * CHECK: %build_lshl = lshr i32 %P1, %P2 + * CHECK: %build_ashl = ashr i32 %P1, %P2 + * CHECK: %build_and = and i32 %P1, %P2 + * CHECK: %build_or = or i32 %P1, %P2 + * CHECK: %build_xor = xor i32 %P1, %P2 + * CHECK: %build_neg = sub i32 0, %P1 + * CHECK: %build_nsw_neg = sub nsw i32 0, %P1 + * CHECK: %build_nuw_neg = sub nuw i32 0, %P1 + * CHECK: %build_fneg = fsub float {{.*}}0{{.*}}, %F1 + * CHECK: %build_not = xor i32 %P1, -1 *) ignore (build_add p1 p2 "build_add" b); ignore (build_nsw_add p1 p2 "build_nsw_add" b); @@ -1045,143 +1280,59 @@ let test_builder () = let bb08 = append_block context "Bb08" fn in let b = builder_at_end context bb08 in - (* RUN: grep {%build_alloca = alloca i32} < %t.ll - * RUN: grep {%build_array_alloca = alloca i32, i32 %P2} < %t.ll - * 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 + (* CHECK: %build_alloca = alloca i32 + * CHECK: %build_array_alloca = alloca i32, i32 %P2 + * CHECK: %build_load = load volatile i32* %build_array_alloca, align 4 + * CHECK: store volatile i32 %P2, i32* %build_alloca, align 4 + * CHECK: %build_gep = getelementptr i32* %build_array_alloca, i32 %P2 + * CHECK: %build_in_bounds_gep = getelementptr inbounds i32* %build_array_alloca, i32 %P2 + * CHECK: %build_struct_gep = getelementptr inbounds{{.*}}%build_alloca2, i32 0, i32 1 + * CHECK: %build_atomicrmw = atomicrmw xchg i8* %p, i8 42 seq_cst *) 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_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_zext = zext i8 %build_trunc to i32} < %t.ll - * RUN: grep {%build_sext = 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_fpext = 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_bitcast = bitcast i64 %build_ptrtoint to double} < %t.ll - *) - let inst28 = build_trunc p1 i8_type "build_trunc" atentry in - let inst29 = build_zext inst28 i32_type "build_zext" atentry in - let inst30 = build_sext inst29 i64_type "build_sext" atentry in - let inst31 = build_uitofp inst30 float_type "build_uitofp" atentry in - let inst32 = build_sitofp inst29 double_type "build_sitofp" atentry in - ignore(build_fptoui inst31 i32_type "build_fptoui" atentry); - ignore(build_fptosi inst32 i64_type "build_fptosi" atentry); - let inst35 = build_fptrunc inst32 float_type "build_fptrunc" 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) - end; - - group "comparisons"; begin - (* RUN: grep {%build_icmp_ne = icmp ne i32 %P1, %P2} < %t.ll - * RUN: grep {%build_icmp_sle = icmp sle i32 %P2, %P1} < %t.ll - * RUN: grep {%build_icmp_false = fcmp false float %F1, %F2} < %t.ll - * RUN: grep {%build_icmp_true = fcmp true float %F2, %F1} < %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_icmp_false" atentry); - ignore (build_fcmp Fcmp.True f2 f1 "build_icmp_true" atentry) - end; - - group "miscellaneous"; begin - (* RUN: grep {%build_call = tail call cc63 i32 @.*(i32 signext %P2, i32 %P1)} < %t.ll - * RUN: grep {%build_select = select i1 %build_icmp, i32 %P1, i32 %P2} < %t.ll - * RUN: grep {%build_va_arg = va_arg i8\\*\\* null, i32} < %t.ll - * 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> } < %t.ll - *) - let ci = build_call fn [| p2; p1 |] "build_call" atentry in - insist (CallConv.c = instruction_call_conv ci); - set_instruction_call_conv 63 ci; - insist (63 = instruction_call_conv ci); - insist (not (is_tail_call ci)); - set_tail_call true ci; - insist (is_tail_call ci); - add_instruction_param_attr ci 1 Attribute.Sext; - add_instruction_param_attr ci 2 Attribute.Noalias; - remove_instruction_param_attr ci 2 Attribute.Noalias; - - let inst46 = build_icmp Icmp.Eq p1 p2 "build_icmp" atentry in - ignore (build_select inst46 p1 p2 "build_select" atentry); - ignore (build_va_arg - (const_null (pointer_type (pointer_type i8_type))) - i32_type "build_va_arg" atentry); - - (* Set up some vector vregs. *) - let one = const_int i32_type 1 in - let zero = const_int i32_type 0 in - let t1 = const_vector [| one; zero; one; zero |] in - let t2 = const_vector [| zero; one; zero; one |] in - 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 - - 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); - end; - group "metadata"; begin - (* RUN: grep {%metadata = add i32 %P1, %P2, !test !0} < %t.ll - * RUN: grep {!0 = metadata !\{i32 1, metadata !"metadata test"\}} < %t.ll - *) - let i = build_add p1 p2 "metadata" atentry in - insist ((has_metadata i) = false); - - let m1 = const_int i32_type 1 in - let m2 = mdstring context "metadata test" in - let md = mdnode context [| m1; m2 |] in - - let kind = mdkind_id context "test" in - set_metadata i kind md; - - insist ((has_metadata i) = true); - insist ((metadata i kind) = Some md); + let load = build_load array_alloca "build_load" b in + ignore(set_alignment 4 load); + ignore(set_volatile true load); + insist(true = is_volatile load); + insist(4 = alignment load); + + let store = build_store p2 alloca b in + ignore(set_volatile true store); + ignore(set_alignment 4 store); + insist(true = is_volatile store); + insist(4 = alignment store); + ignore(build_gep array_alloca [| p2 |] "build_gep" b); + ignore(build_in_bounds_gep array_alloca [| p2 |] "build_in_bounds_gep" b); - clear_metadata i kind; + 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); - insist ((has_metadata i) = false); - insist ((metadata i kind) = None); + let p = build_alloca i8_type "p" b in + ignore(build_atomicrmw AtomicRMWBinOp.Xchg p (const_int i8_type 42) + AtomicOrdering.SequentiallyConsistent false "build_atomicrmw" + b); - set_metadata i kind md + ignore(build_unreachable b) end; - group "dbg"; begin - (* RUN: grep {%dbg = add i32 %P1, %P2, !dbg !1} < %t.ll - * RUN: grep {!1 = metadata !\{i32 2, metadata !"dbg test"\}} < %t.ll - *) - let m1 = const_int i32_type 2 in - let m2 = mdstring context "dbg test" in - let md = mdnode context [| m1; m2 |] in - set_current_debug_location atentry md; - - let i = build_add p1 p2 "dbg" atentry in - insist ((has_metadata i) = true); - - clear_current_debug_location atentry + 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 + (* build_global_string is emitted above. + * CHECK: store{{.*}}build_global_string1{{.*}}p + * *) + 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 "phi"; begin - (* RUN: grep {PhiNode.*P1.*PhiBlock1.*P2.*PhiBlock2} < %t.ll + (* CHECK: PhiNode{{.*}}P1{{.*}}PhiBlock1{{.*}}P2{{.*}}PhiBlock2 *) let b1 = append_block context "PhiBlock1" fn in let b2 = append_block context "PhiBlock2" fn in @@ -1200,14 +1351,13 @@ let test_builder () = ignore (build_unreachable at_jb); end - -(*===-- Module Provider ---------------------------------------------------===*) - -let test_module_provider () = - let m = create_module context "test" in - let mp = ModuleProvider.create m in - ModuleProvider.dispose mp - +(* End-of-file checks for things like metdata and attributes. + * CHECK: attributes #0 = {{.*}}uwtable{{.*}} + * CHECK: !llvm.module.flags = !{!0} + * CHECK: !0 = metadata !{i32 1, metadata !"Debug Info Version", i32 1} + * CHECK: !1 = metadata !{i32 1, metadata !"metadata test"} + * CHECK: !2 = metadata !{i32 2, i32 3, metadata !3, metadata !3} + *) (*===-- Pass Managers -----------------------------------------------------===*) @@ -1225,7 +1375,7 @@ let test_pass_manager () = let fn = define_function "FunctionPassManager" fty m in ignore (build_ret_void (builder_at_end context (entry_block fn))); - ignore (PassManager.create_function mp + ignore (PassManager.create_function m ++ PassManager.initialize ++ PassManager.run_function fn ++ PassManager.finalize @@ -1233,6 +1383,14 @@ let test_pass_manager () = end +(*===-- Memory Buffer -----------------------------------------------------===*) + +let test_memory_buffer () = + group "memory buffer"; + let buf = MemoryBuffer.of_string "foobar" in + insist ((MemoryBuffer.as_string buf) = "foobar") + + (*===-- Writer ------------------------------------------------------------===*) let test_writer () = @@ -1244,23 +1402,26 @@ let test_writer () = group "writer"; insist (write_bitcode_file m filename); - ModuleProvider.dispose mp + dispose_module m (*===-- Driver ------------------------------------------------------------===*) let _ = + suite "conversion" test_conversion; suite "target" test_target; - suite "types" test_types; suite "constants" test_constants; suite "global values" test_global_values; suite "global variables" test_global_variables; + suite "uses" test_uses; + suite "users" test_users; + suite "aliases" test_aliases; suite "functions" test_functions; suite "params" test_params; suite "basic blocks" test_basic_blocks; suite "instructions" test_instructions; suite "builder" test_builder; - suite "module provider" test_module_provider; suite "pass manager" test_pass_manager; + suite "memory buffer" test_memory_buffer; suite "writer" test_writer; (* Keep this last; it disposes m. *) exit !exit_status