diff options
author | Stephen Hines <srhines@google.com> | 2014-12-01 14:51:49 -0800 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-12-02 16:08:10 -0800 |
commit | 37ed9c199ca639565f6ce88105f9e39e898d82d0 (patch) | |
tree | 8fb36d3910e3ee4c4e1b7422f4f017108efc52f5 /test/Bindings | |
parent | d2327b22152ced7bc46dc629fc908959e8a52d03 (diff) | |
download | external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.zip external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.gz external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.bz2 |
Update aosp/master LLVM for rebase to r222494.
Change-Id: Ic787f5e0124df789bd26f3f24680f45e678eef2d
Diffstat (limited to 'test/Bindings')
-rw-r--r-- | test/Bindings/Go/go.test | 3 | ||||
-rw-r--r-- | test/Bindings/Go/lit.local.cfg | 57 | ||||
-rw-r--r-- | test/Bindings/OCaml/analysis.ml (renamed from test/Bindings/Ocaml/analysis.ml) | 28 | ||||
-rw-r--r-- | test/Bindings/OCaml/bitreader.ml (renamed from test/Bindings/Ocaml/bitreader.ml) | 22 | ||||
-rw-r--r-- | test/Bindings/OCaml/bitwriter.ml (renamed from test/Bindings/Ocaml/bitwriter.ml) | 13 | ||||
-rw-r--r-- | test/Bindings/OCaml/core.ml (renamed from test/Bindings/Ocaml/vmcore.ml) | 284 | ||||
-rw-r--r-- | test/Bindings/OCaml/executionengine.ml | 105 | ||||
-rw-r--r-- | test/Bindings/OCaml/ext_exc.ml (renamed from test/Bindings/Ocaml/ext_exc.ml) | 12 | ||||
-rw-r--r-- | test/Bindings/OCaml/ipo.ml (renamed from test/Bindings/Ocaml/ipo_opts.ml) | 12 | ||||
-rw-r--r-- | test/Bindings/OCaml/irreader.ml (renamed from test/Bindings/Ocaml/irreader.ml) | 8 | ||||
-rw-r--r-- | test/Bindings/OCaml/linker.ml (renamed from test/Bindings/Ocaml/linker.ml) | 8 | ||||
-rw-r--r-- | test/Bindings/OCaml/lit.local.cfg | 7 | ||||
-rw-r--r-- | test/Bindings/OCaml/passmgr_builder.ml (renamed from test/Bindings/Ocaml/passmgr_builder.ml) | 8 | ||||
-rw-r--r-- | test/Bindings/OCaml/scalar_opts.ml (renamed from test/Bindings/Ocaml/scalar_opts.ml) | 55 | ||||
-rw-r--r-- | test/Bindings/OCaml/target.ml (renamed from test/Bindings/Ocaml/target.ml) | 16 | ||||
-rw-r--r-- | test/Bindings/OCaml/vectorize.ml (renamed from test/Bindings/Ocaml/vectorize_opts.ml) | 10 | ||||
-rw-r--r-- | test/Bindings/Ocaml/executionengine.ml | 118 | ||||
-rw-r--r-- | test/Bindings/Ocaml/lit.local.cfg | 5 | ||||
-rw-r--r-- | test/Bindings/llvm-c/disassemble.test | 26 | ||||
-rw-r--r-- | test/Bindings/llvm-c/objectfile.ll | 2 |
20 files changed, 479 insertions, 320 deletions
diff --git a/test/Bindings/Go/go.test b/test/Bindings/Go/go.test new file mode 100644 index 0000000..3951483 --- /dev/null +++ b/test/Bindings/Go/go.test @@ -0,0 +1,3 @@ +; RUN: llvm-go test llvm.org/llvm/bindings/go/llvm + +; REQUIRES: shell diff --git a/test/Bindings/Go/lit.local.cfg b/test/Bindings/Go/lit.local.cfg new file mode 100644 index 0000000..e86595b --- /dev/null +++ b/test/Bindings/Go/lit.local.cfg @@ -0,0 +1,57 @@ +import os +import pipes +import shlex +import sys + +if not 'go' in config.root.llvm_bindings: + config.unsupported = True + +def find_executable(executable, path=None): + if path is None: + path = os.environ['PATH'] + paths = path.split(os.pathsep) + base, ext = os.path.splitext(executable) + + if (sys.platform == 'win32' or os.name == 'os2') and (ext != '.exe'): + executable = executable + '.exe' + + if not os.path.isfile(executable): + for p in paths: + f = os.path.join(p, executable) + if os.path.isfile(f): + return f + return None + else: + return executable + +# Resolve certain symlinks in the first word of compiler. +# +# This is a Go-specific hack. cgo and other Go tools check $CC and $CXX for the +# substring 'clang' to determine if the compiler is Clang. This won't work if +# $CC is cc and cc is a symlink pointing to clang, as it is on Darwin. +# +# Go tools also have problems with ccache, so we disable it. +def fixup_compiler_path(compiler): + args = shlex.split(compiler) + if args[0].endswith('ccache'): + args = args[1:] + + path = find_executable(args[0]) + + try: + if path.endswith('/cc') and os.readlink(path) == 'clang': + args[0] = path[:len(path)-2] + 'clang' + except (AttributeError, OSError): + pass + + try: + if path.endswith('/c++') and os.readlink(path) == 'clang++': + args[0] = path[:len(path)-3] + 'clang++' + except (AttributeError, OSError): + pass + + return ' '.join([pipes.quote(arg) for arg in args]) + +config.environment['CC'] = fixup_compiler_path(config.host_cc) +config.environment['CXX'] = fixup_compiler_path(config.host_cxx) +config.environment['CGO_LDFLAGS'] = config.host_ldflags diff --git a/test/Bindings/Ocaml/analysis.ml b/test/Bindings/OCaml/analysis.ml index c02645c..e935ee8 100644 --- a/test/Bindings/Ocaml/analysis.ml +++ b/test/Bindings/OCaml/analysis.ml @@ -1,7 +1,7 @@ -(* 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 %t.builddir/analysis.ml -o %t +(* RUN: cp %s %T/analysis.ml + * RUN: %ocamlc -g -warn-error A -package llvm.analysis -linkpkg %T/analysis.ml -o %t + * RUN: %t + * RUN: %ocamlopt -g -warn-error A -package llvm.analysis -linkpkg %T/analysis.ml -o %t * RUN: %t * XFAIL: vg_leak *) @@ -26,29 +26,29 @@ let _ = let fn = define_function "valid_fn" fty m in let at_entry = builder_at_end context (entry_block fn) in ignore (build_ret_void at_entry); - - + + (* Test that valid constructs verify. *) begin match verify_module m with Some msg -> bomb "valid module failed verification!" | None -> () end; - + if not (verify_function fn) then bomb "valid function failed verification!"; - - + + (* Test that invalid constructs do not verify. A basic block can contain only one terminator instruction. *) ignore (build_ret_void at_entry); - + begin match verify_module m with Some msg -> () | None -> bomb "invalid module passed verification!" end; - + if verify_function fn then bomb "invalid function passed verification!"; - - + + dispose_module m - + (* Don't bother to test assert_valid_{module,function}. *) diff --git a/test/Bindings/Ocaml/bitreader.ml b/test/Bindings/OCaml/bitreader.ml index f1d202a..57cfd04 100644 --- a/test/Bindings/Ocaml/bitreader.ml +++ b/test/Bindings/OCaml/bitreader.ml @@ -1,7 +1,7 @@ -(* RUN: rm -rf %t.builddir - * RUN: mkdir -p %t.builddir - * RUN: cp %s %t.builddir - * RUN: %ocamlopt -warn-error A llvm.cmxa llvm_bitreader.cmxa llvm_bitwriter.cmxa %t.builddir/bitreader.ml -o %t +(* RUN: cp %s %T/bitreader.ml + * RUN: %ocamlc -g -warn-error A -package llvm.bitreader -package llvm.bitwriter -linkpkg %T/bitreader.ml -o %t + * RUN: %t %t.bc + * RUN: %ocamlopt -g -warn-error A -package llvm.bitreader -package llvm.bitwriter -linkpkg %T/bitreader.ml -o %t * RUN: %t %t.bc * RUN: llvm-dis < %t.bc * XFAIL: vg_leak @@ -17,11 +17,11 @@ let test x = if not x then exit 1 else () let _ = let fn = Sys.argv.(1) in let m = Llvm.create_module context "ocaml_test_module" in - + test (Llvm_bitwriter.write_bitcode_file m fn); - + Llvm.dispose_module m; - + (* parse_bitcode *) begin let mb = Llvm.MemoryBuffer.of_file fn in @@ -33,7 +33,7 @@ let _ = raise x end end; - + (* MemoryBuffer.of_file *) test begin try let mb = Llvm.MemoryBuffer.of_file (fn ^ ".bogus") in @@ -42,7 +42,7 @@ let _ = with Llvm.IoError _ -> true end; - + (* get_module *) begin let mb = Llvm.MemoryBuffer.of_file fn in @@ -54,14 +54,14 @@ let _ = end in Llvm.dispose_module m end; - + (* corrupt the bitcode *) let fn = fn ^ ".txt" in begin let oc = open_out fn in output_string oc "not a bitcode file\n"; close_out oc end; - + (* test get_module exceptions *) test begin try diff --git a/test/Bindings/Ocaml/bitwriter.ml b/test/Bindings/OCaml/bitwriter.ml index ae456cf..7c803f6 100644 --- a/test/Bindings/Ocaml/bitwriter.ml +++ b/test/Bindings/OCaml/bitwriter.ml @@ -1,7 +1,7 @@ -(* RUN: rm -rf %t.builddir - * RUN: mkdir -p %t.builddir - * RUN: cp %s %t.builddir - * RUN: %ocamlopt -warn-error A unix.cmxa llvm.cmxa llvm_bitwriter.cmxa %t.builddir/bitwriter.ml -o %t +(* RUN: cp %s %T/bitwriter.ml + * RUN: %ocamlc -g -w -3 -warn-error A -package llvm.bitreader -package llvm.bitwriter -linkpkg %T/bitwriter.ml -o %t + * RUN: %t %t.bc + * RUN: %ocamlopt -g -w -3 -warn-error A -package llvm.bitreader -package llvm.bitwriter -linkpkg %T/bitwriter.ml -o %t * RUN: %t %t.bc * RUN: llvm-dis < %t.bc * XFAIL: vg_leak @@ -39,10 +39,11 @@ let temp_bitcode ?unbuffered m = let _ = let m = Llvm.create_module context "ocaml_test_module" in - + test (Llvm_bitwriter.write_bitcode_file m Sys.argv.(1)); let file_buf = read_file Sys.argv.(1) in test (file_buf = temp_bitcode m); test (file_buf = temp_bitcode ~unbuffered:false m); - test (file_buf = temp_bitcode ~unbuffered:true m) + test (file_buf = temp_bitcode ~unbuffered:true m); + test (file_buf = Llvm.MemoryBuffer.as_string (Llvm_bitwriter.write_bitcode_to_memory_buffer m)) diff --git a/test/Bindings/Ocaml/vmcore.ml b/test/Bindings/OCaml/core.ml index f014116..c08351e 100644 --- a/test/Bindings/Ocaml/vmcore.ml +++ b/test/Bindings/OCaml/core.ml @@ -1,7 +1,7 @@ -(* 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: cp %s %T/core.ml + * RUN: %ocamlc -g -warn-error A -package llvm.analysis -package llvm.bitwriter -linkpkg %T/core.ml -o %t + * RUN: %t %t.bc + * RUN: %ocamlopt -g -warn-error A -package llvm.analysis -package llvm.bitwriter -linkpkg %T/core.ml -o %t * RUN: %t %t.bc * RUN: llvm-dis < %t.bc > %t.ll * RUN: FileCheck %s < %t.ll @@ -83,7 +83,7 @@ let test_target () = set_target_triple trip m; insist (trip = target_triple m) end; - + begin group "layout"; let layout = "e" in set_data_layout layout m; @@ -104,6 +104,7 @@ let test_constants () = ignore (define_global "const_int" c m); insist (i32_type = type_of c); insist (is_constant c); + insist (Some (-1L) = int64_of_const c); (* CHECK: const_sext_int{{.*}}i64{{.*}}-1 *) @@ -111,6 +112,7 @@ let test_constants () = let c = const_int i64_type (-1) in ignore (define_global "const_sext_int" c m); insist (i64_type = type_of c); + insist (Some (-1L) = int64_of_const c); (* CHECK: const_zext_int64{{.*}}i64{{.*}}4294967295 *) @@ -118,6 +120,7 @@ let test_constants () = 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); + insist (Some 4294967295L = int64_of_const c); (* CHECK: const_int_string{{.*}}i32{{.*}}-1 *) @@ -125,6 +128,23 @@ let test_constants () = 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); + insist (None = (string_of_const c)); + insist (None = float_of_const c); + insist (Some (-1L) = int64_of_const c); + + (* CHECK: const_int64{{.*}}i64{{.*}}9223372036854775807 + *) + group "max int64"; + let c = const_of_int64 i64_type 9223372036854775807L true in + ignore (define_global "const_int64" c m) ; + insist (i64_type = type_of c); + insist (Some 9223372036854775807L = int64_of_const c); + + 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" *) @@ -132,6 +152,7 @@ let test_constants () = let c = const_string context "cruel\000world" in ignore (define_global "const_string" c m); insist ((array_type i8_type 11) = type_of c); + insist ((Some "cruel\000world") = (string_of_const c)); (* CHECK: const_stringz{{.*}}"hi\00again\00" *) @@ -142,34 +163,51 @@ let test_constants () = (* CHECK: const_single{{.*}}2.75 * CHECK: const_double{{.*}}3.1459 - * CHECK: const_double_string{{.*}}1.25 + * CHECK: const_double_string{{.*}}2 + * CHECK: const_fake_fp128{{.*}}0xL00000000000000004000000000000000 + * CHECK: const_fp128_string{{.*}}0xLF3CB1CCF26FBC178452FB4EC7F91973F *) begin group "real"; let cs = const_float float_type 2.75 in ignore (define_global "const_single" cs m); insist (float_type = type_of cs); - + insist (float_of_const cs = Some 2.75); + let cd = const_float double_type 3.1459 in ignore (define_global "const_double" cd m); insist (double_type = type_of cd); + insist (float_of_const cd = Some 3.1459); - let cd = const_float_of_string double_type "1.25" in + let cd = const_float_of_string double_type "2" in ignore (define_global "const_double_string" cd m); - insist (double_type = type_of cd) + insist (double_type = type_of cd); + insist (float_of_const cd = Some 2.); + + let cd = const_float fp128_type 2. in + ignore (define_global "const_fake_fp128" cd m); + insist (fp128_type = type_of cd); + insist (float_of_const cd = Some 2.); + + let cd = const_float_of_string fp128_type "1e400" in + ignore (define_global "const_fp128_string" cd m); + insist (fp128_type = type_of cd); + insist (float_of_const cd = None); end; - + let one = const_int i16_type 1 in let two = const_int i16_type 2 in let three = const_int i32_type 3 in let four = const_int i32_type 4 in - + (* 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)); - + insist (three = (const_element c 0)); + insist (four = (const_element c 1)); + (* CHECK: const_vector{{.*}}<i16 1, i16 2{{.*}}> *) group "vector"; @@ -192,7 +230,7 @@ let test_constants () = let c = const_null (packed_struct_type context [| i1_type; i8_type; i64_type; double_type |]) in ignore (define_global "const_null" c m); - + (* CHECK: const_all_ones{{.*}}-1 *) group "all ones"; @@ -205,7 +243,7 @@ let test_constants () = let c = const_pointer_null (pointer_type i64_type) in ignore (define_global "const_pointer_null" c m); end; - + (* CHECK: const_undef{{.*}}undef *) group "undef"; @@ -213,7 +251,7 @@ let test_constants () = ignore (define_global "const_undef" c m); insist (i1_type = type_of c); insist (is_undef c); - + group "constant arithmetic"; (* CHECK: @const_neg = global i64 sub * CHECK: @const_nsw_neg = global i64 sub nsw @@ -280,7 +318,7 @@ let test_constants () = ignore (define_global "const_xor" (const_xor foldbomb five) m); ignore (define_global "const_icmp" (const_icmp Icmp.Sle foldbomb five) m); ignore (define_global "const_fcmp" (const_fcmp Fcmp.Ole ffoldbomb ffive) m); - + group "constant casts"; (* CHECK: const_trunc{{.*}}trunc * CHECK: const_sext{{.*}}sext @@ -307,7 +345,7 @@ let test_constants () = ignore (define_global "const_sitofp" (const_sitofp foldbomb double_type) m); ignore (define_global "const_fptoui" (const_fptoui ffoldbomb i32_type) m); ignore (define_global "const_fptosi" (const_fptosi ffoldbomb i32_type) m); - ignore (define_global "const_ptrtoint" (const_ptrtoint + ignore (define_global "const_ptrtoint" (const_ptrtoint (const_gep (const_null (pointer_type i8_type)) [| const_int i32_type 1 |]) i32_type) m); @@ -316,7 +354,7 @@ let test_constants () = 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"; (* CHECK: const_size_of{{.*}}getelementptr{{.*}}null * CHECK: const_gep{{.*}}getelementptr @@ -393,20 +431,27 @@ let test_global_values () = let g = define_global "GVal03" zero32 m ++ set_section "Hanalei" in insist ("Hanalei" = section g); - + (* CHECK: GVal04{{.*}}hidden *) group "visibility"; let g = define_global "GVal04" zero32 m ++ set_visibility Visibility.Hidden in insist (Visibility.Hidden = visibility g); - + (* CHECK: GVal05{{.*}}align 128 *) group "alignment"; let g = define_global "GVal05" zero32 m ++ set_alignment 128 in - insist (128 = alignment g) + insist (128 = alignment g); + + (* CHECK: GVal06{{.*}}dllexport + *) + group "dll_storage_class"; + let g = define_global "GVal06" zero32 m ++ + set_dll_storage_class DLLStorageClass.DLLExport in + insist (DLLStorageClass.DLLExport = dll_storage_class g) (*===-- Global Variables --------------------------------------------------===*) @@ -437,7 +482,7 @@ let test_global_variables () = insist (match lookup_global "QGVar01" m with Some x -> x = g | None -> false); end; - + group "definitions"; begin (* CHECK: @GVar02 = global i32 42 * CHECK: @GVar03 = global i32 42 @@ -493,30 +538,30 @@ let test_global_variables () = insist (not (is_global_constant g)); set_global_constant true g; insist (is_global_constant g); - + begin group "iteration"; let m = create_module context "temp" in - + insist (At_end m = global_begin m); insist (At_start m = global_end m); - + let g1 = declare_global i32_type "One" m in let g2 = declare_global i32_type "Two" m in - + insist (Before g1 = global_begin m); insist (Before g2 = global_succ g1); insist (At_end m = global_succ g2); - + insist (After g2 = global_end m); insist (After g1 = global_pred g2); insist (At_start m = global_pred g1); - + let lf s x = s ^ "->" ^ value_name x in insist ("->One->Two" = fold_left_globals lf "" m); - + let rf x s = value_name x ^ "<-" ^ s in insist ("One<-Two<-" = fold_right_globals rf m ""); - + dispose_module m end @@ -591,7 +636,7 @@ let test_aliases () = 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 - + (* CHECK: declare i32 @Fn1(i32, i64) *) begin group "declare"; @@ -607,13 +652,13 @@ let test_functions () = | None -> false); insist (m == global_parent fn) end; - + (* CHECK-NOWHERE-NOT: Fn2 *) group "delete"; let fn = declare_function "Fn2" ty m in delete_function fn; - + (* CHECK: define{{.*}}Fn3 *) group "define"; @@ -621,7 +666,7 @@ let test_functions () = insist (not (is_declaration fn)); insist (1 = Array.length (basic_blocks fn)); ignore (build_unreachable (builder_at_end context (entry_block fn))); - + (* CHECK: define{{.*}}Fn4{{.*}}Param1{{.*}}Param2 *) group "params"; @@ -635,7 +680,7 @@ let test_functions () = set_value_name "Param1" params.(0); set_value_name "Param2" params.(1); ignore (build_unreachable (builder_at_end context (entry_block fn))); - + (* CHECK: fastcc{{.*}}Fn5 *) group "callconv"; @@ -644,7 +689,7 @@ let test_functions () = set_function_call_conv CallConv.fast fn; insist (CallConv.fast = function_call_conv fn); ignore (build_unreachable (builder_at_end context (entry_block fn))); - + begin group "gc"; (* CHECK: Fn6{{.*}}gc{{.*}}shadowstack *) @@ -657,30 +702,30 @@ let test_functions () = set_gc (Some "shadowstack") fn; ignore (build_unreachable (builder_at_end context (entry_block fn))); end; - + begin group "iteration"; let m = create_module context "temp" in - + insist (At_end m = function_begin m); insist (At_start m = function_end m); - + let f1 = define_function "One" ty m in let f2 = define_function "Two" ty m in - + insist (Before f1 = function_begin m); insist (Before f2 = function_succ f1); insist (At_end m = function_succ f2); - + insist (After f2 = function_end m); insist (After f1 = function_pred f2); insist (At_start m = function_pred f1); - + let lf s x = s ^ "->" ^ value_name x in insist ("->One->Two" = fold_left_functions lf "" m); - + let rf x s = value_name x ^ "<-" ^ s in insist ("One<-Two<-" = fold_right_functions rf m ""); - + dispose_module m end @@ -690,12 +735,12 @@ let test_functions () = let test_params () = begin group "iteration"; let m = create_module context "temp" in - + let vf = define_function "void" (function_type void_type [| |]) m in - + insist (At_end vf = param_begin vf); insist (At_start vf = param_end vf); - + let ty = function_type void_type [| i32_type; i32_type |] in let f = define_function "f" ty m in let p1 = param f 0 in @@ -712,17 +757,17 @@ let test_params () = insist (Before p1 = param_begin f); insist (Before p2 = param_succ p1); insist (At_end f = param_succ p2); - + insist (After p2 = param_end f); insist (After p1 = param_pred p2); insist (At_start f = param_pred p1); - + let lf s x = s ^ "->" ^ value_name x in insist ("->One->Two" = fold_left_params lf "" f); - + let rf x s = value_name x ^ "<-" ^ s in insist ("One<-Two<-" = fold_right_params rf f ""); - + dispose_module m end @@ -731,7 +776,7 @@ let test_params () = let test_basic_blocks () = let ty = function_type void_type [| |] in - + (* CHECK: Bb1 *) group "entry"; @@ -739,14 +784,14 @@ let test_basic_blocks () = let bb = append_block context "Bb1" fn in insist (bb = entry_block fn); ignore (build_unreachable (builder_at_end context bb)); - + (* CHECK-NOWHERE-NOT: Bb2 *) group "delete"; let fn = declare_function "X2" ty m in let bb = append_block context "Bb2" fn in delete_block bb; - + group "insert"; let fn = declare_function "X3" ty m in let bbb = append_block context "b" fn in @@ -754,7 +799,7 @@ let test_basic_blocks () = insist ([| bba; bbb |] = basic_blocks fn); ignore (build_unreachable (builder_at_end context bba)); ignore (build_unreachable (builder_at_end context bbb)); - + (* CHECK: Bb3 *) group "name/value"; @@ -764,7 +809,7 @@ let test_basic_blocks () = let bbv = value_of_block bb in set_value_name "Bb3" bbv; insist ("Bb3" = value_name bbv); - + group "casts"; let fn = define_function "X5" ty m in let bb = entry_block fn in @@ -772,31 +817,31 @@ let test_basic_blocks () = insist (bb = block_of_value (value_of_block bb)); insist (value_is_block (value_of_block bb)); insist (not (value_is_block (const_null i32_type))); - + begin group "iteration"; let m = create_module context "temp" in let f = declare_function "Temp" (function_type i32_type [| |]) m in - + insist (At_end f = block_begin f); insist (At_start f = block_end f); - + let b1 = append_block context "One" f in let b2 = append_block context "Two" f in - + insist (Before b1 = block_begin f); insist (Before b2 = block_succ b1); insist (At_end f = block_succ b2); - + insist (After b2 = block_end f); insist (After b1 = block_pred b2); insist (At_start f = block_pred b1); - + let lf s x = s ^ "->" ^ value_name (value_of_block x) in insist ("->One->Two" = fold_left_blocks lf "" f); - + let rf x s = value_name (value_of_block x) ^ "<-" ^ s in insist ("One<-Two<-" = fold_right_blocks rf f ""); - + dispose_module m end @@ -810,28 +855,46 @@ let test_instructions () = let f = define_function "f" fty m in let bb = entry_block f in let b = builder_at context (At_end bb) in - + insist (At_end bb = instr_begin bb); insist (At_start bb = instr_end bb); - + let i1 = build_add (param f 0) (param f 1) "One" b in let i2 = build_sub (param f 0) (param f 1) "Two" b in - + insist (Before i1 = instr_begin bb); insist (Before i2 = instr_succ i1); insist (At_end bb = instr_succ i2); - + insist (After i2 = instr_end bb); insist (After i1 = instr_pred i2); insist (At_start bb = instr_pred i1); - + let lf s x = s ^ "->" ^ value_name x in insist ("->One->Two" = fold_left_instrs lf "" bb); - + let rf x s = value_name x ^ "<-" ^ s in insist ("One<-Two<-" = fold_right_instrs rf bb ""); - + dispose_module m + end; + + group "clone instr"; + begin + (* CHECK: %clone = add i32 %0, 2 + *) + let fty = function_type void_type [| i32_type |] in + let fn = define_function "BuilderParent" fty m in + let bb = entry_block fn in + let b = builder_at_end context bb in + let p = param fn 0 in + let sum = build_add p p "sum" b in + let y = const_int i32_type 2 in + let clone = instr_clone sum in + set_operand clone 0 p; + set_operand clone 1 y; + insert_into_builder clone "clone" b; + ignore (build_ret_void b) end @@ -839,14 +902,14 @@ let test_instructions () = let test_builder () = let (++) x f = f x; x in - + begin group "parent"; insist (try ignore (insertion_block (builder context)); false with Not_found -> true); - + let fty = function_type void_type [| i32_type |] in let fn = define_function "BuilderParent" fty m in let bb = entry_block fn in @@ -854,13 +917,13 @@ let test_builder () = let p = param fn 0 in let sum = build_add p p "sum" b in ignore (build_ret_void b); - + insist (fn = block_parent bb); insist (fn = param_parent p); insist (bb = instr_parent sum); insist (bb = insertion_block b) end; - + group "ret void"; begin (* CHECK: ret void @@ -882,7 +945,7 @@ let test_builder () = 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 fn = define_function "X7" fty m in @@ -891,7 +954,7 @@ let test_builder () = let p2 = param fn 1 ++ set_value_name "P2" in let f1 = build_uitofp p1 float_type "F1" atentry in let f2 = build_uitofp p2 float_type "F2" atentry in - + let bb00 = append_block context "Bb00" fn in ignore (build_unreachable (builder_at_end context bb00)); @@ -968,10 +1031,22 @@ let test_builder () = * 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 c = build_icmp Icmp.Ne p1 p2 "build_icmp_ne" atentry in + insist (Some Icmp.Ne = icmp_predicate c); + insist (None = fcmp_predicate c); + + let c = build_icmp Icmp.Sle p2 p1 "build_icmp_sle" atentry in + insist (Some Icmp.Sle = icmp_predicate c); + insist (None = fcmp_predicate c); + + let c = build_fcmp Fcmp.False f1 f2 "build_fcmp_false" atentry in + (* insist (Some Fcmp.False = fcmp_predicate c); *) + insist (None = icmp_predicate c); + + let c = build_fcmp Fcmp.True f2 f1 "build_fcmp_true" atentry in + (* insist (Some Fcmp.True = fcmp_predicate c); *) + insist (None = icmp_predicate c); + 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 @@ -1060,7 +1135,8 @@ let test_builder () = (* !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 + let n3 = const_int i32_type 2 in + let md = mdnode context [| n1; n2; n3 |] in add_named_metadata_operand m "llvm.module.flags" md; insist ((get_named_metadata m "llvm.module.flags") = [| md |]) @@ -1128,18 +1204,26 @@ let test_builder () = *) let bb02 = append_block context "Bb02" fn in let b = builder_at_end context bb02 in - ignore (build_br bb02 b) + let br = build_br bb02 b in + insist (successors br = [| bb02 |]) ; + insist (is_conditional br = false) ; + insist (get_branch br = Some (`Unconditional bb02)) ; end; - + group "cond_br"; begin (* CHECK: br{{.*}}build_br{{.*}}Bb03{{.*}}Bb00 *) let bb03 = append_block context "Bb03" fn in let b = builder_at_end context bb03 in let cond = build_trunc p1 i1_type "build_br" b in - ignore (build_cond_br cond bb03 bb00 b) + let br = build_cond_br cond bb03 bb00 b in + insist (num_successors br = 2) ; + insist (successor br 0 = bb03) ; + insist (successor br 1 = bb00) ; + insist (is_conditional br = true) ; + insist (get_branch br = Some (`Conditional (cond, bb03, bb00))) ; end; - + group "switch"; begin (* CHECK: switch{{.*}}P1{{.*}}SwiBlock3 * CHECK: 2,{{.*}}SwiBlock2 @@ -1153,6 +1237,8 @@ let test_builder () = ignore (add_case si (const_int i32_type 2) bb2); insist (switch_default_dest si = bb3); end; + insist (num_successors si = 2) ; + insist (get_branch si = None) ; end; group "malloc/free"; begin @@ -1184,7 +1270,7 @@ let test_builder () = ignore (add_destination ibr bb2); ignore (add_destination ibr bb3) end; - + group "invoke"; begin (* CHECK: build_invoke{{.*}}invoke{{.*}}P1{{.*}}P2 * CHECK: to{{.*}}Bb04{{.*}}unwind{{.*}}Bblpad @@ -1193,7 +1279,7 @@ let test_builder () = let b = builder_at_end context bb04 in ignore (build_invoke fn [| p1; p2 |] bb04 bblpad "build_invoke" b) end; - + group "unreachable"; begin (* CHECK: unreachable *) @@ -1201,11 +1287,11 @@ let test_builder () = let b = builder_at_end context bb06 in ignore (build_unreachable b) end; - + group "arithmetic"; begin let bb07 = append_block context "Bb07" fn in let b = builder_at_end context bb07 in - + (* 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 @@ -1269,7 +1355,7 @@ let test_builder () = ignore (build_not p1 "build_not" b); ignore (build_unreachable b) end; - + group "memory"; begin let bb08 = append_block context "Bb08" fn in let b = builder_at_end context bb08 in @@ -1330,25 +1416,25 @@ let test_builder () = *) let b1 = append_block context "PhiBlock1" fn in let b2 = append_block context "PhiBlock2" fn in - + let jb = append_block context "PhiJoinBlock" fn in ignore (build_br jb (builder_at_end context b1)); ignore (build_br jb (builder_at_end context b2)); let at_jb = builder_at_end context jb in - + let phi = build_phi [(p1, b1)] "PhiNode" at_jb in insist ([(p1, b1)] = incoming phi); - + add_incoming (p2, b2) phi; insist ([(p1, b1); (p2, b2)] = incoming phi); - + ignore (build_unreachable at_jb); end (* 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: !0 = metadata !{i32 1, metadata !"Debug Info Version", i32 2} * CHECK: !1 = metadata !{i32 1, metadata !"metadata test"} * CHECK: !2 = metadata !{i32 2, i32 3, metadata !3, metadata !3} *) @@ -1363,12 +1449,12 @@ let test_pass_manager () = ++ PassManager.run_module m ++ PassManager.dispose) end; - + begin group "function pass manager"; let fty = function_type void_type [| |] in let fn = define_function "FunctionPassManager" fty m in ignore (build_ret_void (builder_at_end context (entry_block fn))); - + ignore (PassManager.create_function m ++ PassManager.initialize ++ PassManager.run_function fn @@ -1395,7 +1481,7 @@ let test_writer () = group "writer"; insist (write_bitcode_file m filename); - + dispose_module m diff --git a/test/Bindings/OCaml/executionengine.ml b/test/Bindings/OCaml/executionengine.ml new file mode 100644 index 0000000..893f988 --- /dev/null +++ b/test/Bindings/OCaml/executionengine.ml @@ -0,0 +1,105 @@ +(* RUN: cp %s %T/executionengine.ml + * RUN: %ocamlc -g -warn-error A -package llvm.executionengine -linkpkg %T/executionengine.ml -o %t + * RUN: %t + * RUN: %ocamlopt -g -warn-error A -package llvm.executionengine -linkpkg %T/executionengine.ml -o %t + * RUN: %t + * REQUIRES: native, object-emission + * XFAIL: vg_leak + *) + +open Llvm +open Llvm_executionengine +open Llvm_target + +(* Note that this takes a moment to link, so it's best to keep the number of + individual tests low. *) + +let context = global_context () +let i8_type = Llvm.i8_type context +let i32_type = Llvm.i32_type context +let i64_type = Llvm.i64_type context +let double_type = Llvm.double_type context + +let () = + assert (Llvm_executionengine.initialize ()) + +let bomb msg = + prerr_endline msg; + exit 2 + +let define_getglobal m pg = + let fn = define_function "getglobal" (function_type i32_type [||]) m in + let b = builder_at_end (global_context ()) (entry_block fn) in + let g = build_call pg [||] "" b in + ignore (build_ret g b); + fn + +let define_plus m = + let fn = define_function "plus" (function_type i32_type [| i32_type; + i32_type |]) m in + let b = builder_at_end (global_context ()) (entry_block fn) in + let add = build_add (param fn 0) (param fn 1) "sum" b in + ignore (build_ret add b); + fn + +let test_executionengine () = + let open Ctypes in + + (* create *) + let m = create_module (global_context ()) "test_module" in + let ee = create m in + + (* add plus *) + let plus = define_plus m in + + (* add module *) + let m2 = create_module (global_context ()) "test_module2" in + add_module m2 ee; + + (* add global mapping *) + (* BROKEN: see PR20656 *) + (* let g = declare_function "g" (function_type i32_type [||]) m2 in + let cg = coerce (Foreign.funptr (void @-> returning int32_t)) (ptr void) + (fun () -> 42l) in + add_global_mapping g cg ee; + + (* check g *) + let cg' = get_pointer_to_global g (ptr void) ee in + if 0 <> ptr_compare cg cg' then bomb "int pointers to g differ"; + + (* add getglobal *) + let getglobal = define_getglobal m2 g in*) + + (* run_static_ctors *) + run_static_ctors ee; + + (* call plus *) + let cplusty = Foreign.funptr (int32_t @-> int32_t @-> returning int32_t) in + let cplus = get_pointer_to_global plus cplusty ee in + if 4l <> cplus 2l 2l then bomb "plus didn't work"; + + (* call getglobal *) + (* let cgetglobalty = Foreign.funptr (void @-> returning int32_t) in + let cgetglobal = get_pointer_to_global getglobal cgetglobalty ee in + if 42l <> cgetglobal () then bomb "getglobal didn't work"; *) + + (* remove_module *) + remove_module m2 ee; + dispose_module m2; + + (* run_static_dtors *) + run_static_dtors ee; + + (* Show that the data layout binding links and runs.*) + let dl = data_layout ee in + + (* Demonstrate that a garbage pointer wasn't returned. *) + let ty = DataLayout.intptr_type context dl in + if ty != i32_type && ty != i64_type then bomb "target_data did not work"; + + (* dispose *) + dispose ee + +let () = + test_executionengine (); + Gc.compact () diff --git a/test/Bindings/Ocaml/ext_exc.ml b/test/Bindings/OCaml/ext_exc.ml index 9afc3c3..2b44803 100644 --- a/test/Bindings/Ocaml/ext_exc.ml +++ b/test/Bindings/OCaml/ext_exc.ml @@ -1,11 +1,13 @@ -(* RUN: rm -rf %t.builddir - * RUN: mkdir -p %t.builddir - * RUN: cp %s %t.builddir - * RUN: %ocamlopt -warn-error A llvm.cmxa llvm_bitreader.cmxa llvm_executionengine.cmxa %t.builddir/ext_exc.ml -o %t - * RUN: %t </dev/null +(* RUN: cp %s %T/ext_exc.ml + * RUN: %ocamlc -g -warn-error A -package llvm.bitreader -linkpkg %T/ext_exc.ml -o %t + * RUN: %t + * RUN: %ocamlopt -g -warn-error A -package llvm.bitreader -linkpkg %T/ext_exc.ml -o %t + * RUN: %t * XFAIL: vg_leak *) + let context = Llvm.global_context () + (* this used to crash, we must not use 'external' in .mli files, but 'val' if we * want the let _ bindings executed, see http://caml.inria.fr/mantis/view.php?id=4166 *) let _ = diff --git a/test/Bindings/Ocaml/ipo_opts.ml b/test/Bindings/OCaml/ipo.ml index e0bcbe5..fc728b9 100644 --- a/test/Bindings/Ocaml/ipo_opts.ml +++ b/test/Bindings/OCaml/ipo.ml @@ -1,7 +1,7 @@ -(* RUN: rm -rf %t.builddir - * RUN: mkdir -p %t.builddir - * RUN: cp %s %t.builddir - * RUN: %ocamlopt -warn-error A llvm.cmxa llvm_ipo.cmxa llvm_target.cmxa %t.builddir/ipo_opts.ml -o %t +(* RUN: cp %s %T/ipo_opts.ml + * RUN: %ocamlc -g -warn-error A -package llvm.ipo -linkpkg %T/ipo_opts.ml -o %t + * RUN: %t %t.bc + * RUN: %ocamlopt -g -warn-error A -package llvm.ipo -linkpkg %T/ipo_opts.ml -o %t * RUN: %t %t.bc * XFAIL: vg_leak *) @@ -36,7 +36,7 @@ let m = create_module context filename (*===-- Transforms --------------------------------------------------------===*) let test_transforms () = - let (++) x f = ignore (f x); x in + let (++) x f = f x; x in let fty = function_type i8_type [| |] in let fn = define_function "fn" fty m in @@ -58,7 +58,7 @@ let test_transforms () = ++ add_ipc_propagation ++ add_prune_eh ++ add_ipsccp - ++ add_internalize + ++ add_internalize ~all_but_main:true ++ add_strip_dead_prototypes ++ add_strip_symbols ++ PassManager.run_module m diff --git a/test/Bindings/Ocaml/irreader.ml b/test/Bindings/OCaml/irreader.ml index 3511c2b..e1771e7 100644 --- a/test/Bindings/Ocaml/irreader.ml +++ b/test/Bindings/OCaml/irreader.ml @@ -1,7 +1,7 @@ -(* RUN: rm -rf %t.builddir - * RUN: mkdir -p %t.builddir - * RUN: cp %s %t.builddir - * RUN: %ocamlopt -g -warn-error A llvm.cmxa llvm_irreader.cmxa %t.builddir/irreader.ml -o %t +(* RUN: cp %s %T/irreader.ml + * RUN: %ocamlc -g -warn-error A -package llvm.irreader -linkpkg %T/irreader.ml -o %t + * RUN: %t + * RUN: %ocamlopt -g -warn-error A -package llvm.irreader -linkpkg %T/irreader.ml -o %t * RUN: %t * XFAIL: vg_leak *) diff --git a/test/Bindings/Ocaml/linker.ml b/test/Bindings/OCaml/linker.ml index 9359ae9..00064b0 100644 --- a/test/Bindings/Ocaml/linker.ml +++ b/test/Bindings/OCaml/linker.ml @@ -1,7 +1,7 @@ -(* RUN: rm -rf %t.builddir - * RUN: mkdir -p %t.builddir - * RUN: cp %s %t.builddir - * RUN: %ocamlopt -warn-error A llvm.cmxa llvm_linker.cmxa %t.builddir/linker.ml -o %t +(* RUN: cp %s %T/linker.ml + * RUN: %ocamlc -g -warn-error A -package llvm.linker -linkpkg %T/linker.ml -o %t + * RUN: %t + * RUN: %ocamlopt -g -warn-error A -package llvm.linker -linkpkg %T/linker.ml -o %t * RUN: %t * XFAIL: vg_leak *) diff --git a/test/Bindings/OCaml/lit.local.cfg b/test/Bindings/OCaml/lit.local.cfg new file mode 100644 index 0000000..bca5d39 --- /dev/null +++ b/test/Bindings/OCaml/lit.local.cfg @@ -0,0 +1,7 @@ +config.suffixes = ['.ml'] + +if not 'ocaml' in config.root.llvm_bindings: + config.unsupported = True + +if config.root.have_ocaml_ounit != '1': + config.unsupported = True diff --git a/test/Bindings/Ocaml/passmgr_builder.ml b/test/Bindings/OCaml/passmgr_builder.ml index 1a3102f..5dd9d4e 100644 --- a/test/Bindings/Ocaml/passmgr_builder.ml +++ b/test/Bindings/OCaml/passmgr_builder.ml @@ -1,7 +1,7 @@ -(* RUN: rm -rf %t.builddir - * RUN: mkdir -p %t.builddir - * RUN: cp %s %t.builddir - * RUN: %ocamlopt -warn-error A llvm.cmxa llvm_passmgr_builder.cmxa %t.builddir/passmgr_builder.ml -o %t +(* RUN: cp %s %T/passmgr_builder.ml + * RUN: %ocamlc -g -warn-error A -package llvm.passmgr_builder -linkpkg %T/passmgr_builder.ml -o %t + * RUN: %t %t.bc + * RUN: %ocamlopt -g -warn-error A -package llvm.passmgr_builder -linkpkg %T/passmgr_builder.ml -o %t * RUN: %t %t.bc * XFAIL: vg_leak *) diff --git a/test/Bindings/Ocaml/scalar_opts.ml b/test/Bindings/OCaml/scalar_opts.ml index 39913e4..3017fb1 100644 --- a/test/Bindings/Ocaml/scalar_opts.ml +++ b/test/Bindings/OCaml/scalar_opts.ml @@ -1,7 +1,7 @@ -(* RUN: rm -rf %t.builddir - * RUN: mkdir -p %t.builddir - * RUN: cp %s %t.builddir - * RUN: %ocamlopt -warn-error A llvm.cmxa llvm_scalar_opts.cmxa llvm_target.cmxa %t.builddir/scalar_opts.ml -o %t +(* RUN: cp %s %T/scalar_opts.ml + * RUN: %ocamlc -g -warn-error A -package llvm.scalar_opts -linkpkg %T/scalar_opts.ml -o %t + * RUN: %t %t.bc + * RUN: %ocamlopt -g -warn-error A -package llvm.scalar_opts -linkpkg %T/scalar_opts.ml -o %t * RUN: %t %t.bc * XFAIL: vg_leak *) @@ -35,45 +35,50 @@ let m = create_module context filename (*===-- Transforms --------------------------------------------------------===*) let test_transforms () = - let (++) x f = ignore (f x); x in + let (++) x f = f x; x in let fty = function_type void_type [| |] in let fn = define_function "fn" fty m in ignore (build_ret_void (builder_at_end context (entry_block fn))); - + ignore (PassManager.create_function m - ++ 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_alignment_from_assumptions + ++ add_cfg_simplification + ++ add_dead_store_elimination + ++ add_scalarizer + ++ add_merged_load_store_motion + ++ add_gvn ++ add_ind_var_simplification ++ add_instruction_combination + ++ add_jump_threading ++ add_licm - ++ add_loop_unswitch - ++ add_loop_unroll + ++ add_loop_deletion + ++ add_loop_idiom ++ add_loop_rotation + ++ add_loop_reroll + ++ add_loop_unroll + ++ add_loop_unswitch + ++ add_memcpy_opt + ++ add_partially_inline_lib_calls + ++ add_lower_switch ++ add_memory_to_register_promotion - ++ add_memory_to_register_demotion ++ add_reassociation - ++ add_jump_threading - ++ add_cfg_simplification - ++ add_tail_call_elimination - ++ add_gvn - ++ add_memcpy_opt - ++ add_loop_deletion - ++ add_loop_idiom + ++ add_sccp + ++ add_scalar_repl_aggregation + ++ add_scalar_repl_aggregation_ssa + ++ add_scalar_repl_aggregation_with_threshold 4 ++ add_lib_call_simplification + ++ add_tail_call_elimination + ++ add_constant_propagation + ++ add_memory_to_register_demotion + ++ add_verifier ++ add_correlated_value_propagation ++ add_early_cse ++ add_lower_expect_intrinsic ++ add_type_based_alias_analysis + ++ add_scoped_no_alias_alias_analysis ++ add_basic_alias_analysis - ++ add_partially_inline_lib_calls - ++ 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 0a2283a..41faefa 100644 --- a/test/Bindings/Ocaml/target.ml +++ b/test/Bindings/OCaml/target.ml @@ -1,9 +1,7 @@ -(* RUN: rm -rf %t.builddir - * RUN: mkdir -p %t.builddir - * RUN: cp %s %t.builddir - * RUN: %ocamlopt -g -warn-error A llvm.cmxa llvm_target.cmxa llvm_executionengine.cmxa %t.builddir/target.ml -o %t +(* RUN: cp %s %T/target.ml + * RUN: %ocamlc -g -warn-error A -package llvm.target -package llvm.all_backends -linkpkg %T/target.ml -o %t + * RUN: %ocamlopt -g -warn-error A -package llvm.target -package llvm.all_backends -linkpkg %T/target.ml -o %t * RUN: %t %t.bc - * REQUIRES: native, object-emission * XFAIL: vg_leak *) @@ -14,7 +12,7 @@ open Llvm open Llvm_target -let _ = Llvm_executionengine.initialize_native_target () +let () = Llvm_all_backends.initialize () let context = global_context () let i32_type = Llvm.i32_type context @@ -87,7 +85,9 @@ let test_target_machine () = assert_equal (TM.cpu machine) ""; assert_equal (TM.features machine) ""; ignore (TM.data_layout machine); - TM.set_verbose_asm true machine + TM.set_verbose_asm true machine; + let pm = PassManager.create () in + TM.add_analysis_passes pm machine (*===-- Code Emission -----------------------------------------------------===*) @@ -112,5 +112,5 @@ let _ = test_target_data (); test_target (); test_target_machine (); - (* test_code_emission (); *) (* broken without AsmParser support *) + test_code_emission (); dispose_module m diff --git a/test/Bindings/Ocaml/vectorize_opts.ml b/test/Bindings/OCaml/vectorize.ml index 5ef985d..c5b03b5 100644 --- a/test/Bindings/Ocaml/vectorize_opts.ml +++ b/test/Bindings/OCaml/vectorize.ml @@ -1,7 +1,7 @@ -(* RUN: rm -rf %t.builddir - * RUN: mkdir -p %t.builddir - * RUN: cp %s %t.builddir - * RUN: %ocamlopt -warn-error A llvm.cmxa llvm_vectorize.cmxa llvm_target.cmxa %t.builddir/vectorize_opts.ml -o %t +(* RUN: cp %s %T/vectorize_opts.ml + * RUN: %ocamlc -g -warn-error A -package llvm.vectorize -linkpkg %T/vectorize_opts.ml -o %t + * RUN: %t %t.bc + * RUN: %ocamlopt -g -warn-error A -package llvm.vectorize -linkpkg %T/vectorize_opts.ml -o %t * RUN: %t %t.bc * XFAIL: vg_leak *) @@ -35,7 +35,7 @@ let m = create_module context filename (*===-- Transforms --------------------------------------------------------===*) let test_transforms () = - let (++) x f = ignore (f x); x in + let (++) x f = f x; x in let fty = function_type void_type [| |] in let fn = define_function "fn" fty m in diff --git a/test/Bindings/Ocaml/executionengine.ml b/test/Bindings/Ocaml/executionengine.ml deleted file mode 100644 index 8e24949..0000000 --- a/test/Bindings/Ocaml/executionengine.ml +++ /dev/null @@ -1,118 +0,0 @@ -(* RUN: rm -rf %t.builddir - * RUN: mkdir -p %t.builddir - * RUN: cp %s %t.builddir - * RUN: %ocamlopt -warn-error A llvm.cmxa llvm_target.cmxa llvm_executionengine.cmxa %t.builddir/executionengine.ml -o %t - * RUN: %t - * XFAIL: vg_leak - *) - -open Llvm -open Llvm_executionengine -open Llvm_target - -(* Note that this takes a moment to link, so it's best to keep the number of - individual tests low. *) - -let context = global_context () -let i8_type = Llvm.i8_type context -let i32_type = Llvm.i32_type context -let i64_type = Llvm.i64_type context -let double_type = Llvm.double_type context - -let bomb msg = - prerr_endline msg; - exit 2 - -let define_main_fn m retval = - let fn = - let str_arr_type = pointer_type (pointer_type i8_type) in - define_function "main" (function_type i32_type [| i32_type; - str_arr_type; - str_arr_type |]) m in - let b = builder_at_end (global_context ()) (entry_block fn) in - ignore (build_ret (const_int i32_type retval) b); - fn - -let define_plus m = - let fn = define_function "plus" (function_type i32_type [| i32_type; - i32_type |]) m in - let b = builder_at_end (global_context ()) (entry_block fn) in - let add = build_add (param fn 0) (param fn 1) "sum" b in - ignore (build_ret add b) - -let test_genericvalue () = - let tu = (1, 2) in - let ptrgv = GenericValue.of_pointer tu in - assert (tu = GenericValue.as_pointer ptrgv); - - let fpgv = GenericValue.of_float double_type 2. in - assert (2. = GenericValue.as_float double_type fpgv); - - let intgv = GenericValue.of_int i32_type 3 in - assert (3 = GenericValue.as_int intgv); - - let i32gv = GenericValue.of_int32 i32_type (Int32.of_int 4) in - assert ((Int32.of_int 4) = GenericValue.as_int32 i32gv); - - let nigv = GenericValue.of_nativeint i32_type (Nativeint.of_int 5) in - assert ((Nativeint.of_int 5) = GenericValue.as_nativeint nigv); - - let i64gv = GenericValue.of_int64 i64_type (Int64.of_int 6) in - assert ((Int64.of_int 6) = GenericValue.as_int64 i64gv) - -let test_executionengine () = - (* create *) - let m = create_module (global_context ()) "test_module" in - let main = define_main_fn m 42 in - - let m2 = create_module (global_context ()) "test_module2" in - define_plus m2; - - let ee = ExecutionEngine.create m in - ExecutionEngine.add_module m2 ee; - - (* run_static_ctors *) - ExecutionEngine.run_static_ctors ee; - - (* run_function_as_main *) - let res = ExecutionEngine.run_function_as_main main [|"test"|] [||] ee in - if 42 != res then bomb "main did not return 42"; - - (* free_machine_code *) - ExecutionEngine.free_machine_code main ee; - - (* find_function *) - match ExecutionEngine.find_function "dne" ee with - | Some _ -> raise (Failure "find_function 'dne' failed") - | None -> - - match ExecutionEngine.find_function "plus" ee with - | None -> raise (Failure "find_function 'plus' failed") - | Some plus -> - - (* run_function *) - let res = ExecutionEngine.run_function plus - [| GenericValue.of_int i32_type 2; - GenericValue.of_int i32_type 2 |] - ee in - if 4 != GenericValue.as_int res then bomb "plus did not work"; - - (* remove_module *) - Llvm.dispose_module (ExecutionEngine.remove_module m2 ee); - - (* run_static_dtors *) - ExecutionEngine.run_static_dtors ee; - - (* Show that the data layout binding links and runs.*) - let dl = ExecutionEngine.data_layout ee in - - (* Demonstrate that a garbage pointer wasn't returned. *) - let ty = DataLayout.intptr_type context dl in - if ty != i32_type && ty != i64_type then bomb "target_data did not work"; - - (* dispose *) - ExecutionEngine.dispose ee - -let _ = - test_genericvalue (); - test_executionengine () diff --git a/test/Bindings/Ocaml/lit.local.cfg b/test/Bindings/Ocaml/lit.local.cfg deleted file mode 100644 index c38d89a..0000000 --- a/test/Bindings/Ocaml/lit.local.cfg +++ /dev/null @@ -1,5 +0,0 @@ -config.suffixes = ['.ml'] - -bindings = set([s.strip() for s in config.root.llvm_bindings.split(',')]) -if not 'ocaml' in bindings: - config.unsupported = True diff --git a/test/Bindings/llvm-c/disassemble.test b/test/Bindings/llvm-c/disassemble.test index 201e914..bb7a9a0 100644 --- a/test/Bindings/llvm-c/disassemble.test +++ b/test/Bindings/llvm-c/disassemble.test @@ -1,15 +1,27 @@ ; RUN: llvm-c-test --disassemble < %s | FileCheck %s +armv8-linux-gnu +crypto 02 00 81 e0 02 03 b0 f3 +;CHECK: triple: armv8-linux-gnu, features: +crypto +;CHECK: 02 00 81 e0 add r0, r1, r2 +;CHECK: 02 03 b0 f3 aese.8 q0, q1 -arm-linux-android 44 26 1f e5 0c 10 4b e2 02 20 81 e0 -;CHECK: triple: arm-linux-android +armv8-linux-gnu -crypto 02 00 81 e0 02 03 b0 f3 +;CHECK: triple: armv8-linux-gnu, features: -crypto +;CHECK: 02 00 81 e0 add r0, r1, r2 +;CHECK: 02 ??? +;CHECK: 03 ??? +;CHECK: b0 ??? +;CHECK: f3 ??? + +arm-linux-android NULL 44 26 1f e5 0c 10 4b e2 02 20 81 e0 +;CHECK: triple: arm-linux-android, features: NULL ;CHECK: ldr r2, [pc, #-1604] ;CHECK: sub r1, r11, #12 ;CHECK: 02 20 81 e0 ;CHECK: add r2, r1, r2 -x86_64-linux-unknown 48 83 c4 38 5b 5d 41 5c 41 5d 41 5e 41 5f c3 -;CHECK: triple: x86_64-linux-unknown +x86_64-linux-unknown NULL 48 83 c4 38 5b 5d 41 5c 41 5d 41 5e 41 5f c3 +;CHECK: triple: x86_64-linux-unknown, features: NULL ;CHECK: addq $56, %rsp ;CHECK: popq %rbx ;CHECK: popq %rbp @@ -19,11 +31,13 @@ x86_64-linux-unknown 48 83 c4 38 5b 5d 41 5c 41 5d 41 5e 41 5f c3 ;CHECK: popq %r15 ;CHECK: ret -i686-apple-darwin 0f b7 4c 24 0a e8 29 ce ff ff +i686-apple-darwin NULL 0f b7 4c 24 0a e8 29 ce ff ff +;CHECK: triple: i686-apple-darwin, features: NULL ;CHECK: movzwl 10(%esp), %ecx ;CHECK: calll -12759 -i686-linux-unknown dd 44 24 04 d9 e1 c3 +i686-linux-unknown NULL dd 44 24 04 d9 e1 c3 +;CHECK: triple: i686-linux-unknown, features: NULL ;CHECK: fldl 4(%esp) ;CHECK: fabs ;CHECK: ret diff --git a/test/Bindings/llvm-c/objectfile.ll b/test/Bindings/llvm-c/objectfile.ll new file mode 100644 index 0000000..b6cb4a0 --- /dev/null +++ b/test/Bindings/llvm-c/objectfile.ll @@ -0,0 +1,2 @@ +; RUN: not llvm-c-test --object-list-sections < /dev/null +; This used to cause a segfault |