Add indirect br support to llvm-c and ocaml.
[oota-llvm.git] / test / Bindings / Ocaml / vmcore.ml
index 1ae8e606416f2bebbc4b1cf8b249eb69f8693d57..9a2f54753196d058e05d53b81854145d26d7820d 100644 (file)
@@ -288,6 +288,12 @@ let test_constants () =
   ignore (define_global "const_structure" c m);
   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
    *)
@@ -312,12 +318,25 @@ let test_constants () =
   
   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
@@ -335,12 +354,25 @@ let test_constants () =
   let foldbomb = const_ptrtoint foldbomb_gv i64_type in
   let ffoldbomb = const_uitofp foldbomb double_type in
   ignore (define_global "const_neg" (const_neg foldbomb) m);
+  ignore (define_global "const_nsw_neg" (const_nsw_neg foldbomb) m);
+  ignore (define_global "const_nuw_neg" (const_nuw_neg foldbomb) m);
+  ignore (define_global "const_fneg" (const_fneg ffoldbomb) m);
   ignore (define_global "const_not" (const_not foldbomb) m);
   ignore (define_global "const_add" (const_add foldbomb five) m);
+  ignore (define_global "const_nsw_add" (const_nsw_add foldbomb five) m);
+  ignore (define_global "const_nuw_add" (const_nuw_add foldbomb five) m);
+  ignore (define_global "const_fadd" (const_fadd ffoldbomb ffive) m);
   ignore (define_global "const_sub" (const_sub foldbomb five) m);
+  ignore (define_global "const_nsw_sub" (const_nsw_sub foldbomb five) m);
+  ignore (define_global "const_nuw_sub" (const_nuw_sub foldbomb five) m);
+  ignore (define_global "const_fsub" (const_fsub ffoldbomb ffive) m);
   ignore (define_global "const_mul" (const_mul foldbomb five) m);
+  ignore (define_global "const_nsw_mul" (const_nsw_mul foldbomb five) m);
+  ignore (define_global "const_nuw_mul" (const_nuw_mul foldbomb five) m);
+  ignore (define_global "const_fmul" (const_fmul ffoldbomb ffive) m);
   ignore (define_global "const_udiv" (const_udiv foldbomb five) m);
   ignore (define_global "const_sdiv" (const_sdiv foldbomb five) m);
+  ignore (define_global "const_exact_sdiv" (const_exact_sdiv foldbomb five) m);
   ignore (define_global "const_fdiv" (const_fdiv ffoldbomb ffive) m);
   ignore (define_global "const_urem" (const_urem foldbomb five) m);
   ignore (define_global "const_srem" (const_srem foldbomb five) m);
@@ -865,6 +897,23 @@ let test_builder () =
     let si = build_switch p1 bb3 1 (builder_at_end context bb1) in
     ignore (add_case si (const_int i32_type 2) bb2)
   end;
+
+  group "indirectbr"; begin
+    (* RUN: grep {indirectbr i8\\* blockaddress(@X7, %IBRBlock2), \\\[label %IBRBlock2, label %IBRBlock3\\\]} < %t.ll
+     *)
+    let bb1 = append_block context "IBRBlock1" fn in
+
+    let bb2 = append_block context "IBRBlock2" fn in
+    ignore (build_unreachable (builder_at_end context bb2));
+
+    let bb3 = append_block context "IBRBlock3" fn in
+    ignore (build_unreachable (builder_at_end context bb3));
+
+    let addr = block_address fn bb2 in
+    let ibr = build_indirect_br addr 2 (builder_at_end context bb1) in
+    ignore (add_destination ibr bb2);
+    ignore (add_destination ibr bb3)
+  end;
   
   group "invoke"; begin
     (* RUN: grep {build_invoke.*invoke.*P1.*P2} < %t.ll
@@ -896,10 +945,20 @@ let test_builder () =
     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
@@ -911,13 +970,26 @@ let test_builder () =
      * 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
      *)
     ignore (build_add p1 p2 "build_add" b);
+    ignore (build_nsw_add p1 p2 "build_nsw_add" b);
+    ignore (build_nuw_add p1 p2 "build_nuw_add" b);
+    ignore (build_fadd f1 f2 "build_fadd" b);
     ignore (build_sub p1 p2 "build_sub" b);
+    ignore (build_nsw_sub p1 p2 "build_nsw_sub" b);
+    ignore (build_nuw_sub p1 p2 "build_nuw_sub" b);
+    ignore (build_fsub f1 f2 "build_fsub" b);
     ignore (build_mul p1 p2 "build_mul" b);
+    ignore (build_nsw_mul p1 p2 "build_nsw_mul" b);
+    ignore (build_nuw_mul p1 p2 "build_nuw_mul" b);
+    ignore (build_fmul f1 f2 "build_fmul" b);
     ignore (build_udiv p1 p2 "build_udiv" b);
     ignore (build_sdiv p1 p2 "build_sdiv" b);
+    ignore (build_exact_sdiv p1 p2 "build_exact_sdiv" b);
     ignore (build_fdiv f1 f2 "build_fdiv" b);
     ignore (build_urem p1 p2 "build_urem" b);
     ignore (build_srem p1 p2 "build_srem" b);
@@ -929,6 +1001,9 @@ let test_builder () =
     ignore (build_or p1 p2 "build_or" b);
     ignore (build_xor p1 p2 "build_xor" b);
     ignore (build_neg p1 "build_neg" b);
+    ignore (build_nsw_neg p1 "build_nsw_neg" b);
+    ignore (build_nuw_neg p1 "build_nuw_neg" b);
+    ignore (build_fneg f1 "build_fneg" b);
     ignore (build_not p1 "build_not" b);
     ignore (build_unreachable b)
   end;
@@ -1031,6 +1106,46 @@ let test_builder () =
     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);
+
+    clear_metadata i kind;
+
+    insist ((has_metadata i) = false);
+    insist ((metadata i kind) = None);
+
+    set_metadata i kind md
+  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
+  end;
   
   group "phi"; begin
     (* RUN: grep {PhiNode.*P1.*PhiBlock1.*P2.*PhiBlock2} < %t.ll