Hacker News new | ask | show | jobs
by Agingcoder 1251 days ago
I find several every year. Most people simply don't see compiler bugs because they don't test (and most of the time don't need to) their compilers extensively enough (by testing I mean they must build, run the generated binaries, and compare the output ).
1 comments

That sounds very weird, unless you are working

1) With with an esoteric environment that has relatively few users.

2) Have specific objectives that require a lot of edge case testing or ridiculously thorough fuzzing of the binary.

3) Go out looking for them by crafting nifty things that aren't much used.

Otherwise it would imply large companies (Google-scale) experience thousands of compiler bugs per year...

They most likely do (just look at the gcc bugzilla).

I find them because of a combination of : - a very large codebase - compiling with optimizations (O3) and targeting recent archs - yearly compiler upgrades - an extremely extensive testsuite

I have found all kinds of bugs (frontend, middle, backend) - the codegen ones tend to be very nasty to diagnose.

> Otherwise it would imply large companies (Google-scale) experience thousands of compiler bugs per year...

This seems likely to be true, from my experience.

Fortunately, most compiler bugs I run into (mostly with gcc and llvm) are not code generation bugs (which can eat months of debugging), but just segfaults / rejecting correct code / other broken stuff.

I also suspect most programmers spend most of their time staying more or less on the “straight and narrow”. There’s lots of obscure features in most languages (especially in old languages like C++) that not many programmers use.

These features are much more likely to have buggy edge cases in the compiler. And only a small select group of programmers will run into those bugs over and over again.

Eg complex template metaprogramming - which had known broken corner cases in all C++ compilers up until a decade or so ago.

If you don't hit compiler bugs, it's mostly because you're not updating your compiler.

Large companies with compiler teams want to use them, so they do update their compiler, so they will find bugs in it.

Btw, what do you think this prints with clang? (Whether the answer is a compiler bug is debatable…)

   printf("%#x\n", 1 << 32);
Assuming int is 32 bits wide, `1 << 32` invokes UB.
Indeed it does.

(Spoiler: it prints uninitialized stack memory. A bit closer to demons flying out your nose than you'd expect!)

Fun. Basically, it decides that (due to UB) it can simply not materialize the argument and carry on.

On Darwin/x86_64, this actually means that it prints out bits from an "uninitialized" register, specifically %rsi in this case, since that's where the second argument should be (even for variadic functions).

Certainly a jarring failure mode! However, if updating your compiler causes you to run into this, you already have a bug in your code (one that clang -- arguably not forcefully enough -- already warns you of).

This is exactly when I find most of my compiler bugs : every time we upgrade.