+ 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> <i32 1, i32 1, i32 0, i32 0>
+ * 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;
+