Fix unsafetyck disabling for custom MIR

This commit is contained in:
Jakob Degen 2022-12-03 23:54:55 -08:00
parent 21ee03e062
commit c1b27eea45
4 changed files with 30 additions and 1 deletions

View File

@ -533,6 +533,11 @@ impl<'tcx> Body<'tcx> {
};
injection_phase > self.phase
}
#[inline]
pub fn is_custom_mir(&self) -> bool {
self.injection_phase.is_some()
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, TyEncodable, TyDecodable, HashStable)]

View File

@ -500,7 +500,7 @@ fn unsafety_check_result<'tcx>(
// `mir_built` force this.
let body = &tcx.mir_built(def).borrow();
if body.should_skip() {
if body.is_custom_mir() {
return tcx.arena.alloc(UnsafetyCheckResult {
violations: Vec::new(),
used_unsafe_blocks: FxHashSet::default(),

View File

@ -0,0 +1,10 @@
// MIR for `raw_pointer` after built
fn raw_pointer(_1: *const i32) -> *const i32 {
let mut _0: *const i32; // return place in scope 0 at $DIR/references.rs:+0:38: +0:48
bb0: {
_0 = &raw const (*_1); // scope 0 at $DIR/references.rs:+4:9: +4:27
return; // scope 0 at $DIR/references.rs:+5:9: +5:17
}
}

View File

@ -36,8 +36,22 @@ pub fn immut_ref(x: &i32) -> &i32 {
)
}
// EMIT_MIR references.raw_pointer.built.after.mir
#[custom_mir(dialect = "built")]
pub fn raw_pointer(x: *const i32) -> *const i32 {
// Regression test for a bug in which unsafetyck was not correctly turned off for
// `dialect = "built"`
mir!({
RET = addr_of!(*x);
Return()
})
}
fn main() {
let mut x = 5;
assert_eq!(*mut_ref(&mut x), 5);
assert_eq!(*immut_ref(&x), 5);
unsafe {
assert_eq!(*raw_pointer(addr_of!(x)), 5);
}
}