-
Notifications
You must be signed in to change notification settings - Fork 13k
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
fix Miri discriminant handling #63448
Conversation
I'd prefer to block this on #63450. |
90d692b
to
bc8cde5
Compare
I factored out the parts that are not blocked into a separate PR: #63658. |
bc8cde5
to
43b52ab
Compare
43b52ab
to
8c0f601
Compare
@eddyb noticed that doing all arithmetic using machine operations at discriminant type is also not correct, so now this does the variant idx computations on the host (checked so they do not overflow). |
I should also mention, tests will be added to Miri. My naive attempt at turning that into CTFE tests failed. @oli-obk is it possible to test this with current CTFE so that we have an in-tree test? |
Make it a |
I think that actually worked :D |
5530722
to
b21622c
Compare
// Then computing the absolute variant idx should not overflow any more. | ||
let variant_index = variants_start | ||
.checked_add(variant_index_relative) | ||
.expect("oveflow computing absolute variant idx"); |
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.
I wonder if this can overflow when it's the dataful variant. Still, ICE > silently doing the wrong thing.
.checked_add(variant_index_relative) | ||
.expect("oveflow computing absolute variant idx"); | ||
// Check if this is in the range that indicates an actual discriminant. | ||
if variants_start <= variant_index && variant_index <= variants_end { |
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.
Oh wait you can just compare variant_index_relative
against variants_end - variants_start
, and then you can move the addition inside the "niche" side of the if
.
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.
So the if should change to variant_index_relative <= variants_end - variants_start
you say?
What is the "niche side of the if"?
let variants_start = niche_variants.start().as_u32(); | ||
let variant_index_relative = variant_index.as_u32() | ||
.checked_sub(variants_start) | ||
.expect("overflow computing relative variant idx"); |
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.
I think this is fine because this is a "niche" variant.
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.
Sure but is there any reason not to ICE if this overflows anyway?
let discr_val = self.binary_op( | ||
mir::BinOp::Add, | ||
variant_index_relative_val, | ||
niche_start_val, | ||
)?; |
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.
I wonder how much this matters - you just need to truncate the result, I think? Either way, the symmetry with reading is probably fine.
r=me with #63448 (comment) fixed. |
📌 Commit 1de533a has been approved by |
⌛ Testing commit 1de533a with merge b480f068c8efc171da04e5e132310df0778ff4b1... |
💥 Test timed out |
cc @pietroalbini ^^ many jobs were stared very late and some still are waiting for the agent |
@bors retry |
fix Miri discriminant handling This can be reviewed commit-by-commit fairly well. The Miri side is at rust-lang/miri#903. Fixes rust-lang#62138 r? @eddyb @oli-obk
Rollup of 6 pull requests Successful merges: - #63448 (fix Miri discriminant handling) - #64592 (Point at original span when emitting unreachable lint) - #64601 (Fix backticks in documentation) - #64606 (Remove unnecessary `mut` in doc example) - #64611 (rustbuild: Don't package libstd twice) - #64613 (rustbuild: Copy crate doc files fewer times) Failed merges: r? @ghost
Rollup of 6 pull requests Successful merges: - #63448 (fix Miri discriminant handling) - #64592 (Point at original span when emitting unreachable lint) - #64601 (Fix backticks in documentation) - #64606 (Remove unnecessary `mut` in doc example) - #64611 (rustbuild: Don't package libstd twice) - #64613 (rustbuild: Copy crate doc files fewer times) Failed merges: r? @ghost
fix discriminant handling The Miri side of rust-lang/rust#63448
This can be reviewed commit-by-commit fairly well.
The Miri side is at rust-lang/miri#903.
Fixes #62138
r? @eddyb @oli-obk