Compiler bugs are a particularly insiduous form of computer bug.

A compiler is a computer program that translates a computer program written in one computer language (called the source language) into a program written in another computer language (called the output or the target language).

In the common case, an ordinary computer bug (e.g. division by zero) often manifests itself as a report that a particular error has occurred. Programming errors (e.g. using + instead of -) may merely produce the wrong answer.

In the case of a compiler bug, the result may be to translate the source program incorrectly, so that when you come to run the program you either get wrong answers or some error message which doesn't really relate to your original program.

As well as translating your program, some compilers also attempt to optimize it, so that it will run faster, or use less memory, or both. This optimization is often the most complicated part of a compiler, and hence is likely to have the most bugs.

Examples of compiler bugs:

  • One vendor offers 4 different levels of compiler optimization. In the section of the manual discussing optimization, it says "use the highest workable optimization level", and then goes on to provide an example where use of the highest level can cause a program to fail.

  • The language and compiler allowed declarations of the form "const real ApproxPi = 355/113;" If you used this within a subroutine everything worked perfectly. But if you used it in a global context then ApproxPi had the value 1.0 instead of the expected 3.141592...

  • In a batch-mode compiler, you could select whether or not you got a program listing. But if you switched off the listing to save disk space, then bad code was generated.