Skip to content
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

Merged
merged 3 commits into from
Mar 29, 2020

Conversation

RalfJung
Copy link
Member

No description provided.

@rust-highfive
Copy link
Collaborator

r? @varkor

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 28, 2020
@RalfJung RalfJung changed the title use more specialized Scalar::from_ constructors where appropriate Miri: use more specialized Scalar::from_ constructors where appropriate Mar 28, 2020
@@ -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)?;
Copy link
Member Author

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...)

Copy link
Member Author

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...

@RalfJung
Copy link
Member Author

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned varkor Mar 28, 2020
@eddyb
Copy link
Member

eddyb commented Mar 28, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Mar 28, 2020

📌 Commit bd9e046 has been approved by eddyb

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 28, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 29, 2020
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
@bors bors merged commit acc1dc2 into rust-lang:master Mar 29, 2020
@RalfJung RalfJung deleted the scalar-from branch March 29, 2020 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants