about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-08 04:10:14 +0000
committerbors <bors@rust-lang.org>2023-09-08 04:10:14 +0000
commit3d249706aa8b0167dd49efa1b3ce7cc0e9cbba08 (patch)
treec2f7d903b055b7321cfb82598195c57cdce17406 /compiler
parent69ec43001afd14bac506c519b47f2a17595086e7 (diff)
parent73d8dcb803aad67df31abe99f573a2320282bc60 (diff)
downloadrust-3d249706aa8b0167dd49efa1b3ce7cc0e9cbba08.tar.gz
rust-3d249706aa8b0167dd49efa1b3ce7cc0e9cbba08.zip
Auto merge of #115608 - RalfJung:fn-arg-validity, r=oli-obk
miri: catch function calls where the argument is caller-invalid / the return value callee-invalid

When doing a type-changing copy, we must validate the data both at the old and new type.

Fixes https://github.com/rust-lang/miri/issues/3017
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_const_eval/src/interpret/place.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs
index d8ad82d3da0..90f2b470179 100644
--- a/compiler/rustc_const_eval/src/interpret/place.rs
+++ b/compiler/rustc_const_eval/src/interpret/place.rs
@@ -796,6 +796,13 @@ where
         dest: &impl Writeable<'tcx, M::Provenance>,
         allow_transmute: bool,
     ) -> InterpResult<'tcx> {
+        // Generally for transmutation, data must be valid both at the old and new type.
+        // But if the types are the same, the 2nd validation below suffices.
+        if src.layout().ty != dest.layout().ty && M::enforce_validity(self, src.layout()) {
+            self.validate_operand(&src.to_op(self)?)?;
+        }
+
+        // Do the actual copy.
         self.copy_op_no_validate(src, dest, allow_transmute)?;
 
         if M::enforce_validity(self, dest.layout()) {