3 ms·
Oh compilers are fun. Just recently I was reading through Rust's bug tracker, as one does, and learned that comparing function pointers is not deterministic. Co
by jiripospisil 6y ago
Oh compilers are fun. Just recently I was reading through Rust's bug tracker, as one does, and learned that comparing function pointers is not deterministic. Compiling this code [0] in the Debug mode yields different results than in the Release mode. You can read the whole discussion about whether it's a LLVM bug, a Rustc bug, an undefined behavior, an intended behavior, a pretty serious bug, or nothing to worry about over at [1].
[0] https://play.rust-lang.org/?version=stable&mode=release&edition=2015 https://play.rust-lang.org/?version=stable&mode=release&edit...
[1] https://github.com/rust-lang/rust/issues/54685 https://github.com/rust-lang/rust/issues/54685
- account42 6y ago> comparing function pointers is not deterministic The comparison is deterministic - the perhaps unexpected part is that two distinct but identical functions in the source code are folded into one in the binary.
- johncolanduoni 6y agoThat bug was actually a bit deeper; it merged the functions but would statically fold some comparisons to false while letting others persist to runtime (where they would evaluate to true) in the same build. You could do `x == y` twice and get different results, one of which was a lie.
- chc4 6y agoGod, that issue is a mess. Lots of people missing the forest (Rust and LLVM are breaking constant folding guarantees) for the trees (function pointer equality is weird).
- dathinab 6y agoIt should be noted that function pointer comparison is defined to not be deterministic between different compiler option sets, it's at least for now possible but mostly useless. Through there are bugs involved, too ;=) (Due to const folding comparisons vs. doing them at runtime there was/is non-determinism in the same build between different call sites ... )
- Asraelite 6y agoJust a heads up, you linked to the main Rust Playground page, not an actual gist.
- jiripospisil 6y agoDamn, you're right. I didn't notice because Playground remembers the last content you had in the editor... Anyway, the correct link is https://play.rust-lang.org/?gist=62d362e2bf72001bd3f3c4a3ed0c842c&version=stable&mode=release&edition=2015 https://play.rust-lang.org/?gist=62d362e2bf72001bd3f3c4a3ed0...