3 ms·
I wonder if it's possible to sneak UB into normal "safe" Rust code, by leveraging LLVM optimizations?
by iainmerrick 9y ago
I wonder if it's possible to sneak UB into normal "safe" Rust code, by leveraging LLVM optimizations?
- bbatha 9y agoIts totally possible, but its considered a compiler bug if it does happen. In the same way that its possible to segfault java if there's a bug in the jit. There's an on going project to verify the semantics of the Rust language and its safe abstractions[0] which should make it easier to choose which optimizations are legal. 0: http://plv.mpi-sws.org/rustbelt/ http://plv.mpi-sws.org/rustbelt/
- Manishearth 9y agoAssuming no compiler bugs, no. UB isn't something "caused" by optimizations, it's something that exists in the code before optimizations, optimizations can just trigger nasal demons. So you shouldn't be able to write UB in safe Rust assuming no compiler bugs. (And assuming that any unsafe libraries being leveraged are bug free)
- kibwen 9y agoYes, though those are considered bugs in the Rust compiler. As the goal of Rust is to forbid memory unsafety in safe code, the Rust developers accept the burden of working around LLVM-related UB (which sometimes is quite difficult, see e.g. this longstanding UB bug related to how LLVM translates certain numeric casts: https://github.com/rust-lang/rust/issues/10184 https://github.com/rust-lang/rust/issues/10184 ).
- deleted 9y ago[deleted]