Remix.run Logo
▲ masklinn 2 hours ago

Most UBs are runtime conditions, and inserting runtime checks would defeat the point of optimizing for them not possibly happening.

For the static ones there are often warnings you can set, but you’ll have to go through the list. Or possibly external checkers (e.g. clang-tidy has one for infinite loops but not sure it’s 1:1 with the optimiser on complex cases)

▲vbezhenar an hour ago | parent [-]

It's not about inserting checks. It's about removing code that I wrote from the binary. That should not happen silently.

▲flohofwoe 18 minutes ago | parent [-]

You can get that behaviour already today by simply not enabling optimizations.

The resulting performance difference is basically the price to pay for such a 'strict' compiler which translates the input source code straight into machine code instructions without attempting to simplify the output code via inlining, constant folding and dead code removal.

▲vbezhenar 8 minutes ago | parent [-]

-O0 program is useless and should be written with any other language. The whole point of C is to use compiler with optimizations. I'm not against optimizations. I'm against optimizations that perform things unexpected by the programmer. Dead code removal is unexpected by the programmer, because programmer does not write dead code.