mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 06:35:27 +00:00
Fix ICE with ReadPointerAsBytes
validation error
This commit is contained in:
parent
5e91c4ecc0
commit
def0e9b8a4
@ -515,7 +515,11 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
||||
Ok(true)
|
||||
}
|
||||
ty::Float(_) | ty::Int(_) | ty::Uint(_) => {
|
||||
let value = self.ecx.read_scalar(value)?;
|
||||
let value = try_validation!(
|
||||
self.ecx.read_scalar(value),
|
||||
self.path,
|
||||
err_unsup!(ReadPointerAsBytes) => { "read of part of a pointer" },
|
||||
);
|
||||
// NOTE: Keep this in sync with the array optimization for int/float
|
||||
// types below!
|
||||
if self.ctfe_mode.is_some() {
|
||||
|
29
src/test/ui/issues/issue-79690.rs
Normal file
29
src/test/ui/issues/issue-79690.rs
Normal file
@ -0,0 +1,29 @@
|
||||
union Transmute<T: Copy, U: Copy> {
|
||||
t: T,
|
||||
u: U,
|
||||
}
|
||||
trait Bar {
|
||||
fn bar(&self) -> u32;
|
||||
}
|
||||
struct Foo {
|
||||
foo: u32,
|
||||
bar: bool,
|
||||
}
|
||||
impl Bar for Foo {
|
||||
fn bar(&self) -> u32 {
|
||||
self.foo
|
||||
}
|
||||
}
|
||||
#[derive(Copy, Clone)]
|
||||
struct Fat<'a>(&'a Foo, &'static VTable);
|
||||
struct VTable {
|
||||
size: Foo,
|
||||
}
|
||||
const FOO: &dyn Bar = &Foo {
|
||||
foo: 128,
|
||||
bar: false,
|
||||
};
|
||||
const G: Fat = unsafe { Transmute { t: FOO }.u };
|
||||
//~^ ERROR it is undefined behavior to use this value
|
||||
|
||||
fn main() {}
|
11
src/test/ui/issues/issue-79690.stderr
Normal file
11
src/test/ui/issues/issue-79690.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/issue-79690.rs:26:1
|
||||
|
|
||||
LL | const G: Fat = unsafe { Transmute { t: FOO }.u };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered read of part of a pointer at .1.<deref>.size.foo
|
||||
|
|
||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
Loading…
Reference in New Issue
Block a user