Skip to content

Commit 2405ac4

Browse files
committed
Remove transmute intrinsic code from interpret and codegen_ssa
1 parent 0905bad commit 2405ac4

File tree

2 files changed

+9
-49
lines changed

2 files changed

+9
-49
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_index::vec::Idx;
1616
use rustc_middle::mir::{self, AssertKind, SwitchTargets};
1717
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
1818
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
19-
use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt};
19+
use rustc_middle::ty::{self, Instance, Ty};
2020
use rustc_session::config::OptLevel;
2121
use rustc_span::source_map::Span;
2222
use rustc_span::{sym, Symbol};
@@ -782,6 +782,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
782782
_ => None,
783783
};
784784

785+
if let Some(intrinsic @ (sym::copy_nonoverlapping | sym::transmute)) = intrinsic {
786+
bug!("Intrinsic {intrinsic} should have been lowered before codegen");
787+
}
788+
785789
let extra_args = &args[sig.inputs().skip_binder().len()..];
786790
let extra_args = bx.tcx().mk_type_list(extra_args.iter().map(|op_arg| {
787791
let op_ty = op_arg.ty(self.mir, bx.tcx());
@@ -793,23 +797,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
793797
None => bx.fn_abi_of_fn_ptr(sig, extra_args),
794798
};
795799

796-
if intrinsic == Some(sym::transmute) {
797-
return if let Some(target) = target {
798-
self.codegen_transmute(bx, &args[0], destination);
799-
helper.funclet_br(self, bx, target, mergeable_succ)
800-
} else {
801-
// If we are trying to transmute to an uninhabited type,
802-
// it is likely there is no allotted destination. In fact,
803-
// transmuting to an uninhabited type is UB, which means
804-
// we can do what we like. Here, we declare that transmuting
805-
// into an uninhabited type is impossible, so anything following
806-
// it must be unreachable.
807-
assert_eq!(fn_abi.ret.layout.abi, abi::Abi::Uninhabited);
808-
bx.unreachable();
809-
MergingSucc::False
810-
};
811-
}
812-
813800
if let Some(merging_succ) = self.codegen_panic_intrinsic(
814801
&helper,
815802
bx,
@@ -852,7 +839,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
852839

853840
match intrinsic {
854841
None | Some(sym::drop_in_place) => {}
855-
Some(sym::copy_nonoverlapping) => unreachable!(),
856842
Some(intrinsic) => {
857843
let dest = match ret_dest {
858844
_ if fn_abi.ret.is_indirect() => llargs[0],
@@ -1763,32 +1749,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
17631749
}
17641750
}
17651751

1766-
fn codegen_transmute(&mut self, bx: &mut Bx, src: &mir::Operand<'tcx>, dst: mir::Place<'tcx>) {
1767-
if let Some(index) = dst.as_local() {
1768-
match self.locals[index] {
1769-
LocalRef::Place(place) => self.codegen_transmute_into(bx, src, place),
1770-
LocalRef::UnsizedPlace(_) => bug!("transmute must not involve unsized locals"),
1771-
LocalRef::Operand(None) => {
1772-
let dst_layout = bx.layout_of(self.monomorphized_place_ty(dst.as_ref()));
1773-
assert!(!dst_layout.ty.has_erasable_regions());
1774-
let place = PlaceRef::alloca(bx, dst_layout);
1775-
place.storage_live(bx);
1776-
self.codegen_transmute_into(bx, src, place);
1777-
let op = bx.load_operand(place);
1778-
place.storage_dead(bx);
1779-
self.locals[index] = LocalRef::Operand(Some(op));
1780-
self.debug_introduce_local(bx, index);
1781-
}
1782-
LocalRef::Operand(Some(op)) => {
1783-
assert!(op.layout.is_zst(), "assigning to initialized SSAtemp");
1784-
}
1785-
}
1786-
} else {
1787-
let dst = self.codegen_place(bx, dst.as_ref());
1788-
self.codegen_transmute_into(bx, src, dst);
1789-
}
1790-
}
1791-
17921752
pub(crate) fn codegen_transmute_into(
17931753
&mut self,
17941754
bx: &mut Bx,

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
124124
let substs = instance.substs;
125125
let intrinsic_name = self.tcx.item_name(instance.def_id());
126126

127+
if let sym::copy_nonoverlapping | sym::transmute = intrinsic_name {
128+
bug!("Intrinsic {intrinsic_name} should have been lowered before interpreting MIR");
129+
}
130+
127131
// First handle intrinsics without return place.
128132
let ret = match ret {
129133
None => match intrinsic_name {
130-
sym::transmute => throw_ub_format!("transmuting to uninhabited type"),
131134
sym::abort => M::abort(self, "the program aborted execution".to_owned())?,
132135
// Unsupported diverging intrinsic.
133136
_ => return Ok(false),
@@ -411,9 +414,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
411414
self.exact_div(&val, &size, dest)?;
412415
}
413416

414-
sym::transmute => {
415-
self.copy_op(&args[0], dest, /*allow_transmute*/ true)?;
416-
}
417417
sym::assert_inhabited
418418
| sym::assert_zero_valid
419419
| sym::assert_mem_uninitialized_valid => {

0 commit comments

Comments
 (0)