mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-17 05:25:37 +03:00
Reading values should not be looking at the variant
This commit is contained in:
@@ -1521,7 +1521,7 @@ pub fn try_read_by_ref(&self, mut val: Value, ty: Ty<'tcx>) -> EvalResult<'tcx,
|
||||
}
|
||||
|
||||
pub fn try_read_value(&self, ptr: Scalar, ptr_align: Align, ty: Ty<'tcx>) -> EvalResult<'tcx, Option<Value>> {
|
||||
let mut layout = self.layout_of(ty)?;
|
||||
let layout = self.layout_of(ty)?;
|
||||
self.memory.check_align(ptr, ptr_align)?;
|
||||
|
||||
if layout.size.bytes() == 0 {
|
||||
@@ -1530,19 +1530,6 @@ pub fn try_read_value(&self, ptr: Scalar, ptr_align: Align, ty: Ty<'tcx>) -> Eva
|
||||
|
||||
let ptr = ptr.to_ptr()?;
|
||||
|
||||
match layout.variants {
|
||||
layout::Variants::NicheFilling { .. } |
|
||||
layout::Variants::Tagged { .. } => {
|
||||
let variant_index = self.read_discriminant_as_variant_index(
|
||||
Place::from_ptr(ptr, ptr_align),
|
||||
layout,
|
||||
)?;
|
||||
layout = layout.for_variant(self, variant_index);
|
||||
trace!("variant layout: {:#?}", layout);
|
||||
},
|
||||
layout::Variants::Single { .. } => {},
|
||||
}
|
||||
|
||||
match layout.abi {
|
||||
layout::Abi::Scalar(..) => {
|
||||
let scalar = self.memory.read_scalar(ptr, ptr_align, layout.size)?;
|
||||
@@ -1558,7 +1545,7 @@ pub fn try_read_value(&self, ptr: Scalar, ptr_align: Align, ty: Ty<'tcx>) -> Eva
|
||||
let b_val = self.memory.read_scalar(b_ptr, ptr_align, b_size)?;
|
||||
Ok(Some(Value::ScalarPair(a_val, b_val)))
|
||||
}
|
||||
_ => Ok(None),
|
||||
_ => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ union Foo {
|
||||
|
||||
// A pointer is guaranteed non-null
|
||||
const BAD_ENUM: Enum = unsafe { Foo { a: &1 }.b};
|
||||
//~^ ERROR this constant cannot be used
|
||||
//~^ ERROR this constant likely exhibits undefined behavior
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
error: this constant cannot be used
|
||||
error[E0080]: this constant likely exhibits undefined behavior
|
||||
--> $DIR/ub-enum-ptr.rs:23:1
|
||||
|
|
||||
LL | const BAD_ENUM: Enum = unsafe { Foo { a: &1 }.b};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ a raw memory access tried to access part of a pointer value as raw bytes
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer at .TAG, but expected something in the range 0..=0
|
||||
|
|
||||
= note: #[deny(const_err)] on by default
|
||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler 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`.
|
||||
|
||||
Reference in New Issue
Block a user