OCaml bindings: add some missing functions and testcases.
[oota-llvm.git] / test / Bindings / Ocaml / vmcore.ml
index 1b7200b19f47cb741e06436c3d9cc583a412cab1..9329286286608d71aea517c054e048c0c295855f 100644 (file)
@@ -1,6 +1,7 @@
 (* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_analysis.cmxa llvm_bitwriter.cmxa %s -o %t
- * RUN: ./%t %t.bc
+ * RUN: %t %t.bc
  * RUN: llvm-dis < %t.bc > %t.ll
+ * XFAIL: vg_leak
  *)
 
 (* Note: It takes several seconds for ocamlopt to link an executable with
@@ -58,7 +59,6 @@ let suite name f =
 
 let filename = Sys.argv.(1)
 let m = create_module context filename
-let mp = ModuleProvider.create m
 
 
 (*===-- Target ------------------------------------------------------------===*)
@@ -80,130 +80,6 @@ let test_target () =
     insist (layout = data_layout m)
   end
 
-(*===-- Types -------------------------------------------------------------===*)
-
-let test_types () =
-  (* RUN: grep {void_type.*void} < %t.ll
-   *)
-  group "void";
-  insist (define_type_name "void_type" void_type m);
-  insist (TypeKind.Void == classify_type void_type);
-
-  (* RUN: grep {i1_type.*i1} < %t.ll
-   *)
-  group "i1";
-  insist (define_type_name "i1_type" i1_type m);
-  insist (TypeKind.Integer == classify_type i1_type);
-
-  (* RUN: grep {i32_type.*i32} < %t.ll
-   *)
-  group "i32";
-  insist (define_type_name "i32_type" i32_type m);
-
-  (* RUN: grep {i42_type.*i42} < %t.ll
-   *)
-  group "i42";
-  let ty = integer_type context 42 in
-  insist (define_type_name "i42_type" ty m);
-
-  (* RUN: grep {float_type.*float} < %t.ll
-   *)
-  group "float";
-  insist (define_type_name "float_type" float_type m);
-  insist (TypeKind.Float == classify_type float_type);
-
-  (* RUN: grep {double_type.*double} < %t.ll
-   *)
-  group "double";
-  insist (define_type_name "double_type" double_type m);
-  insist (TypeKind.Double == classify_type double_type);
-
-  (* RUN: grep {function_type.*i32.*i1, double} < %t.ll
-   *)
-  group "function";
-  let ty = function_type i32_type [| i1_type; double_type |] in
-  insist (define_type_name "function_type" ty m);
-  insist (TypeKind.Function = classify_type ty);
-  insist (not (is_var_arg ty));
-  insist (i32_type == return_type ty);
-  insist (double_type == (param_types ty).(1));
-  
-  (* RUN: grep {var_arg_type.*\.\.\.} < %t.ll
-   *)
-  group "var arg function";
-  let ty = var_arg_function_type void_type [| i32_type |] in
-  insist (define_type_name "var_arg_type" ty m);
-  insist (is_var_arg ty);
-  
-  (* RUN: grep {array_type.*\\\[7 x i8\\\]} < %t.ll
-   *)
-  group "array";
-  let ty = array_type i8_type 7 in
-  insist (define_type_name "array_type" ty m);
-  insist (7 = array_length ty);
-  insist (i8_type == element_type ty);
-  insist (TypeKind.Array == classify_type ty);
-  
-  begin group "pointer";
-    (* RUN: grep {pointer_type.*float\*} < %t.ll
-     *)
-    let ty = pointer_type float_type in
-    insist (define_type_name "pointer_type" ty m);
-    insist (float_type == element_type ty);
-    insist (0 == address_space ty);
-    insist (TypeKind.Pointer == classify_type ty)
-  end;
-  
-  begin group "qualified_pointer";
-    (* RUN: grep {qualified_pointer_type.*i8.*3.*\*} < %t.ll
-     *)
-    let ty = qualified_pointer_type i8_type 3 in
-    insist (define_type_name "qualified_pointer_type" ty m);
-    insist (i8_type == element_type ty);
-    insist (3 == address_space ty)
-  end;
-  
-  (* RUN: grep {vector_type.*\<4 x i16\>} < %t.ll
-   *)
-  group "vector";
-  let ty = vector_type i16_type 4 in
-  insist (define_type_name "vector_type" ty m);
-  insist (i16_type == element_type ty);
-  insist (4 = vector_size ty);
-  
-  (* RUN: grep {opaque_type.*opaque} < %t.ll
-   *)
-  group "opaque";
-  let ty = opaque_type context in
-  insist (define_type_name "opaque_type" ty m);
-  insist (ty == ty);
-  insist (ty <> opaque_type context);
-  
-  (* RUN: grep -v {delete_type} < %t.ll
-   *)
-  group "delete";
-  let ty = opaque_type context in
-  insist (define_type_name "delete_type" ty m);
-  delete_type_name "delete_type" m;
-
-  (* RUN: grep {type_name.*opaque} < %t.ll
-   *)
-  group "type_name"; begin
-    let ty = opaque_type context in
-    insist (define_type_name "type_name" ty m);
-    insist ((type_by_name m "type_name") = Some ty)
-  end;
-  
-  (* RUN: grep -v {recursive_type.*recursive_type} < %t.ll
-   *)
-  group "recursive";
-  let ty = opaque_type context in
-  let th = handle_to_type ty in
-  refine_type ty (pointer_type ty);
-  let ty = type_of_handle th in
-  insist (define_type_name "recursive_type" ty m);
-  insist (ty == element_type ty)
-
 
 (*===-- Constants ---------------------------------------------------------===*)
 
@@ -297,12 +173,6 @@ 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
    *)
   group "null";
