r/programming • • Sep 03 '20

Almost 30 year old optimization bug in MSVC causing incorrect code (In specific circumstances) found

https://developercommunity.visualstudio.com/content/problem/1096974/msvc-global-optimization-of-program-results-in-inc.html?childToView=1172202#comment-1172202
114 Upvotes

19 comments sorted by

20

u/ChildishJack Sep 03 '20

Am I missing something, or does the explanation make it seem fairly easy to run into this bug?

Edit: Seems like an O flag and link time code generation must be enabled and you can’t print the variable

31

u/[deleted] Sep 03 '20

It's fairly shocking that this isn't more widely manifested though. There are probably thousands of binaries generating bad results in subtle ways around this bug, but debugging it would be extremely tricky.

I sort of wonder who tracked this down. Would like to buy a beer for that person.

16

u/codygman Sep 03 '20

Exactly. Which is why I don't buy arguments along the lines of "we know it's correct because we tested a lot".

What code paths? Why not the others?

There is a reason people are trying to make formal methods and property based testing more ergonomic and approachable.

13

u/suwu_uwu Sep 04 '20

sure, but proving a program is correct devolves into godelian madness. is the compiler you used to compile the test program correct? is the compiler used to compile the compiler correct? is the instruction set correct? is the silicon correct?

4

u/that_jojo Sep 04 '20

I also feel like not enough is said about the fact that to verify something perfectly, you have to have a perfectly correct and comprehensive specification.

How do you verify the spec itself, and who gets to decide what 'comprehensive' means?

1

u/albgr03 Sep 04 '20

Well, Xavier Leroy did it with compcert, and apparently it paid off.

1

u/codygman Sep 04 '20

but proving a program is correct devolves into godelian madness

I don't think this always happens, though it seems to be the perception.

Also, it doesn't have to turn into that. I think lack of careful experimentation in industry helps make it seem like lightweight verification is a misnomer.

At the least, I think industry generally devalues correctness too much by the metric of what's better in the long, medium, and sometimes short term.

Part of it is because "just having it together" always feels faster and we don't have good ways of actually reasonably proving "we made the deliberate decision to have less correctness here, but we shipped 3 months in advance and are within error tolerance".

Further, there is no looking back and saying "last year we shipped 3 months in advance but the technical debt incurred wrecked our targets there first 3 quarters of the year... Was it worth it?".

6

u/Alexander_Selkirk Sep 04 '20

The timsort bug is a good example too.

Or the bug with parsing strings to decimal floating point values which could result in an endless loop when given a specific input with a denormal IEE754 float .... halting webservers written in PHP.

1

u/flatfinger Sep 07 '20

How about a bug in Turbo C 2.00 printf which would treat exact powers of ten as the threshold for deciding how many digits to print to the left of the decimal point, with such determination being made before rounding, so outputting 99.9996 with a %1,3f format specifier would yield 00.000?

1

u/nakilon Sep 05 '20 edited Sep 05 '20

I sort of wonder who tracked this down.

As a Software Engineer in Test with many years of experience I can tell you that if you don't want to lose a job you should not track down bugs. Would be even better if you didn't find it. But if you found, don't insist on fixing, try to call it a feature. If it's gonna be fixed it should be fixed in a way of replacing the whole component putting months of work in it and no one should look at the existing source code. If they look, they should not look up the git history. And if everything failed and someone tracked down the bug line and the author you are fucked and became closer to get fired for finding that original issue.

I mean unfortunately

Would like to buy a beer for that person.

is not how things actually work in software industry.

1

u/[deleted] Sep 05 '20

Why? I buy beer for my testers all the time. They make software better. I want to shop better software. Full stop.

If that’s not how it works for you, go elsewhere.

1

u/nakilon Sep 05 '20

Your job sounds like an imaginary place from fiction books. I have to go elsewhere more frequently than bunnies are making new bunnies. At the last job it wasn't just "wrong to find bugs" but "wrong to work at all" and they didn't even give me a computer, lol. Real goal of having QA departments and people hired for such work is never really about finding issues their causes or fixing them but just increasing the budget flow.

0

u/[deleted] Sep 04 '20

[deleted]

11

u/[deleted] Sep 04 '20

Exactly the type of guy who would. Amazing!

7

u/TheOsuConspiracy Sep 04 '20

People who can do low level programming are on another level.

28

u/[deleted] Sep 04 '20

They're on a lower level.

3

u/Theemuts Sep 04 '20

Just a bit

1

u/funny_falcon Sep 04 '20

Where "lower" means "more fundamental".

-2

u/[deleted] Sep 04 '20

Not defending this and there needs to be a lot more testing but having ritten a compiler from 0 in colllege and done associated work in a top-10 compiler firm, I can tell you they are very complex beasts and most compilers are buggy by default

0

u/flatfinger Sep 07 '20

C was designed to allow simple compilers to produce decent machine code when fed source code that was designed around the strengths of the target machine. It was never really designed to allow simple compilers to turn portable programs into efficient machine code, and compilers for that purpose end up being more more complicated than would be needed to effectively accomplish the former job.