-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Miri: use more specialized Scalar::from_ constructors where appropriate #70508
Conversation
r? @varkor (rust_highfive has picked a reviewer for you, use r? to override) |
@@ -220,7 +222,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |||
sym::discriminant_value => { | |||
let place = self.deref_operand(args[0])?; | |||
let discr_val = self.read_discriminant(place.into())?.0; | |||
self.write_scalar(Scalar::from_uint(discr_val, dest.layout.size), dest)?; | |||
self.write_scalar(Scalar::from_u64(u64::try_from(discr_val).unwrap()), dest)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eddyb this is where Miri would now ICE for too big discriminants. (And I am not entirely sure what happens for negative discriminants, TBH...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this, I think for signed 64bit discriminants we appropriately truncate and everything is okay. (I tried to find a way to share that code there with cast.rs
but found no good way.)
For negative discriminants with repr(i128)
this will ICE, but well, these just cannot be represented properly in a u64
...
r? @eddyb |
@bors r+ |
📌 Commit bd9e046 has been approved by |
Rollup of 5 pull requests Successful merges: - rust-lang#69937 (ASCII methods on OsStr) - rust-lang#70235 (Validate git setup before accessing functionality) - rust-lang#70503 (rename Scalar::{ptr_null -> null_ptr} and add "machine_" prefix like elsewhere) - rust-lang#70508 (Miri: use more specialized Scalar::from_ constructors where appropriate) - rust-lang#70510 (fix TryEnterCriticalSection return type) Failed merges: r? @ghost
No description provided.