@@ -437,7 +307,7 @@ let test_constants () =
    * 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
+   * RUN: grep {const_shufflevector = global <4 x i32> <i32 0, i32 1, i32 1, i32 0>} < %t.ll
    *)
   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 +326,8 @@ 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
@@ -466,6 +337,16 @@ let test_constants () =
       "{cx},{ax},{di},~{dirflag},~{fpsr},~{flags},~{edi},~{ecx}"
       true
       false)
+  end;
+
+  group "recursive struct"; begin
+      let nsty = named_struct_type context "rec" in
+      let pty = pointer_type nsty in
+      struct_set_body nsty [| i32_type; pty |] false;
+      let elts = [| const_int i32_type 4; const_pointer_null pty |] in
+      let grec_init = const_named_struct nsty elts in
+      ignore (define_global "grec" grec_init m);
+      ignore (string_of_lltype nsty);
   end
 
 
@@ -606,6 +487,58 @@ let test_global_variables () =
     dispose_module m
   end
 
+
+(*===-- 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 () =
@@ -899,6 +832,18 @@ let test_builder () =
     let b = builder_at_end context (append_block context "Bb01" fn) in
     ignore (build_ret_void b)
   end;
+
+  group "ret aggregate";
+  begin
+      (* RUN: grep {ret \{ i8, i64 \} \{ i8 4, i64 5 \}} < %t.ll
+       *)
+      let sty = struct_type context [| i8_type; i64_type |] in
+      let fty = function_type sty [| |] in
+      let fn = declare_function "XA6" fty m in
+      let b = builder_at_end context (append_block context "Bb01" fn) in
+      let agg = [| const_int i8_type 4; const_int i64_type 5 |] in
+      ignore (build_aggregate_ret agg b)
+  end;
   
   (* The rest of the tests will use one big function. *)
   let fty = function_type i32_type [| i32_type; i32_type |] in
@@ -911,7 +856,44 @@ let test_builder () =
   
   let bb00 = append_block context "Bb00" fn in
   ignore (build_unreachable (builder_at_end context bb00));
-  
+
+  group "function attribute";
+  begin
+      ignore (add_function_attr fn Attribute.UWTable);
+      (* RUN: grep "X7.*uwtable" < %t.ll
+       *)
+      insist ([Attribute.UWTable] = function_attr fn);
+  end;
+
+  (* see test/Feature/exception.ll *)
+  let bblpad = append_block context "Bblpad" fn in
+  let rt = struct_type context [| pointer_type i8_type; i32_type |] in
+  let ft = var_arg_function_type i32_type  [||] in
+  let personality = declare_function "__gxx_personality_v0" ft m in
+  let ztic = declare_global (pointer_type i8_type) "_ZTIc" m in
+  let ztid = declare_global (pointer_type i8_type) "_ZTId" m in
+  let ztipkc = declare_global (pointer_type i8_type) "_ZTIPKc" m in
+  begin
+      set_global_constant true ztic;
+      set_global_constant true ztid;
+      set_global_constant true ztipkc;
+      let lp = build_landingpad rt personality 0 "lpad"
+       (builder_at_end context bblpad) in begin
+           set_cleanup lp true;
+           add_clause lp ztic;
+           insist((pointer_type (pointer_type i8_type)) = type_of ztid);
+           let ety = pointer_type (pointer_type i8_type) in
+           add_clause lp (const_array ety [| ztipkc; ztid |]);
+           ignore (build_resume lp (builder_at_end context bblpad));
+      end;
+      (* RUN: grep "landingpad.*personality.*__gxx_personality_v0" < %t.ll
+       * RUN: grep "cleanup" < %t.ll
+       * RUN: grep "catch.*i8\*\*.*@_ZTIc" < %t.ll
+       * RUN: grep "filter.*@_ZTIPKc.*@_ZTId" < %t.ll
+       * RUN: grep "resume " < %t.ll
+       * *)
+  end;
+
   group "ret"; begin
     (* RUN: grep {ret.*P1} < %t.ll
      *)
@@ -945,8 +927,23 @@ let test_builder () =
     ignore (build_unreachable (builder_at_end context bb2));
     let bb3 = append_block context "SwiBlock3" fn in
     ignore (build_unreachable (builder_at_end context bb3));
-    let si = build_switch p1 bb3 1 (builder_at_end context bb1) in
-    ignore (add_case si (const_int i32_type 2) bb2)
+    let si = build_switch p1 bb3 1 (builder_at_end context bb1) in begin
+        ignore (add_case si (const_int i32_type 2) bb2);
+        insist (switch_default_dest si = bb3);
+    end;
+  end;
+
+  group "malloc/free"; begin
+      (* RUN: grep {call.*@malloc(i32 ptrtoint} < %t.ll
+       * RUN: grep {call.*@free(i8\*} < %t.ll
+       * RUN: grep {call.*@malloc(i32 %} < %t.ll
+       *)
+      let bb1 = append_block context "MallocBlock1" fn in
+      let m1 = (build_malloc (pointer_type i32_type) "m1"
+      (builder_at_end context bb1)) in
+      ignore (build_free m1 (builder_at_end context bb1));
+      ignore (build_array_malloc i32_type p1 "m2" (builder_at_end context bb1));
+      ignore (build_unreachable (builder_at_end context bb1));
   end;
 
   group "indirectbr"; begin
@@ -968,19 +965,11 @@ let test_builder () =
   
   group "invoke"; begin
     (* RUN: grep {build_invoke.*invoke.*P1.*P2} < %t.ll
-     * RUN: grep {to.*Bb04.*unwind.*Bb00} < %t.ll
+     * RUN: grep {to.*Bb04.*unwind.*Bblpad} < %t.ll
      *)
     let bb04 = append_block context "Bb04" fn in
     let b = builder_at_end context bb04 in
-    ignore (build_invoke fn [| p1; p2 |] bb04 bb00 "build_invoke" b)
-  end;
-  
-  group "unwind"; begin
-    (* RUN: grep {unwind} < %t.ll
-     *)
-    let bb05 = append_block context "Bb05" fn in
-    let b = builder_at_end context bb05 in
-    ignore (build_unwind b)
+    ignore (build_invoke fn [| p1; p2 |] bb04 bblpad "build_invoke" b)
   end;
   
   group "unreachable"; begin
@@ -1068,30 +1057,63 @@ let test_builder () =
      * RUN: grep {%build_load = load i32\\* %build_array_alloca} < %t.ll
      * RUN: grep {store i32 %P2, i32\\* %build_alloca} < %t.ll
      * RUN: grep {%build_gep = getelementptr i32\\* %build_array_alloca, i32 %P2} < %t.ll
+     * RUN: grep {%build_in_bounds_gep = getelementptr inbounds i32\\* %build_array_alloca, i32 %P2} < %t.ll
+     * RUN: grep {%build_struct_gep = getelementptr inbounds.*%build_alloca2, i32 0, i32 1} < %t.ll
      *)
     let alloca = build_alloca i32_type "build_alloca" b in
     let array_alloca = build_array_alloca i32_type p2 "build_array_alloca" b in
     ignore(build_load array_alloca "build_load" b);
     ignore(build_store p2 alloca b);
     ignore(build_gep array_alloca [| p2 |] "build_gep" b);
+    ignore(build_in_bounds_gep array_alloca [| p2 |] "build_in_bounds_gep" b);
+
+    let sty = struct_type context [| i32_type; i8_type |] in
+    let alloca2 = build_alloca sty "build_alloca2" b in
+    ignore(build_struct_gep alloca2 1 "build_struct_gep" b);
+
     ignore(build_unreachable b)
   end;
-  
+
+  group "string"; begin
+    let bb09 = append_block context "Bb09" fn in
+    let b = builder_at_end context bb09 in
+    let p = build_alloca (pointer_type i8_type) "p" b in
+    (* RUN: grep "build_global_string.*stringval" < %t.ll
+     * RUN: grep "store.*build_global_string1.*p" < %t.ll
+     * *)
+    ignore (build_global_string "stringval" "build_global_string" b);
+    let g = build_global_stringptr "stringval" "build_global_string1" b in
+    ignore (build_store g p b);
+    ignore(build_unreachable b);
+  end;
+
   group "casts"; begin
     let void_ptr = pointer_type i8_type in
     
     (* RUN: grep {%build_trunc = trunc i32 %P1 to i8} < %t.ll
+     * RUN: grep {%build_trunc2 = trunc i32 %P1 to i8} < %t.ll
+     * RUN: grep {%build_trunc3 = trunc i32 %P1 to i8} < %t.ll
      * RUN: grep {%build_zext = zext i8 %build_trunc to i32} < %t.ll
+     * RUN: grep {%build_zext2 = zext i8 %build_trunc to i32} < %t.ll
      * RUN: grep {%build_sext = sext i32 %build_zext to i64} < %t.ll
+     * RUN: grep {%build_sext2 = sext i32 %build_zext to i64} < %t.ll
+     * RUN: grep {%build_sext3 = sext i32 %build_zext to i64} < %t.ll
      * RUN: grep {%build_uitofp = uitofp i64 %build_sext to float} < %t.ll
      * RUN: grep {%build_sitofp = sitofp i32 %build_zext to double} < %t.ll
      * RUN: grep {%build_fptoui = fptoui float %build_uitofp to i32} < %t.ll
      * RUN: grep {%build_fptosi = fptosi double %build_sitofp to i64} < %t.ll
      * RUN: grep {%build_fptrunc = fptrunc double %build_sitofp to float} < %t.ll
+     * RUN: grep {%build_fptrunc2 = fptrunc double %build_sitofp to float} < %t.ll
      * RUN: grep {%build_fpext = fpext float %build_fptrunc to double} < %t.ll
+     * RUN: grep {%build_fpext2 = fpext float %build_fptrunc to double} < %t.ll
      * RUN: grep {%build_inttoptr = inttoptr i32 %P1 to i8\\*} < %t.ll
      * RUN: grep {%build_ptrtoint = ptrtoint i8\\* %build_inttoptr to i64} < %t.ll
+     * RUN: grep {%build_ptrtoint2 = ptrtoint i8\\* %build_inttoptr to i64} < %t.ll
      * RUN: grep {%build_bitcast = bitcast i64 %build_ptrtoint to double} < %t.ll
+     * RUN: grep {%build_bitcast2 = bitcast i64 %build_ptrtoint to double} < %t.ll
+     * RUN: grep {%build_bitcast3 = bitcast i64 %build_ptrtoint to double} < %t.ll
+     * RUN: grep {%build_bitcast4 = bitcast i64 %build_ptrtoint to double} < %t.ll
+     * RUN: grep {%build_pointercast = bitcast i8\\* %build_inttoptr to i16\\*} < %t.ll
      *)
     let inst28 = build_trunc p1 i8_type "build_trunc" atentry in
     let inst29 = build_zext inst28 i32_type "build_zext" atentry in
@@ -1104,19 +1126,42 @@ let test_builder () =
     ignore(build_fpext inst35 double_type "build_fpext" atentry);
     let inst37 = build_inttoptr p1 void_ptr "build_inttoptr" atentry in
     let inst38 = build_ptrtoint inst37 i64_type "build_ptrtoint" atentry in
-    ignore(build_bitcast inst38 double_type "build_bitcast" atentry)
+    ignore(build_bitcast inst38 double_type "build_bitcast" atentry);
+    ignore(build_zext_or_bitcast inst38 double_type "build_bitcast2" atentry);
+    ignore(build_sext_or_bitcast inst38 double_type "build_bitcast3" atentry);
+    ignore(build_trunc_or_bitcast inst38 double_type "build_bitcast4" atentry);
+    ignore(build_pointercast inst37 (pointer_type i16_type) "build_pointercast" atentry);
+
+    ignore(build_zext_or_bitcast inst28 i32_type "build_zext2" atentry);
+    ignore(build_sext_or_bitcast inst29 i64_type "build_sext2" atentry);
+    ignore(build_trunc_or_bitcast p1 i8_type "build_trunc2" atentry);
+    ignore(build_pointercast inst37 i64_type "build_ptrtoint2" atentry);
+    ignore(build_intcast inst29 i64_type "build_sext3" atentry);
+    ignore(build_intcast p1 i8_type "build_trunc3" atentry);
+    ignore(build_fpcast inst35 double_type "build_fpext2" atentry);
+    ignore(build_fpcast inst32 float_type "build_fptrunc2" atentry);
   end;
   
   group "comparisons"; begin
     (* 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
+     * RUN: grep {%build_fcmp_false = fcmp false float %F1, %F2} < %t.ll
+     * RUN: grep {%build_fcmp_true = fcmp true float %F2, %F1} < %t.ll
+     * RUN: grep {%build_is_null.*= icmp eq.*%X0,.*null} < %t.ll
+     * RUN: grep {%build_is_not_null = icmp ne i8\\* %X1, null} < %t.ll
+     * RUN: grep {%build_ptrdiff} < %t.ll
      *)
     ignore (build_icmp Icmp.Ne    p1 p2 "build_icmp_ne" atentry);
     ignore (build_icmp Icmp.Sle   p2 p1 "build_icmp_sle" atentry);
-    ignore (build_fcmp Fcmp.False f1 f2 "build_icmp_false" atentry);
-    ignore (build_fcmp Fcmp.True  f2 f1 "build_icmp_true" 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
@@ -1126,6 +1171,8 @@ let test_builder () =
      * RUN: grep {%build_extractelement = extractelement <4 x i32> %Vec1, i32 %P2} < %t.ll
      * RUN: grep {%build_insertelement = insertelement <4 x i32> %Vec1, i32 %P1, i32 %P2} < %t.ll
      * RUN: grep {%build_shufflevector = shufflevector <4 x i32> %Vec1, <4 x i32> %Vec2, <4 x i32> <i32 1, i32 1, i32 0, i32 0>} < %t.ll
+     * RUN: grep {%build_insertvalue0 = insertvalue.*%bl, i32 1, 0} < %t.ll
+     * RUN: grep {%build_extractvalue = extractvalue.*%build_insertvalue1, 1} < %t.ll
      *)
     let ci = build_call fn [| p2; p1 |] "build_call" atentry in
     insist (CallConv.c = instruction_call_conv ci);
@@ -1152,10 +1199,19 @@ let test_builder () =
     let t3 = const_vector [| one; one; zero; zero |] in
     let vec1 = build_insertelement t1 p1 p2 "Vec1" atentry in
     let vec2 = build_insertelement t2 p1 p2 "Vec2" atentry in
+    let sty = struct_type context [| i32_type; i8_type |] in
     
     ignore (build_extractelement vec1 p2 "build_extractelement" atentry);
     ignore (build_insertelement vec1 p1 p2 "build_insertelement" atentry);
     ignore (build_shufflevector vec1 vec2 t3 "build_shufflevector" atentry);
+
+    let p = build_alloca sty "ba" atentry in
+    let agg = build_load p "bl" atentry in
+    let agg0 = build_insertvalue agg (const_int i32_type 1) 0
+                 "build_insertvalue0" atentry in
+    let agg1 = build_insertvalue agg0 (const_int i8_type 2) 1
+                 "build_insertvalue1" atentry in
+    ignore (build_extractvalue agg1 1 "build_extractvalue" atentry)
   end;
 
   group "metadata"; begin
@@ -1185,13 +1241,19 @@ let test_builder () =
 
   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
+     * RUN: grep {!1 = metadata !\{i32 2, i32 3, metadata !2, metadata !2\}} < %t.ll
      *)
-    let m1 = const_int i32_type 2 in
-    let m2 = mdstring context "dbg test" in
-    let md = mdnode context [| m1; m2 |] in
+    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);
 
@@ -1219,14 +1281,6 @@ let test_builder () =
   end
 
 
-(*===-- Module Provider ---------------------------------------------------===*)
-
-let test_module_provider () =
-  let m = create_module context "test" in
-  let mp = ModuleProvider.create m in
-  ModuleProvider.dispose mp
-
-
 (*===-- Pass Managers -----------------------------------------------------===*)
 
 let test_pass_manager () =
@@ -1243,7 +1297,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
@@ -1262,24 +1316,24 @@ let test_writer () =
   group "writer";
   insist (write_bitcode_file m filename);
   
-  ModuleProvider.dispose mp
+  dispose_module m
 
 
 (*===-- Driver ------------------------------------------------------------===*)
 
 let _ =
   suite "target"           test_target;
-  suite "types"            test_types;
   suite "constants"        test_constants;
   suite "global values"    test_global_values;
   suite "global variables" test_global_variables;
+  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 "writer"           test_writer; (* Keep this last; it disposes m. *)
   exit !exit_status