Remove workaround for CastKind::Transmute from const prop

Since constants are no longer validated before propagation the
workaround is obsolete. Remove it.
This commit is contained in:
Tomasz Miąsko 2023-03-27 00:00:00 +00:00
parent bc41973e35
commit 4adb8fbda0
6 changed files with 19 additions and 15 deletions

View file

@ -501,16 +501,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
return None; return None;
} }
// Do not try creating references, nor any types with potentially-complex
// invariants. This avoids an issue where checking validity would do a
// bunch of work generating a nice message about the invariant violation,
// only to not show it to anyone (since this isn't the lint).
Rvalue::Cast(CastKind::Transmute, op, dst_ty) if !dst_ty.is_primitive() => {
trace!("skipping Transmute of {:?} to {:?}", op, dst_ty);
return None;
}
// There's no other checking to do at this time. // There's no other checking to do at this time.
Rvalue::Aggregate(..) Rvalue::Aggregate(..)
| Rvalue::Use(..) | Rvalue::Use(..)

View file

@ -7,7 +7,8 @@
} }
bb0: { bb0: {
_0 = const -1_i8 as bool (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:30 - _0 = const -1_i8 as bool (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:30
+ _0 = const {transmute(0xff): bool}; // scope 1 at $DIR/transmute.rs:+1:14: +1:30
return; // scope 0 at $DIR/transmute.rs:+2:2: +2:2 return; // scope 0 at $DIR/transmute.rs:+2:2: +2:2
} }
} }

View file

@ -7,7 +7,8 @@
} }
bb0: { bb0: {
_0 = const _ as char (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:33 - _0 = const _ as char (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:33
+ _0 = const {transmute(0x7fffffff): char}; // scope 1 at $DIR/transmute.rs:+1:14: +1:33
return; // scope 0 at $DIR/transmute.rs:+2:2: +2:2 return; // scope 0 at $DIR/transmute.rs:+2:2: +2:2
} }
} }

View file

@ -15,7 +15,11 @@
bb0: { bb0: {
StorageLive(_1); // scope 0 at $DIR/transmute.rs:+0:38: +3:2 StorageLive(_1); // scope 0 at $DIR/transmute.rs:+0:38: +3:2
StorageLive(_2); // scope 0 at $DIR/transmute.rs:+1:9: +1:10 StorageLive(_2); // scope 0 at $DIR/transmute.rs:+1:9: +1:10
_2 = const 1_usize as std::boxed::Box<Never> (Transmute); // scope 2 at $DIR/transmute.rs:+1:34: +1:52 - _2 = const 1_usize as std::boxed::Box<Never> (Transmute); // scope 2 at $DIR/transmute.rs:+1:34: +1:52
+ _2 = const Box::<Never>(Unique::<Never> {{ pointer: NonNull::<Never> {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData::<Never> }}, std::alloc::Global); // scope 2 at $DIR/transmute.rs:+1:34: +1:52
+ // mir::Constant
+ // + span: no-location
+ // + literal: Const { ty: Box<Never>, val: Value(Scalar(0x0000000000000001)) }
StorageLive(_3); // scope 1 at $DIR/transmute.rs:+2:5: +2:16 StorageLive(_3); // scope 1 at $DIR/transmute.rs:+2:5: +2:16
unreachable; // scope 1 at $DIR/transmute.rs:+2:11: +2:13 unreachable; // scope 1 at $DIR/transmute.rs:+2:11: +2:13
} }

View file

@ -17,7 +17,11 @@
StorageLive(_1); // scope 0 at $DIR/transmute.rs:+0:38: +3:2 StorageLive(_1); // scope 0 at $DIR/transmute.rs:+0:38: +3:2
StorageLive(_2); // scope 0 at $DIR/transmute.rs:+1:9: +1:10 StorageLive(_2); // scope 0 at $DIR/transmute.rs:+1:9: +1:10
StorageLive(_3); // scope 0 at $DIR/transmute.rs:+1:34: +1:52 StorageLive(_3); // scope 0 at $DIR/transmute.rs:+1:34: +1:52
_3 = const 1_usize as &mut Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:34: +1:52 - _3 = const 1_usize as &mut Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:34: +1:52
+ _3 = const {0x1 as &mut Never}; // scope 2 at $DIR/transmute.rs:+1:34: +1:52
+ // mir::Constant
+ // + span: no-location
+ // + literal: Const { ty: &mut Never, val: Value(Scalar(0x0000000000000001)) }
_2 = &mut (*_3); // scope 0 at $DIR/transmute.rs:+1:34: +1:52 _2 = &mut (*_3); // scope 0 at $DIR/transmute.rs:+1:34: +1:52
StorageDead(_3); // scope 0 at $DIR/transmute.rs:+1:54: +1:55 StorageDead(_3); // scope 0 at $DIR/transmute.rs:+1:54: +1:55
StorageLive(_4); // scope 1 at $DIR/transmute.rs:+2:5: +2:16 StorageLive(_4); // scope 1 at $DIR/transmute.rs:+2:5: +2:16

View file

@ -15,7 +15,11 @@
bb0: { bb0: {
StorageLive(_1); // scope 0 at $DIR/transmute.rs:+0:38: +3:2 StorageLive(_1); // scope 0 at $DIR/transmute.rs:+0:38: +3:2
StorageLive(_2); // scope 0 at $DIR/transmute.rs:+1:9: +1:10 StorageLive(_2); // scope 0 at $DIR/transmute.rs:+1:9: +1:10
_2 = const 1_usize as &Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:30: +1:48 - _2 = const 1_usize as &Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:30: +1:48
+ _2 = const {0x1 as &Never}; // scope 2 at $DIR/transmute.rs:+1:30: +1:48
+ // mir::Constant
+ // + span: no-location
+ // + literal: Const { ty: &Never, val: Value(Scalar(0x0000000000000001)) }
StorageLive(_3); // scope 1 at $DIR/transmute.rs:+2:5: +2:16 StorageLive(_3); // scope 1 at $DIR/transmute.rs:+2:5: +2:16
unreachable; // scope 1 at $DIR/transmute.rs:+2:11: +2:13 unreachable; // scope 1 at $DIR/transmute.rs:+2:11: +2:13
} }