4 ms·
Warning when optimization passes take advantage of UB is a reasonable desire. The compilers are getting increasingly good at this, but I believe it would be far
by vnorilo 7y ago
Warning when optimization passes take advantage of UB is a reasonable desire. The compilers are getting increasingly good at this, but I believe it would be far too noisy to blanket enable all of that.
- mjevans 7y agoThe point is to push the info to the programmer so that the code can be re-written as only defined behavior. Yes this would eliminate the 'gains' of abusing UB, but it would actually fix the errors of abusing UB.
- vnorilo 7y agoI guess signed indvars would be a prime example. Compilers famously ignore overflow of signed integers when computing loop trip counts. Would it be better to only ever use unsigned integers for indvars and loop limits? Maybe. But that would reach deep into the types in stdlib for example. And then there's https://software.intel.com/en-us/forums/intel-c-compiler/topic/698664 https://software.intel.com/en-us/forums/intel-c-compiler/top... So, all in all, not simple. Not that that invalidates your point: I just wanted to add some nuance.
- marcan_42 7y agoThe problem is the compiler cannot prove UB actually happens. The point of these "use UB to optimize" approaches isn't to screw over simple programs with bugs. It's to better optimize larger, correct programs where higher levels of logic that the compiler is unaware of ensure UB never happens.