Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1a26891

Browse files
committed
Replace llvm intrinsics with runtime trap
1 parent 90f2b12 commit 1a26891

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/abi.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,11 @@ pub fn codegen_terminator_call<'a, 'tcx: 'a>(
643643
let instance =
644644
ty::Instance::resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap();
645645

646+
if fx.tcx.symbol_name(instance).as_str().starts_with("llvm.") {
647+
crate::llvm_intrinsics::codegen_llvm_intrinsic_call(fx, &fx.tcx.symbol_name(instance).as_str(), substs, args, destination);
648+
return;
649+
}
650+
646651
match instance.def {
647652
InstanceDef::Intrinsic(_) => {
648653
crate::intrinsics::codegen_intrinsic_call(fx, def_id, substs, args, destination);

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ mod debuginfo;
4040
mod driver;
4141
mod intrinsics;
4242
mod linkage;
43+
mod llvm_intrinsics;
4344
mod main_shim;
4445
mod metadata;
4546
mod pretty_clif;

src/llvm_intrinsics.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::prelude::*;
2+
3+
use rustc::ty::subst::SubstsRef;
4+
5+
pub fn codegen_llvm_intrinsic_call<'a, 'tcx: 'a>(
6+
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
7+
intrinsic: &str,
8+
substs: SubstsRef<'tcx>,
9+
args: Vec<CValue<'tcx>>,
10+
destination: Option<(CPlace<'tcx>, BasicBlock)>,
11+
) {
12+
fx.tcx.sess.warn(&format!("unsupported llvm intrinsic {}; replacing with trap", intrinsic));
13+
crate::trap::trap_unimplemented(fx, intrinsic);
14+
15+
if let Some((_, dest)) = destination {
16+
let ret_ebb = fx.get_ebb(dest);
17+
fx.bcx.ins().jump(ret_ebb, &[]);
18+
} else {
19+
trap_unreachable(fx, "[corruption] Diverging intrinsic returned.");
20+
}
21+
}

0 commit comments

Comments
 (0)