News for hackers. Stuff that matters.
Re:Clang-11.0.0 Miscompiled SQLite by alkonaut on Thursday June 04, 2020 @01:57AM (#23413065)
I have absolutely no problem finding out that we have a dozen new bugs in production for our 15 year old codebase, because we upgraded our compiler and it revealed places we used undefined or unspecified behavior.

I’d much rather have that than a compiler that evolves slower because its developers worry about existing non-conforming code.

I can always use the old version of the compiler if I don’t want it to break.

Re:Clang-11.0.0 Miscompiled SQLite by saagarjha on Thursday June 04, 2020 @02:01AM (#23413092)
You might if the compiler yelled at you for it before you shipped, but it’s just as likely to compile your code into something you didn’t really foresee…
Re:Clang-11.0.0 Miscompiled SQLite by Quekid5 on Thursday June 04, 2020 @02:41AM (#23413338)
How do much do you expect your compiler to yell? Undefined Behavior can result from extremely trivial things like x+1, where x is signed. Obviously, you don't want the compiler yelling at you for almost every single for loop or simple signed addition in your program.

There also seems to be this weird misapprehension (probably not shared by you) that this is the compiler being "out of to get you" for UB. That's not what happens... the compiler ASSUMES that no UB can happen and optimizes accordingly. This can certainly have surprising results, but doing anything else would leave a lot of performance on the floor. What has happened over the last decade is that compilers have become better and better at optimizing leading to more and more surprising results.

To anyone (again, not you) ITT complaining that their program 'used to work fine': It just happened to work, but it's been buggy from the get-go. If that's a problem for your ego, then you need to adjust your ego.

Re:Clang-11.0.0 Miscompiled SQLite by gwd on Thursday June 04, 2020 @04:48AM (#23414222)
> There also seems to be this weird misapprehension (probably not shared by you) that this is the compiler being "out of to get you" for UB.

Of course nobody actually thinks that the compiler is "out to get you". But if you do any work in a security context, that is the attitude you have to take: "If the compiler was lawful evil and trying to put security vulnerabilities into my code, what excuse could it use from the spec to justify doing so?" That's the only way to make sure that you won't get bitten by "well-intentioned" optimizations.

> To anyone (again, not you) ITT complaining that their program 'used to work fine': It just happened to work, but it's been buggy from the get-go. If that's a problem for your ego, then you need to adjust your ego.

This would be valid if what people were complaining about was random cowboy behavior. What people are complaining about is the fact that it is nearly impossible to write code without UB. The fact that UB can result from "trivial things like x+1 where x is signed" is exactly the problem.

Re:Clang-11.0.0 Miscompiled SQLite by saagarjha on Thursday June 04, 2020 @03:13AM (#23413588)
I mostly agree with your points, but I still think compiler authors have dropped the ball by not putting as much effort as detecting cases where they have run optimizations based on undefined behavior as they should have. We’ve seen some of these be rolled back with flags for overflow or null checks (which I personally think is a bit too far in the other direction).
Re:Clang-11.0.0 Miscompiled SQLite by Orphis on Thursday June 04, 2020 @07:17AM (#23415122)
Alternatively, you can instrument the code with checks for UB using a sanitizer. It won't be the compiler screaming at you but your CI running all your tests with this instrumented version of your software.

Not perfect, but should work for most sane people running CI before merging changes.

Re:Clang-11.0.0 Miscompiled SQLite by saagarjha on Thursday June 04, 2020 @02:21PM (#23419955)
Sanitizers don't catch all instances of undefined behavior, and they sure won't find anything that doesn't run…
Re:Clang-11.0.0 Miscompiled SQLite by klodolph on Thursday June 04, 2020 @01:59AM (#23413079)
The compiler doesn’t do a good job of revealing undefined behavior, it usually just makes your program break in mysterious ways.
Re:Clang-11.0.0 Miscompiled SQLite by alkonaut on Thursday June 04, 2020 @02:05AM (#23413119)
A better example is perhaps behavior that shouldn’t be relied upon: a standard library unordered collection (Set) where the implementation for 10 years preserves insertion order but says in the docs not to rely on it. Lots of programs have deliberately or not relied on it. Then suddenly it changes impl to one that doesn’t preserve insertion order for slightly better perf. You don’t want the std library developers to worry about existing code as long as the documentation always said “don’t rely on insertion order”.

Same with a list sort that is stable but never guaranteed it would be, then turns unstable much later. I was bitten by this one in .NET as were many others, and as a response the developers added hacks into the code to simulate the old behavior it detected the code was built against the older lib. That didn’t make the problem easier to find...

Re:Clang-11.0.0 Miscompiled SQLite by saagarjha on Thursday June 04, 2020 @02:09AM (#23413136)
> You don’t want the std library developers to worry about existing code as long as the documentation always said “don’t rely on insertion order”.

Sometime practicality wins out and the change is reverted when it breaks everything. It’s nice to come up with purist views, and in this case being able to point to documentation and say that the entire world needs to change is the morally high stance to take, but it’s not always what happens. (Some may say that this is what needs to happen to undefined behavior, but that one’s still up in the air. As it so happens I am on the “read the standard” camp…)