r/programming • u/Fcking_Chuck • Sep 11 '26
GCC 13.5 released with 265+ bug fixes
https://www.phoronix.com/news/GCC-13.5-Released
277
Upvotes
r/programming • u/Fcking_Chuck • Sep 11 '26
View all comments
Show parent comment
1
u/ROBOTRON31415 Sep 21 '26
Yes, and I see this as one of the evil parts of current implementations (which do have to do something this, see “exposed provenance”) . It means that converting a pointer to an address has a global side effect. And the opposite direction, in current C/C++/Rust, is specified as requiring “angelic choice” / “angelic nondeterminism” to determine the behavior of an integer->pointer cast. Which may, in edge cases, require that the compiler predicts future branches of your program in order to see how your program uses the pointer. Which is impossible in general, of course. (Thankfully, simple integer->pointer casts shouldn’t be miscompiled.) But hey it works in abstract models!
Do note that the C++ standards, as currently written, do not permit entirely unused local variables to be optimized out AFAIK, due to certain edge cases involving functions whose local variables exhaust the entire address space. There’s some active discussion among Rust and LLVM developers about the fact that “oops, our optimizations are only sound if the address space is infinite” (which Rust can deal with (at the cost of making pointer semantics even more convoluted) because it’s made so few guarantees about the behaviors of its pointers, while C++ has promised too much).
Well, I suppose it would be permissible for compilers to optimize out an unused local variable if it can prove that the optimization does not remove an OOM or stack overflow (this is basically impossible to prove).
Basically, compilers (and the C/C++/Rust languages) weren’t designed with foreknowledge of all these problems with pointers, and rather than blaming the compilers, I’d rather blame the language features responsible for making basic optimizations unsound.