Search code examples
compiler-construction

Compiler test cases or how to test a compiler


Compilers like all software, would also be prone to bugs, logical errors.

How does one validate the output generated by the compiler. Typically, my question is(are)

  • How to validate that the machine code generated is correct?

  • How to ensure that the machine code generated is according to the language specification.

  • Does it make sense to just pick an open source project (in C if one is also writing a compiler in C) to just compile it through the "compiler". In that case also, how do judge that the compiler is behaving as expected.

  • Are there any formal test cases (literature) provided by the language standards committee that a "language complying" compiler has to satisfy?

  • What are the sure "give aways" that the problem in a program compiled by a compiler is a compiler bug and not a program bug.

    - Any examples where mainstream compilers get confused and compile the code wrong?

Links to any literature would be appreciated.


Solution

  • There are several compiler test suites out there. We've had some luck using the Plum Hall test suite for a C compiler. It consists of a large set of C code specifically written to test against the language standard. It verifies that the compiler can handle the language syntax and semantics.