3 ms·
>-O2 to -O3 in gcc This sounds more like undefined behavior in your codebase than a compiler error. I don't know Rust but I'm pretty sure the whole selling poi
by dfhjgkljhf44 6y ago
>-O2 to -O3 in gcc
This sounds more like undefined behavior in your codebase than a compiler error. I don't know Rust but I'm pretty sure the whole selling point is that you won't run into problems like this.
- tsimionescu 6y agoThere are active open bugs today in GCC and clang for x86 where optimizations can break standards-correct code [0] (writing to a union through a pointer to a currently inactive member, which std::variant does internally). For more obscure platforms and older releases, there are bound to be numerous bugs. In particular, volatile handling is notoriously shoddy on many platforms. As an aside, the clang bug would also affect Rust if they used that type of optimization (assuming strict aliasing rules). [0] https://lists.isocpp.org/std-discussion/2020/10/0882.php https://lists.isocpp.org/std-discussion/2020/10/0882.php
- ordu 6y ago> As an aside, the clang bug would also affect Rust if they used that type of optimization (assuming strict aliasing rules). No, this bug cannot affect rust, because rust wouldn't allow to pass into a function three mutable references pointing to the same object. It wouldn't even allow two, nor one mutable and one immutable. Either it pass one mutable reference, or any number of immutable.
- steveklabnik 6y agoThis one (probably) wouldn’t, but there have been codegen bugs in Rust, some that have blocked people from upgrading before they can be fixed. It doesn’t happen often, but it does happen.
- tsimionescu 6y agoNot sure if that bug explicitly, but the fact that clang in noalias mode assumes that two pointers to different variants of the same union are not aliased (if it can't see from the immediate context that they are pointers to the same union variable) can very much affect Rust - if you call one function with a &mut to one field, than another function with a &mut to another field, and the optimizer inlines both functions in a broader context and loses the union information, you may well see reordering issues even in pure safe Rust. Anyway, Rust has found plenty of noalias bugs in clang, which is why it still doesn't compile with noalias optimizations turned on.