4 ms·
Works in practice resulted in the compilers adding security bugs - literally this article is about overflow checks that worked perfectly fine until the mid-2000
by olliej 8y ago
Works in practice resulted in the compilers adding security bugs - literally this article is about overflow checks that worked perfectly fine until the mid-2000s when compiler engineers realized they could abuse UB of overflow for “performance” and then a mountain of previously safe code became insecure.
- jcranmer 8y agoSpeaking as someone who works on compilers: Aliasing queries in the compiler basically work on a tiered system. There's a simple aliasing pass that first checks for really obvious alias information (such as, it's the same pointer, it's a bitcast of the pointer, it's a simple arithmetic expression of the same pointer), possibly some more advanced Andersen's-style alias passes, and only finally is there a last-ditch strict-aliasing based pass. If you take the address of a float and cast that to an integer pointer to get at the bits of the float (and don't let either pointer escape the function), it will work, even with "abusive" compilers that have aggressive optimization turned on, even if you modify the lvalue in the intervening code. It's literally more work to make the compiler not realize that the two pointers alias, and there's no benefit to pessimizing a trivial query, so I would be shocked if any compiler actually miscompiled that code.
- olliej 8y agoIt “working” isn’t the problem, the problem is when the compiler makes use of the “this is UB” to make formerly correct code incorrect. The definition of UB would allow a type punned union on the stack for instance to be treated as logically a struct - eg changes to the float value would not impact the integer value. While I agree that would not happen in practice today there is no reason it has to continue to work. The fact that compilers already make sane decisions regarding some UB - evaluation order of parameters used to be unspecified and gcc at least would change evaluation order depending of optimisation level, but all compilers have realized that just insane and so left to right evaluation. Similarly bzero will initialise padding bytes in a struct even though that is technically UB, so could technically be skipped. Sorry for run on horror sentences I’m typing on my phone :)