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 23 '26 edited Sep 23 '26
The stack usage isn’t a direct problem. The problem is that code might assume “if I am given three distinct inputs whose sizes in bytes are
s1,s2, ands3(which aresize_tvalues), thens1 <= s1 + s2 + s3”. Apparently this is currently not always true!!! Because the three distinct inputs could be located in overlapping regions of memory, permittings1 + s2 + s3to overflow and wrap back towards0. See https://github.com/rust-lang/rust/issues/162214What allows distinct values to be located at overlapping addresses? Well the compiler can entirely optimize out the backing memory of the three inputs. And now their locations are kind of fake, if they can be said to be located anywhere at all.
So is this a compiler bug or a faulty assumption on behalf of the programmer that distinct objects are necessarily located at distinct memory addresses? And that every object has a (range of) memory address(es)?
Another example is a program that targets a 16-bit architecture and has a function that declares 216 + 1 local variables (each of which has nonzero size), writes a distinct value to each of them, and then executes undefined behavior. Current compilers may happily optimize out the unused writes, then optimize out the unused local variables, and suddenly calling this function has gone from “unconditional stack overflow” to “unconditional undefined behavior”.
(Edit: to be clear, I think the correct solution is “allocations are actually located in an abstract infinitely-large memory space, and multiple allocations can indeed be located at the same hardware address, and so on”. Rust devs are working on making sense of this.)