News for hackers. Stuff that matters.
Re:When you see a Heisenbug in C, change your compiler's opt... by cpncrunch on Saturday March 01, 2014 @06:21PM (#7326647)
Agreed. Many times I've seen a bug disappear when I've added printfs or turned on -g, but I've never, ever seen an optimization bug in a C/C++ compiler.

The only time I've seen optimization bugs is in the emscripten compiler, but I'm sure those will be ironed out eventually (and the current version seems pretty stable).

Re:When you see a Heisenbug in C, change your compiler's opt... by userbinator on Saturday March 01, 2014 @09:14PM (#7327361)
In nearly 2 decades I have seen only one compiler bug, in MSVC6, which was related to large switch statements.

The most successful way of finding what's causing these "heisenbugs" is to NOT change the binary, but just load it in the debugger as-is, make a guess at where it's failing, and set a few breakpoints/watchpoints. Either the compiler is not generating the code that you expect, or your expectations of the language were wrong, and both cases are fairly clear from looking at the generated code.

Re:When you see a Heisenbug in C, change your compiler's opt... by infogulch on Saturday March 01, 2014 @08:40PM (#7327244)
That has happened to me as well. There's a bug until I add a printf or enable debugging, or (paradoxically) go from -O0 to -O2. What's going on here? Is there some specific class of UB that I'm invoking to get this infuriating bug?
Re:When you see a Heisenbug in C, change your compiler's opt... by cpncrunch on Sunday March 02, 2014 @12:30AM (#7327848)
I think it's usually just accessing out of bounds memory / uninitialized read, and -g/-O just happens to change the memory layout enough to cause/prevent the crash.