Re:Initialization in C++ is Seriously Bonkers
by zawerf on Sunday January 06, 2019 @03:25AM
(#18837275)
Do compilers really try to prove UB so they can use it as an excuse to silently murder kittens? That sounds so counterproductive. If it can prove UB, it should just pop an error and stop.
[ Parent
| on HN ]
Re:Initialization in C++ is Seriously Bonkers
by codeflo on Sunday January 06, 2019 @04:00AM
(#18837372)
What's actually happening is a bit more subtle: The compiler is allowed to assume that the programmer in fact made no mistake and there's a reason why the UB is never actually triggered at runtime. Reasoning backwards from that can open up large optimization opportunities elsewhere, like not loading a value from memory twice, or not actually checking a condition. A good article about this that was recently discussed on HN: https://news.ycombinator.com/item?id=18575383
Re:Initialization in C++ is Seriously Bonkers
by palunon on Sunday January 06, 2019 @05:34AM
(#18837656)
What they do is not try to prove UB, but use it as a precondition for the proof that their optimizations don't change the program behavior - ie. they can assume that anything resulting in UB won't happen.
Re:Initialization in C++ is Seriously Bonkers
by saagarjha on Sunday January 06, 2019 @05:07AM
(#18837559)
> Do compilers really try to prove UB so they can use it as an excuse to silently murder kittens?
Clang in particular is quite aggressive about this, and is prone to producing surprising results. GCC has started doing this too, but it is much more conservative,