Replace llvm intrinsics with runtime trap

This commit is contained in:
bjorn3 2019-07-28 09:54:57 +02:00
parent 90f2b12d47
commit 1a26891170
3 changed files with 27 additions and 0 deletions

View File

@ -643,6 +643,11 @@ pub fn codegen_terminator_call<'a, 'tcx: 'a>(
let instance =
ty::Instance::resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap();
if fx.tcx.symbol_name(instance).as_str().starts_with("llvm.") {
crate::llvm_intrinsics::codegen_llvm_intrinsic_call(fx, &fx.tcx.symbol_name(instance).as_str(), substs, args, destination);
return;
}
match instance.def {
InstanceDef::Intrinsic(_) => {
crate::intrinsics::codegen_intrinsic_call(fx, def_id, substs, args, destination);

View File

@ -40,6 +40,7 @@ mod debuginfo;
mod driver;
mod intrinsics;
mod linkage;
mod llvm_intrinsics;
mod main_shim;
mod metadata;
mod pretty_clif;

21
src/llvm_intrinsics.rs Normal file
View File

@ -0,0 +1,21 @@
use crate::prelude::*;
use rustc::ty::subst::SubstsRef;
pub fn codegen_llvm_intrinsic_call<'a, 'tcx: 'a>(
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
intrinsic: &str,
substs: SubstsRef<'tcx>,
args: Vec<CValue<'tcx>>,
destination: Option<(CPlace<'tcx>, BasicBlock)>,
) {
fx.tcx.sess.warn(&format!("unsupported llvm intrinsic {}; replacing with trap", intrinsic));
crate::trap::trap_unimplemented(fx, intrinsic);
if let Some((_, dest)) = destination {
let ret_ebb = fx.get_ebb(dest);
fx.bcx.ins().jump(ret_ebb, &[]);
} else {
trap_unreachable(fx, "[corruption] Diverging intrinsic returned.");
}
}