From 0350f2faa97229c49ac2b7efb7058ae7abf0232b Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 20 Jul 2018 14:20:37 +0200 Subject: [PATCH] Don't panic on intrinsics --- example.rs | 15 ++++++++++++++- src/abi.rs | 2 ++ src/base.rs | 2 +- src/constant.rs | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/example.rs b/example.rs index f0078c5a239c..027d0ba95424 100644 --- a/example.rs +++ b/example.rs @@ -1,4 +1,4 @@ -#![feature(no_core, lang_items)] +#![feature(no_core, lang_items, intrinsics)] #![no_core] #![allow(dead_code)] @@ -68,6 +68,10 @@ unsafe fn drop_in_place(to_drop: *mut T) { drop_in_place(to_drop); } +extern "rust-intrinsic" { + fn copy(src: *const T, dst: *mut T, count: usize); +} + fn abc(a: u8) -> u8 { a * 2 } @@ -144,3 +148,12 @@ struct DebugTuple(()); fn debug_tuple() -> DebugTuple { DebugTuple(()) } + +unsafe fn use_copy_intrinsic(src: *const u8, dst: *mut u8) { + copy::(src, dst, 1); +} + +/*unsafe fn use_copy_intrinsic_ref(src: *const u8, dst: *mut u8) { + let copy2 = ©::; + copy2(src, dst, 1); +}*/ diff --git a/src/abi.rs b/src/abi.rs index 85210e876384..01e2bc69fc70 100644 --- a/src/abi.rs +++ b/src/abi.rs @@ -15,6 +15,8 @@ pub fn cton_sig_from_fn_ty<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn_ty: Ty< unimplemented!(); } Abi::System => bug!("system abi should be selected elsewhere"), + // TODO: properly implement intrinsics + Abi::RustIntrinsic => (CallConv::SystemV, sig.inputs().to_vec(), sig.output()), _ => unimplemented!("unsupported abi {:?}", sig.abi), }; Signature { diff --git a/src/base.rs b/src/base.rs index 49a0b30919f2..1186f5138558 100644 --- a/src/base.rs +++ b/src/base.rs @@ -322,7 +322,7 @@ fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, cur_ebb: Ebb, stmt: & } }, Rvalue::Cast(CastKind::ClosureFnPointer, operand, ty) => unimplemented!("rval closure_fn_ptr {:?} {:?}", operand, ty), - Rvalue::Cast(CastKind::Unsize, operand, ty) => unimplemented!("rval unsize {:?} {:?}", operand, ty), + Rvalue::Cast(CastKind::Unsize, operand, ty) => return Err(format!("rval unsize {:?} {:?}", operand, ty)), Rvalue::Discriminant(place) => { let place = trans_place(fx, place); let dest_cton_ty = fx.cton_type(dest_layout.ty).unwrap(); diff --git a/src/constant.rs b/src/constant.rs index 2e17b318fcb5..70b82cee8622 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -14,6 +14,7 @@ pub fn trans_constant<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, const_: &Cons })) .unwrap(), }; + fx.tcx.sess.warn(&format!("const: {:?}", value)); let ty = fx.monomorphize(&const_.ty); let layout = fx.layout_of(ty);