Comments (8)
@RalfJung Non-deterministic NaNs can cause miscompilations. Here is an example that works on x86-64 (playground):
#[inline(never)]
fn print_vals(x: f64, i: usize, vals_i: u32) {
println!("x={x} i={i} vals[i]={vals_i}");
}
#[inline(never)]
pub fn evil(vals: &[u32; 300]) {
const INC: f64 = f64::MAX / 90.0;
let mut x: f64 = -1.0;
let mut i: usize = 0;
while x.is_sign_negative() {
print_vals(x, i, vals[i]);
// Use a big decrement to reach negative infinity quickly.
x -= INC;
// Convert infinity into a NaN (Inf - Inf = NaN)
x = x + x - x;
i += 2;
}
}
pub fn main() {
let mut vals: [u32; 300] = [0; 300];
for i in 0..300 { vals[i as usize] = i; }
evil(&vals);
}
On x86-64 (and 32-bit x86), NaNs produced at runtime will always have a negative sign whereas NaNs produced by LLVM at compile time always have a positive sign. This means LLVM thinks the loop will exit when x
becomes a NaN, but at runtime the loop will never exit.
from rust.
@rustbot label +A-floating-point +A-llvm +I-unsound +A-cross
from rust.
WG-prioritization assigning priority (Zulip discussion).
@rustbot label -I-prioritize +P-high
from rust.
This different sin
implementations problem was previously reported as #109118
from rust.
Shouldn't an LLVM issue be filed for this? Ideally the results of transcendentals should be represented by a "fuzzy" range, making compile time float equality impossible in this case.
from rust.
llvm/llvm-project#89885 was filed on the llvm side
from rust.
Ah, fun. So LLVM assumes that sin
is deterministic. Yeah that's clearly incoherent.
Now I wonder if the non-determinism in NaNs (as specified in rust-lang/rfcs#3514) is subject to similar issues. If LLVM assumes float operations are deterministic then indeed it must not do any const-folding that differs from the effective runtime behavior.
from rust.
@beetrees thanks for constructing an example!
from rust.
Related Issues (20)
- ICE :coherence: impl was matchable against Binder but now it is not, otherwise hang
- tests/crashes/124436.rs is creating a `mir_dump` directory in the repo root, not the build directory HOT 1
- `-C target_cpu=cortex-a72` (and `-target-cpu=native` on Raspberry Pi) wrongly enables crypto features that are optional on Cortex-A72 HOT 3
- Replace uses of #[allow(static_mut_refs)] with SyncUnsafeCell HOT 6
- Generic compilation struggle HOT 7
- Generic Problem Compilation HOT 1
- the documentation for the Future trait specifies invariants that are not always true
- rust-lld failing for RISCV R32Ve HOT 1
- rustc 1.78.0 segfault on MacOS / M1 HOT 6
- println!("{}", 9.4 * 3.0) HOT 4
- ICE: `explicit deref of non-derefable type` HOT 4
- ICE: `explicit index of non-indexable type` HOT 3
- Different Behaviors When Using from and into with Implemented From<&mut T> HOT 2
- why use surrealdb use primitive model error display HOT 1
- Incorrect link for `BufWriter` on `std::fs::File` page HOT 2
- Rustc 1.78 Undefined Reference to getauxval HOT 4
- non-local-definitions lint fires for impl using private types HOT 17
- Incomplete template in the list of allow-by-default rustc lints HOT 1
- RPIT with 'static bound lifetime capture issue with generic parameter HOT 1
- ICE: `assertion failed: bpos.to_u32() >= mbc.pos.to_u32() + mbc.bytes as u32` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust.