diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-02-24 18:32:52 -0800 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-03-22 15:15:41 -0700 |
| commit | 64cce5fc7d2c1070adeaa719932b4bbccf27dd46 (patch) | |
| tree | 918975145ee82f7777d722aedea9cc75f218dcce /src/tools | |
| parent | a266f11990d9544ee408e213e1eec8cc9eb032b7 (diff) | |
| download | rust-64cce5fc7d2c1070adeaa719932b4bbccf27dd46.tar.gz rust-64cce5fc7d2c1070adeaa719932b4bbccf27dd46.zip | |
Add `CastKind::Transmute` to MIR
Updates `interpret`, `codegen_ssa`, and `codegen_cranelift` to consume the new cast instead of the intrinsic. Includes `CastTransmute` for custom MIR building, to be able to test the extra UB.
Diffstat (limited to 'src/tools')
4 files changed, 10 insertions, 5 deletions
diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index 24403e8b6f3..ff492a5104d 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -176,6 +176,9 @@ fn check_rvalue<'tcx>( // FIXME(dyn-star) unimplemented!() }, + Rvalue::Cast(CastKind::Transmute, _, _) => { + Err((span, "transmute can attempt to turn pointers into integers, so is unstable in const fn".into())) + }, // binops are fine on integers Rvalue::BinaryOp(_, box (lhs, rhs)) | Rvalue::CheckedBinaryOp(_, box (lhs, rhs)) => { check_operand(tcx, lhs, span, body)?; diff --git a/src/tools/miri/tests/fail/never_transmute_humans.rs b/src/tools/miri/tests/fail/never_transmute_humans.rs index de723433dc2..cba3cc0ccf1 100644 --- a/src/tools/miri/tests/fail/never_transmute_humans.rs +++ b/src/tools/miri/tests/fail/never_transmute_humans.rs @@ -7,6 +7,6 @@ struct Human; fn main() { let _x: ! = unsafe { - std::mem::transmute::<Human, !>(Human) //~ ERROR: transmuting to uninhabited + std::mem::transmute::<Human, !>(Human) //~ ERROR: entering unreachable code }; } diff --git a/src/tools/miri/tests/fail/never_transmute_humans.stderr b/src/tools/miri/tests/fail/never_transmute_humans.stderr index e8df4739f9b..a51ca7fe7e7 100644 --- a/src/tools/miri/tests/fail/never_transmute_humans.stderr +++ b/src/tools/miri/tests/fail/never_transmute_humans.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: transmuting to uninhabited type +error: Undefined Behavior: entering unreachable code --> $DIR/never_transmute_humans.rs:LL:CC | LL | std::mem::transmute::<Human, !>(Human) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ transmuting to uninhabited type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ entering unreachable code | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/src/tools/miri/tests/fail/never_transmute_void.rs b/src/tools/miri/tests/fail/never_transmute_void.rs index 19473e9ac21..ad67b444616 100644 --- a/src/tools/miri/tests/fail/never_transmute_void.rs +++ b/src/tools/miri/tests/fail/never_transmute_void.rs @@ -10,11 +10,13 @@ mod m { pub struct Void(VoidI); pub fn f(v: Void) -> ! { - match v.0 {} //~ ERROR: entering unreachable code + match v.0 {} + //~^ ERROR: entering unreachable code } } fn main() { let v = unsafe { std::mem::transmute::<(), m::Void>(()) }; - m::f(v); //~ NOTE: inside `main` + m::f(v); + //~^ NOTE: inside `main` } |
