Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

If a compiler's work is essentially translating source code into machine level code, can there be any glitch in a compiler, i.e. a faulty "translation?"

The same goes for an interpreter: can it fail to output the required content sometimes?

I have not heard of any bugs in compilers/interpreters, but do they exist?

share|improve this question

closed as off-topic by Glenn Nelson, Dan Pichelman, MichaelT, Jim G., Eric Lippert Jul 9 '13 at 15:45

  • This question does not appear to be about software development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

6  
in development they will most definitely exist just look at the bugtracker on any open source compiler –  ratchet freak Jul 8 '13 at 14:36
7  
I have not heard of any bugs in compilers/interpreters, but do they exist? I found the mailing list for bugs in the gcc compiler: gcc.gnu.org/ml/gcc-bugs –  FrustratedWithFormsDesigner Jul 8 '13 at 15:07
46  
This isn't a really good question, it just asks something that is common sense. –  Glenn Nelson Jul 8 '13 at 15:10
12  
None of the comments or answers so far address the likelihood of encountering a compiler bug. Be sure to rule out errors in your own code first. –  Dan Pichelman Jul 8 '13 at 16:08
6  
Short answer: definitely. While IDEs and compilers are typically exercised within an inch of their lives before they ever see the outside world, there's always a corner case somewhere that a developer being a little too clever will find. –  KeithS Jul 8 '13 at 16:27

10 Answers 10

up vote 46 down vote accepted

Yes

You tend to find them more in languages that are actively being developed than in those that are relatively mature (and thus don't see a lot of change on a frequent basis). This is probably why most languages are released at various 'stages' of stability. A nightly build is far less likely to be stable than a release candidate, which itself is less likely to be stable than a fully released and actively used version.

Luckily most of these languages (especially those that are open source) will have a public bug tracking system that you can submit reports to.

In my own experience, I ran into a fairly obscure but severe bug in Scala on Windows. I submitted my findings to the bug tracker and the issue was fixed fairly quickly. In that case, the language developers were smart enough to include a helpful note in the error log output, suggesting that what I'd run into was in fact a compiler error, and said where to submit the report.

share|improve this answer
    
Hope you don't mind; I added a new paragraph (pending approval) which I thought might be relevant. Not only might a compiler contain bugs, it might contain malicious code. –  Andy Jul 9 '13 at 10:03
    
@Andy it looks like one of the moderators rejected it as something that should be a comment or separate answer. –  KChaloux Jul 9 '13 at 12:51
    
Not just "yes", but "hell yes!" :-) –  Hellion Jul 9 '13 at 14:45

In layman's words:

All programs can have bugs.

Compilers are programs.

Ergo, compilers can have bugs.

share|improve this answer
52  
More worrisome: Debuggers are programs. Therefore, debuggers have bugs. –  jozefg Jul 8 '13 at 14:52
17  
@jozefg: So how do you debug the debugger? Who watches the watchers? –  FrustratedWithFormsDesigner Jul 8 '13 at 15:04
12  
@FrustratedWithFormsDesigner The watcher watchers, duh. –  Jimmy Hoffa Jul 8 '13 at 15:14
9  
@JoelFan Since I wrote "can have", that exception is covered. If you say "have" you have to specify that you are referring to non-trivial programs only. By saying "can have", you don't have to. –  user61852 Jul 8 '13 at 16:43
8  
"Hello world" programs can have bugs if its complied with a bugged compiler. –  wtsang02 Jul 8 '13 at 17:50

There can bugs even in hardware; a famous example is the Pentium FDIV bug. Without doubt there is the possibility that the compilers contain bugs.

share|improve this answer
2  
+1 This led me to the scratch monkey story. –  luser droog Jul 9 '13 at 7:10

Compilers and interpreters are software too, and thus they aren't free from any of the problems of other software.

This is an example from a compiler as recent as MSVC 11 (2012), and here's an article on how they test the backend.

share|improve this answer
1  

Of course, because compilers are software.

In 2005, I had a piece of code fail in a highly critical piece of software I had written for a large company. Since it cost the company literally millions of dollars to rectify, they of course launched a big-ass investigation.

Thankfully (from my perspective), the issue turned out to be a compiler issue in Delphi. In the try finally block, the return value of a function was destroyed, and resulted in absolutely random results back to the caller. This was documented, and acknowledged by Borland.

