fast_math: detect non-finite results
This commit is contained in:
parent
4658d3816c
commit
dae48ea4bb
@ -268,7 +268,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
|
|||||||
),
|
),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
this.binop_ignore_overflow(op, &a, &b, dest)?;
|
let res = this.wrapping_binary_op(op, &a, &b)?;
|
||||||
|
if !float_finite(&res)? {
|
||||||
|
throw_ub_format!("`{intrinsic_name}` intrinsic produced non-finite value as result");
|
||||||
|
}
|
||||||
|
this.write_immediate(*res, dest)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
7
src/tools/miri/tests/fail/intrinsics/fast_math_result.rs
Normal file
7
src/tools/miri/tests/fail/intrinsics/fast_math_result.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#![feature(core_intrinsics)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
unsafe {
|
||||||
|
let _x: f32 = core::intrinsics::fdiv_fast(1.0, 0.0); //~ ERROR: `fdiv_fast` intrinsic produced non-finite value as result
|
||||||
|
}
|
||||||
|
}
|
15
src/tools/miri/tests/fail/intrinsics/fast_math_result.stderr
Normal file
15
src/tools/miri/tests/fail/intrinsics/fast_math_result.stderr
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
error: Undefined Behavior: `fdiv_fast` intrinsic produced non-finite value as result
|
||||||
|
--> $DIR/fast_math_result.rs:LL:CC
|
||||||
|
|
|
||||||
|
LL | let _x: f32 = core::intrinsics::fdiv_fast(1.0, 0.0);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `fdiv_fast` intrinsic produced non-finite value as result
|
||||||
|
|
|
||||||
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
||||||
|
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
||||||
|
= note: BACKTRACE:
|
||||||
|
= note: inside `main` at $DIR/fast_math_result.rs:LL:CC
|
||||||
|
|
||||||
|
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user