r/programming • u/isJuhn • 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-2
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.
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