-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Miri: handling of SNaN inputs in f*::pow
operations
#142514
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: handling of SNaN inputs in f*::pow
operations
#142514
Conversation
The Miri subtree was changed cc @rust-lang/miri |
src/tools/miri/src/intrinsics/mod.rs
Outdated
fn random_nan<S: Semantics>(rng: &mut StdRng) -> IeeeFloat<S> { | ||
if rng.random() { | ||
IeeeFloat::<S>::snan(Some(rng.random())) | ||
} else { | ||
IeeeFloat::<S>::qnan(Some(rng.random())) | ||
} | ||
} |
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.
We already have extensive logic for random NaNs (generate_nan
), please use that instead.
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 yeah 🤦
src/tools/miri/src/intrinsics/mod.rs
Outdated
("powf32" | "powf64", [base, exp]) if *base == one => { | ||
let rng = ecx.machine.rng.get_mut(); | ||
// Handle both the musl and glibc cases non-deterministically. | ||
if !exp.is_signaling() || rng.random() { one } else { random_nan(rng) } |
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.
This is too compact to be readable. Also, this needs to honor the (new) float_nondet
flag.
let return_nan = exp.is_signaling() && ecx.machine.float_nondet && rng.random();
if return_nan { ...
src/tools/miri/tests/pass/float.rs
Outdated
} | ||
|
||
// x^(SNaN) = (1 | NaN) | ||
test_snan_nondet!(f32::powf(SNAN_F32, 0.0)); |
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.
Please don't invent new logic, but use existing logic. We already have ensure_nondet
.
Sorry for the slow review, I was traveling. And due to an upcoming deadline I'll be quite busy for another 2 weeks, unfortunately. |
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
@bors2 try jobs=x86_64-gnu-aux |
Miri: handling of SNaN inputs in `f*::pow` operations <!-- homu-ignore:start --> <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> --> <!-- homu-ignore:end --> fixes [miri/#4286](rust-lang/miri#4286) and related to #138062 and [miri/#4208](rust-lang/miri#4208 (comment)). For the following cases of the powf or powi operations, Miri returns either `1.0` or an arbitrary `NaN`: - `powf(SNaN, 0.0)` - `powf(1.0, SNaN)` - `powi(SNaN, 0)` Also added a macro in `miri/tests/pass/float.rs` which conveniently checks if both are indeed returned from such an operation. Made these changes in the rust repo so I could test against stdlib, since these were impacted some time ago and were fixed in #138062. Tested with: ```fish env MIRIFLAGS=-Zmiri-many-seeds ./x miri --no-fail-fast std core coretests -- f32 f64 ``` This was successful. This does take a while, so I recommend using `--no-doc` and separate use of `f32` or `f64` The pr is somewhat split up into 3 main commits, which implement the cases described above. The first commit also introduces the macro, and the last commit is just a global refactor of some things. r? `@RalfJung` try-job: x86_64-gnu-aux
No worries! I had exams, so I couldn't respond to the review if it had been done sooner. |
550a13b
to
f49980c
Compare
@rustbot ready |
6718b82
to
06dd8bc
Compare
Thanks! I added a commit with some more tests. Should be good to go now :) |
06dd8bc
to
e059457
Compare
plus various minor tweaks
e059457
to
67ab61e
Compare
@bors r+ |
Rollup of 14 pull requests Successful merges: - #142429 (`tests/ui`: A New Order [13/N]) - #142514 (Miri: handling of SNaN inputs in `f*::pow` operations) - #143066 (Use let chains in the new solver) - #143090 (Workaround for memory unsafety in third party DLLs) - #143118 (`tests/ui`: A New Order [15/N]) - #143159 (Do not freshen `ReError`) - #143168 (`tests/ui`: A New Order [16/N]) - #143176 (fix typos and improve clarity in documentation) - #143187 (Add my work email to mailmap) - #143190 (Use the `new` method for `BasicBlockData` and `Statement`) - #143195 (`tests/ui`: A New Order [17/N]) - #143196 (Port #[link_section] to the new attribute parsing infrastructure) - #143199 (Re-disable `tests/run-make/short-ice` on Windows MSVC again) - #143219 (Show auto trait and blanket impls for `!`) r? `@ghost` `@rustbot` modify labels: rollup
Oh wow, thanks! |
Rollup merge of #142514 - LorrensP-2158466:miri-float-nondet-pow, r=RalfJung Miri: handling of SNaN inputs in `f*::pow` operations fixes [miri/#4286](rust-lang/miri#4286) and related to #138062 and [miri/#4208](rust-lang/miri#4208 (comment)). For the following cases of the powf or powi operations, Miri returns either `1.0` or an arbitrary `NaN`: - `powf(SNaN, 0.0)` - `powf(1.0, SNaN)` - `powi(SNaN, 0)` Also added a macro in `miri/tests/pass/float.rs` which conveniently checks if both are indeed returned from such an operation. Made these changes in the rust repo so I could test against stdlib, since these were impacted some time ago and were fixed in #138062. Tested with: ```fish env MIRIFLAGS=-Zmiri-many-seeds ./x miri --no-fail-fast std core coretests -- f32 f64 ``` This was successful. This does take a while, so I recommend using `--no-doc` and separate use of `f32` or `f64` The pr is somewhat split up into 3 main commits, which implement the cases described above. The first commit also introduces the macro, and the last commit is just a global refactor of some things. r? `@RalfJung`
fixes miri/#4286 and related to #138062 and miri/#4208.
For the following cases of the powf or powi operations, Miri returns either
1.0
or an arbitraryNaN
:powf(SNaN, 0.0)
powf(1.0, SNaN)
powi(SNaN, 0)
Also added a macro in
miri/tests/pass/float.rs
which conveniently checks if both are indeed returned from such an operation.Made these changes in the rust repo so I could test against stdlib, since these were impacted some time ago and were fixed in #138062. Tested with:
This was successful. This does take a while, so I recommend using
--no-doc
and separate use off32
orf64
The pr is somewhat split up into 3 main commits, which implement the cases described above. The first commit also introduces the macro, and the last commit is just a global refactor of some things.
r? @RalfJung