diff --git a/example.rs b/example.rs index 37161b87380..1f9a5e0755b 100644 --- a/example.rs +++ b/example.rs @@ -147,3 +147,7 @@ fn eq_char(a: char, b: char) -> bool { unsafe fn transmute(c: char) -> u32 { intrinsics::transmute(c) } + +unsafe fn call_uninit() -> u8 { + intrinsics::uninit() +} diff --git a/mini_core.rs b/mini_core.rs index 115746d61c9..9ecfd5113ff 100644 --- a/mini_core.rs +++ b/mini_core.rs @@ -118,5 +118,6 @@ pub mod intrinsics { pub fn size_of() -> usize; pub fn copy(src: *const T, dst: *mut T, count: usize); pub fn transmute(e: T) -> U; + pub fn uninit() -> T; } } diff --git a/src/abi.rs b/src/abi.rs index 6bef83a5bb7..cc22ef06080 100644 --- a/src/abi.rs +++ b/src/abi.rs @@ -252,6 +252,9 @@ pub fn codegen_call<'a, 'tcx: 'a>( let usize_layout = fx.layout_of(fx.tcx.types.usize); let ret = return_place.unwrap(); match intrinsic { + "abort" => { + fx.bcx.ins().trap(TrapCode::User(!0 - 1)); + } "copy" | "copy_nonoverlapping" => { /*let elem_ty = substs.type_at(0); assert_eq!(args.len(), 3); @@ -266,6 +269,18 @@ pub fn codegen_call<'a, 'tcx: 'a>( let size_of = CValue::const_val(fx, usize_layout.ty, size_of as i64); ret.write_cvalue(fx, size_of); } + "type_id" => { + assert_eq!(args.len(), 0); + let type_id = fx.tcx.type_id_hash(substs.type_at(0)); + let type_id = CValue::const_val(fx, usize_layout.ty, type_id as i64); + ret.write_cvalue(fx, type_id); + } + "min_align_of" => { + assert_eq!(args.len(), 0); + let min_align = fx.layout_of(substs.type_at(0)).align.abi(); + let min_align = CValue::const_val(fx, usize_layout.ty, min_align as i64); + ret.write_cvalue(fx, min_align); + } _ if intrinsic.starts_with("unchecked_") => { assert_eq!(args.len(), 2); let lhs = args[0].load_value(fx); @@ -304,6 +319,20 @@ pub fn codegen_call<'a, 'tcx: 'a>( let dst_layout = fx.layout_of(dst_ty); ret.write_cvalue(fx, CValue::ByRef(addr, dst_layout)) } + "uninit" => { + assert_eq!(args.len(), 0); + let ty = substs.type_at(0); + let layout = fx.layout_of(ty); + let stack_slot = fx.bcx.create_stack_slot(StackSlotData { + kind: StackSlotKind::ExplicitSlot, + size: layout.size.bytes() as u32, + offset: None, + }); + + let uninit_place = CPlace::from_stack_slot(fx, stack_slot, ty); + let uninit_val = uninit_place.to_cvalue(fx); + ret.write_cvalue(fx, uninit_val); + } _ => fx.tcx.sess.fatal(&format!("unsupported intrinsic {}", intrinsic)), } if let Some((_, dest)) = *destination { diff --git a/src/base.rs b/src/base.rs index 6c060be973b..e65abd0ddd7 100644 --- a/src/base.rs +++ b/src/base.rs @@ -501,7 +501,7 @@ pub fn trans_int_binop<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, bin_op: BinO fn trans_float_binop<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, bin_op: BinOp, lhs: Value, rhs: Value, ty: Ty<'tcx>) -> CValue<'tcx> { let res = binop_match! { - fx, bin_op, false, lhs, rhs, "bool"; + fx, bin_op, false, lhs, rhs, "float"; Add (_) fadd; Sub (_) fsub; Mul (_) fmul;