Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Differing match results between opt levels when casting to #[repr(C)] enum
I've been doing some serialization work and recently encountered a really unexpected situation where depending on the compiler opt-level, a match statement can produce differing results. Does anyone have any insight on why this is? This almost seems like a compiler bug, since O0 and O1 shouldn't be following different logical branches with the same data, but it could easily be UB nose-demons manifesting due to the use of unsafe type casting.
To demonstrate, try the code below with opt-level=1 and opt-level=0. With no optimizations, the discriminant is read as none, however with opt-level 1 or higher, it's detected as some.
5 posts - 4 participants
🏷️ rust_feed