.NET was well known to have literally hundreds of different memory leaks, particularly in its early implementations.

I would contend that there is no such thing as bugless software. Compilers are no exception. They are, though, tested more thoroughly than most business software, and are consumed by smart, critical, contentious people, so their track record has actually, on the whole, been pretty good.

share|improve this answer
    
There is "formally verified" software. It is mathematically proven to work. Occasionally even formally verified code has bugs. IIRC Java's quicksort implementation was formally verified, but that did not account for overflows. –  David Plumpton Jul 9 '13 at 1:57
1  
What was the software? C'mon :) –  LachlanB Jul 9 '13 at 5:44

Yes of course like any software compilers have bugs, for example the gcc bug list is here

share|improve this answer

Not only bugs, but also deliberate malware.

The "login" trojan implemented by Brian Kernighan to the original Unix C compiler is the most well-known of these; the article http://cm.bell-labs.com/who/ken/trust.html has some background on this.

share|improve this answer
    
Is it clear that that was actually implemented? –  Keith Thompson Jul 8 '13 at 22:20
    
This is a quite interesting topic, but not at all related to this question. –  delnan Jul 8 '13 at 22:38
    
@delnan I disagree; at the heart of the question seems to be "how much can I trust my compiler?" –  Andy Jul 9 '13 at 15:10

Compiler is a program that reads a program written in one language (the source language) and translates it into an another equivalent program in another language (the target language), mostly machine language.

There are different phases of compiler through which your source language code is scanned line by line. There is a symbol table which keeps the track of all Keywords which are scanned for in source language code.

Phase 1 : Lexical Analyzer - reads all the character in source program and forms the logical separation of tokens (int, char, float, if-else,for,while etc.)

Phase 2 : Syntax Analyzer - analyze the structure of stream of tokens. Hierarchical parsing of expressions which includes postfix/prefix etc. (a=b+c*d)

Phase 3 : Semantic Analyzer - Type checking of tokens (integer to real, float etc.) and many things like operator precedence etc..

Phase 4 : Intermediate Code Generator - a=b+c*d-e(temp1=c*d, temp2=temp1+b, temp3=temp2-e)

Phase 5 : Code Optimization - Various Analysis (control flow, data flow, transformations)
which eleminates : Redundancy code, Constants propogation, Partial dead code, common subexpression, Loop invariant code

Phase 6 : Code Generation - Generation of target code (Mostly Assembly Language) putting values in Registers

All these phases are nothing but well written programs and there could be N number of flaws in that..

share|improve this answer

Yes.

Also, not only with compilers, but also with Interpretors/debuggers, and any 3rd party software tool.

We are currently using some 3rd party software, and have been having some of the issue. Sometimes they thank us, for finding and reporting a bug. :)

Some of them have some memory leaks too, which leads to crash. The important question here could be, how to determine if the 3rd party tool, or the compiler has bugs for your application to work correctly?

share|improve this answer
    
Your important question will then lead back to the Halting problem –  wtsang02 Jul 8 '13 at 17:57

Of course, compilers are just programms and their authors are idiots too :). Even language specification can have a bug. Example: c# + foreach + lambda.

Or in Python, bug in interpreter: Compiling evil ast crashes interpreter.

Well, if you want to look on bugs in compiler/interpeter -> look at php. There is a famous bug with integer overflow. First fix started from if (size > INT_MAX) return NULL;. Continuation of the story.

share|improve this answer
    
Compiler writers are not idiots. As compilers are quite complicated the barrier to enter the field is also substantially higher. So we can expect the people who write them to not commit mistakes as average guys do. –  jszpilewski Jul 9 '13 at 11:47
    
The foreach / lambda is not a bug, its comes down to a specific and conscience design decision made before lambdas were added. –  Andy Jul 9 '13 at 15:12
    
@Andy, as I know, no one has knowed what problems this decision will cause. Why not bug? –  nsinreal Jul 9 '13 at 16:08
    
@jszpilewski do you see a smile after that text? –  nsinreal Jul 9 '13 at 16:09
    
Its not a bug because they designed for each a certain way. Yes its unexpected with lambdas in the mix, but it was a purposeful choice made by the language designers. They did change this in .net 4.5 though. Read more about it here blogs.msdn.com/b/ericlippert/archive/2009/11/12/… –  Andy Jul 10 '13 at 1:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.