News for hackers. Stuff that matters.
Re:GCC undefined behaviors are getting wild by fps_doug on Monday November 28, 2022 @04:53AM (#33771619)
But then again, UB doesn't mean the compiler author can't treat it as implementation-defined and do something reasonable.
Re:GCC undefined behaviors are getting wild by tuyiown on Monday November 28, 2022 @05:31AM (#33771892)
You're getting it backward. UB doesn't immediately stop compilation only due to implementation defined backward compatibility, just because you don't want to break compilation of existing programs each time the compiler converges to the C spec and identified an implementation of undefined behavior.

And since you want some cross-compiler compatibility, you also import's third parties implementation defined UB.

This is not some conceptual reasonable decision, the proper way would be to throw out compilation on each UB behavior. The reality is that the proper way would be too harsh on existing codebase, making people use a less strict compiler or not updating version, which are non-desirable effects for compilers writers.

Re:GCC undefined behaviors are getting wild by fps_doug on Monday November 28, 2022 @05:46AM (#33771987)
I can't really follow. What would be wrong with making -fwrapv the default? i.e. let the compiler assume signed integers are two's complement on according platforms (i.e. virtually everything in use today). Then stop assuming "a + 1 < a" cannot be true for signed ints. How would that make existing code worse, or break it? It's basically what you already get with -O0 afaict, so any such program would be broken with optimizations turned off.
Re:GCC undefined behaviors are getting wild by tuyiown on Monday November 28, 2022 @07:03AM (#33772562)
I think I misunderstood your comment, sorry, but I have difficulties in understanding how it's different that how things works already, then. You either have to rely that the compiler author did chose what you expect (not the case here), or check by yourself and hope it won't change.
Re:GCC undefined behaviors are getting wild by gpderetta on Monday November 28, 2022 @07:40AM (#33772865)
There is nothing wrong. Except that a subset of GCC users prefer -ftrapv and another subset wants no overhead, so the status quo remains.
Re:GCC undefined behaviors are getting wild by dzaima on Monday November 28, 2022 @05:11AM (#33771763)
And sanitizers that throw warnings on undefined behavior do indeed exist.