Compilers
A compiler translates a program from one language into an equivalent program in another, such as machine instructions or another language meant for programmers to read (Aho et al., 2007). Compilers can rewrite programs to run faster, but measured speed gains depend on the programs and on what is compared (Pfenning et al., 2026; Kästner et al., 2017; Keiserås et al., 2026). Their output is not always faithful. Random test programs find bugs in widely used compilers, programs’ own tests miss many of them, and proofs cover only stated stages (Yang et al., 2011; Marcozzi et al., 2019; CompCert, n.d.). Studies of improved error messages for beginners give mixed results (Becker et al., 2019).
Translation and execution
An interpreter, by contrast, carries out the program’s operations on the inputs it receives (Aho et al., 2007). It can work from the source code or from bytecode, instructions produced by an earlier translation (Universidad Politécnica de Cartagena, 2022).
Usage varies for translation between two languages written for programmers. Some accounts call it compiling; others separate this source-to-source translation from compiling into lower-level instructions. The TypeScript documentation calls generating JavaScript from TypeScript transpiling (Aho et al., 2007; Harsu, 2000; TypeScript Team, 2026).
From early compilers to reusable tools
Historians name different first compilers depending on how they define one. Donald Knuth and Luis Trabb Pardo date Grace Hopper’s A-0, which assembled programs from existing routines, to spring 1952, and credit Alick Glennie’s Autocode as the first compiler (Hopper, 1952; Knuth & Trabb Pardo, 1976). John Backus instead credits Laning and Zierler’s Whirlwind system as the first working algebraic compiler, one that translated mathematical notation, and disputed whether Glennie’s example qualified (Backus, 1978b; Laning & Zierler, 1954).
Compiler design also developed formal ways to describe languages. The ALGOL 60 report separated a reference language from the ways different machines represented it (Naur et al., 1960). A grammar describes how pieces of a program combine. Knuth formalised which grammars allow left-to-right analysis looking a fixed number of symbols ahead, and Yacc generated code to recognise such structure (Knuth, 1965; Johnson, 1978).
The GNU Compiler Collection (GCC) and LLVM show two ways to reuse compiler machinery. Supporting a new kind of computer in GCC means describing how its intermediate code maps to that machine’s assembly language, a notation for machine instructions (Stallman, 1987; Perumal & Karkare, 2013). LLVM was built around one shared code representation that can be analysed and rewritten at several points, including when separately compiled pieces are linked and while programs run (Lattner & Adve, 2003; LLVM Project, n.d.a).
Phases and intermediate representations
A compiler’s work divides into phases, though one pass through the code can do several of them together (Aho et al., 2014).
| Phase | What it does |
|---|---|
| Lexing | Groups source characters into tokens, such as names and operators (Appel & Palsberg, 2002). |
| Parsing | Works out how tokens group into expressions and other parts of the program (Appel & Palsberg, 2002). |
| Semantic analysis | Connects variable uses to their definitions and checks types, such as whether an expression produces a number (Appel & Palsberg, 2002). |
| Intermediate code generation | Translates the analysed program into an intermediate representation (IR), a notation the compiler uses internally (Appel & Palsberg, 2002). |
| Optimisation | Rewrites intermediate code to improve properties such as execution time (Águila, 2004). |
| Code generation | Turns the intermediate code into output, for instance by selecting instructions for the target machine (Águila, 2004; Appel & Palsberg, 2002). |
The choice of representation makes some analyses easier. GCC’s GIMPLE uses a simplified three-address code, in which an instruction names at most two inputs and one destination, and lets GCC share analyses across source languages (Johnson & Zelenski, 2012; GCC Team, 2026). In static single assignment (SSA) form, each name is assigned once in the program text. Where two paths join, such as after an if and its else, a phi operation picks the value from the path taken (Cytron et al., 1991).
Compiling while a program runs
Just-in-time (JIT) compilation translates code after the program starts, unlike ahead-of-time compilation (Universidad Politécnica de Cartagena, 2022; Aycock, 2003). It can use what it observes during execution to decide where optimisation is worth the time. In adaptive SELF, a method is first translated quickly, and heavily used methods are compiled again with an optimising compiler (Hölzle, 1994).
The idea is old. A historical survey names a 1960 paper on Lisp as a candidate for its earliest account; Smalltalk-80 and SELF later translated methods when needed (Aycock, 2003; Chambers et al., 1991). Modern engines combine strategies. JavaScriptCore runs an interpreter, a bytecode-template JIT and two optimising tiers (Pizlo, 2020). V8’s Sparkplug turns bytecode straight into machine instructions without another intermediate representation (Swirski, 2021).
Optimisation and its measured gains
An optimisation changes a program’s form to improve execution time, memory use or code size. One optimisation, constant folding, computes an operation such as 2 + 3 during compilation. Another, constant propagation, replaces a variable with a value known to be constant, which can expose more operations to fold (Pfenning et al., 2026).
Language rules set the limits of these rewrites. In standard C, signed integer arithmetic that exceeds the type’s range has undefined behaviour: the standard imposes no requirements, so an optimiser may assume such overflow never happens (Svoboda, n.d.). A GCC setting instead makes overflowing signed arithmetic wrap around, which changes which rewrites are allowed (GCC Team, 2024).
How large are speed gains?
The size of a speed gain depends on the starting point of the comparison. Turning optimisation on and upgrading an already optimising compiler measure different effects (Kästner et al., 2017; Keiserås et al., 2026).
| What changed | Measured result |
|---|---|
| Turn on GCC optimisation for a suite of embedded-systems programs | -O1 and -O2 cut execution time to 45% and 42% of the unoptimised -O0 time (Kästner et al., 2017). |
| Upgrade from GCC 4 to GCC 13 at the same setting, on the C programs in SPEC CPU 2017 | Estimated time and energy costs fell by 13% at -O2 and 9% at -O3 (Keiserås et al., 2026). |
Even which setting is faster can depend on the setup. In one experiment, changing the size of the execution environment or the order in which program pieces were linked could reverse whether -O2 or -O3 appeared faster (Mytkowicz et al., 2009).
How far compiler output can be trusted
A compiler is correct when its translation preserves the program’s specified behaviour. Tests can reveal defects, while a proof can establish what a successful translation preserves under stated assumptions (Yang et al., 2011; Tan et al., 2019). A separate question is whether the compiler executable itself matches the compiler’s source code (Wheeler, 2009).
What bug reports show
Bug counts here rest on one hand-checked sample and one tracker study, and cover only what trackers record. Compiler bugs can appear before a program runs or change what it does. In a sample of 219 fixes linked to bug reports, the most frequent symptoms were incorrect messages, rejection of valid programs and wrong generated code (He & Zhong, 2025).
Fixes can take months. Across about 50,000 fixed GCC and LLVM reports, the mean time from filing to closing a bug was 200 days for GCC and 111 days for LLVM (Sun et al., 2016). One later analysis excluded LLVM’s newer tracker because it did not mark which reports were fixed (Zhong, 2025).
What tests detect
Randomly generated programs, a technique called fuzzing, find bugs in widely used compilers. Csmith generates C programs for differential testing, which compares the results of different compilers or settings on the same program. Its authors reported more than 325 bugs in mainstream C compilers over three years (Yang et al., 2011).
A program’s own tests rarely catch a compiler bug that changed it. In one study, almost half the sampled bugs, found by random test programs, changed the compiled binary of at least one package, yet the packages’ tests produced only two failures (Marcozzi et al., 2019). Those tests ran a median of 47% of statements, so about half the code went unexercised (Marcozzi et al., 2019).
What a proof guarantees
A semantic preservation theorem relates a program’s behaviour before and after a successful translation, but only between the stages it names. CompCert’s theorem starts from a tree representing the analysed C program and ends with assembly instructions, before they become machine code and are linked (CompCert, n.d.). An audit found further assumptions, including how the source and target languages are modelled and how the compiler uses external algorithms (Monniaux & Boulmé, 2022).
CakeML’s theorem reaches the machine code itself. It sets conditions on the machine’s starting state, configuration and environment, and allows the program to run out of memory after behaving correctly up to that point (Tan et al., 2019).
Testing can cover what a proof leaves out. Csmith found defects in an older, unverified part of CompCert that processed source programs. It found no wrong-code errors in the early-2011 development compiler after about six years of processor time (Yang et al., 2011).
Checking the built compiler
Compilers are often built by bootstrapping: an older version of a compiler builds a newer version of itself, usually in stages (Xu, 2025b). In his 1984 lecture “Reflections on trusting trust”, Ken Thompson used this to show that reviewing a program’s source leaves open whether the tools that built it can be trusted (Thompson, 1984).
Diverse double-compiling rebuilds a compiler with a different, independent compiler to check that the executable matches its stated source. David Wheeler proved that matching output establishes this under the method’s assumptions; what the source itself does still needs review (Wheeler, 2009). In one demonstration, three Linux distributions built identical GNU Mes binaries starting from different versions of GCC, and a later TinyCC build matched them (Reproducible Builds, 2019).
Error messages for beginners
Studies disagree on whether enhanced compiler error messages help beginners, partly because they measure different outcomes. With Java learners, enhanced messages reduced repeated errors per common message but made no significant difference to total errors per student. Another study found no significant effect of adding explanations and examples, and a working group judged comparisons between the two inconclusive (Becker, 2016; Denny et al., 2014; Becker et al., 2019).
Explanations can also be judged by how fast beginners fix errors. In an experiment with 106 participants repairing six C programs, GPT-4 explanations beat standard compiler messages on repair time in one of the six tasks (Santos & Becker, 2024).
Further reading
- Appel and Palsberg (2002) introduces the jobs a compiler performs and shows how they fit together.
- Knuth and Trabb Pardo (1976) traces early programming languages and the systems built to translate them.
- Lattner and Adve (2003) explains the original design of LLVM’s shared representation.
- Yang et al. (2011) describes Csmith and what its random test programs found in C compilers.
- CompCert (n.d.) states CompCert’s preservation theorem and the stages it covers.
- Becker et al. (2019) surveys research on compiler error messages and compares studies of changes to them.
First published .
Known gaps
What this article cannot tell you yet.
- The early history does not survey compiler development in the Soviet Union or Japan.
- The benchmark studies do not establish an average speed gain across production programs and hardware.
- The probability of meeting a compiler bug in a production compilation is not estimated.
- Whether improved error messages help beginners on later tasks remains open.
References
- Solid source
- Rated highly trustworthy by the research, and every passage taken from it was found in it.
- Weak source
- Rated low, or a passage taken from it was not found in it.
- Medium trust
- Rated medium by the research.
- Not checked
- Rated high, but its passages could not all be checked against it.
Show all 48 references
- Águila, J. (2004). Fases de un Compilador. Universidad de Magallanes. https://kataix.umag.cl/~jaguila/Compilers/T01_Fases_Compilador.pdf Medium trust Documentation, read in large part.
- Aho, A. V., Lam, M. S., Sethi, R., & Ullman, J. D. (2007). Compilers: Principles, Techniques, and Tools. Pearson Addison-Wesley, 2nd edition. https://dpvipracollege.ac.in/wp-content/uploads/2023/01/Alfred-V.-Aho-Monica-S.-Lam-Ravi-Sethi-Jeffrey-D.-Ullman-Compilers-Principles-Techniques-and-Tools-Pearson_Addison-Wesley-2007.pdf Medium trust Book, read in large part.
- Aho, A. V., Lam, M. S., Sethi, R., & Ullman, J. D. (2014). Compilers: Principles, Techniques, and Tools (2nd ed., Pearson New International Edition). Pearson Education. https://api.pageplace.de/preview/DT0400.9781292037233_A24581712/preview-9781292037233_A24581712.pdf Medium trust Book, read in large part.
- Appel, A. W., & Palsberg, J. (2002). Modern Compiler Implementation in Java (2nd ed.). Cambridge University Press. https://assets.cambridge.org/97805218/20608/excerpt/9780521820608_excerpt.pdf Solid source Book, read in large part.
- Aycock, J. (2003). A Brief History of Just-In-Time. ACM Computing Surveys, 35(2), 97–113. https://citeseerx.ist.psu.edu/document?doi=102c32b73ee0fb172b746d9ff983d5f20fc0767c&repid=rep1&type=pdf Solid source Peer-reviewed, read in large part.
- Backus, J. (1978b). The History of FORTRAN I, II, and III. ACM SIGPLAN Notices, 13(8), 165–180. https://softwarepreservation.computerhistory.org/FORTRAN/paper/p165-backus.pdf Medium trust Peer-reviewed, read in large part.
- Becker, B. A. (2016). An Effective Approach to Enhancing Compiler Error Messages. Proceedings of the 47th ACM Technical Symposium on Computer Science Education, 126–131. https://www.academia.edu/26100242/An_Effective_Approach_to_Enhancing_Compiler_Error_Messages Solid source Peer-reviewed, read in large part.
- Becker, B. A., Denny, P., Pettit, R., Bouchard, D., Bouvier, D. J., Harrington, B., et al. (2019). Compiler Error Messages Considered Unhelpful: The Landscape of Text-Based Programming Error Message Research. 2019 ITiCSE Working Group Reports. https://www.researchgate.net/publication/339039595_Compiler_Error_Messages_Considered_Unhelpful_The_Landscape_of_Text-Based_Programming_Error_Message_Research Solid source Peer-reviewed, read in large part.
- Chambers, C., Ungar, D., & Lee, E. (1991). An Efficient Implementation of SELF, a Dynamically-Typed Object-Oriented Language Based on Prototypes. Lisp and Symbolic Computation, 4(3). https://bibliography.selflanguage.org/_static/implementation.pdf Medium trust Peer-reviewed, read in large part.
- CompCert (n.d.). CompCert C: A trustworthy compiler. The CompCert C compiler manual. https://compcert.org/man/manual001.html Weak source Documentation, read in large part.
- Cytron, R., Ferrante, J., Rosen, B. K., Wegman, M. N., & Zadeck, F. K. (1991). Efficiently Computing Static Single Assignment Form and the Control Dependence Graph. ACM Transactions on Programming Languages and Systems, 13(4), 451–490. https://faculty.cc.gatech.edu/~harrold/6340/cs6340_fall2009/Readings/cytron91oct.pdf Solid source Peer-reviewed, read in large part.
- Denny, P., Luxton-Reilly, A., & Carpenter, D. (2014). Enhancing Syntax Error Messages Appears Ineffectual. Proceedings of the 2014 Conference on Innovation & Technology in Computer Science Education, 273–278. https://www.cs.auckland.ac.nz/courses/compsci747s2c/lectures/errors.pdf Solid source Peer-reviewed, read in large part.
- GCC Team (2024). Code Generation Options. Using the GNU Compiler Collection, GCC 14.1.0. https://gcc.gnu.org/onlinedocs/gcc-14.1.0/gcc/Code-Gen-Options.html Solid source Documentation, read in large part.
- GCC Team (2026). SSA for Trees. GNU Project. https://gcc.gnu.org/projects/tree-ssa/ Solid source Documentation, read in large part.
- Harsu, M. (2000). Re-engineering Legacy Software through Language Conversion. University of Tampere. https://trepo.tuni.fi/bitstream/handle/10024/67033/951-44-4899-5.pdf?isAllowed=y&sequence=1 Medium trust Read in large part.
- He, Z., & Zhong, H. (2025). From bug reports to workarounds: The real-world impact of compiler bugs. IEEE International Conference on Software Analysis, Evolution and Reengineering. https://www.researchgate.net/publication/391952518_From_Bug_Reports_to_Workarounds_The_Real-World_Impact_of_Compiler_Bugs Solid source Peer-reviewed, read in large part.
- Hölzle, U. (1994). Adaptive optimization for SELF: Reconciling high performance with exploratory programming. Stanford University. https://bibliography.selflanguage.org/_static/urs-thesis.pdf Solid source Read in large part.
- Hopper, G. M. (1952). The Education of a Computer. Association for Computing Machinery meetings, May 2–3, 1952. https://mads.si.edu/mads/id/NMAH-AC0324-B004-F010-001 Solid source Read in large part.
- Johnson, S. C. (1978). Yacc: Yet another compiler-compiler. Bell Laboratories. https://archive.computerhistory.org/resources/access/text/2024/05/102734484-05-0005-acc.pdf Solid source Documentation, read in large part.
- Johnson, M., & Zelenski, J. (2012). Three Address Code Examples. Stanford University. https://web.stanford.edu/class/archive/cs/cs143/cs143.1128/handouts/240%20TAC%20Examples.pdf Solid source Documentation, read in large part.
- Kästner, D., Leroy, X., Blazy, S., Schommer, B., Schmidt, M., & Ferdinand, C. (2017). Closing the Gap – The Formally Verified Optimizing Compiler CompCert. Safety-Critical Systems Symposium, Safety-Critical Systems Club. https://xavierleroy.org/publi/compcert-SSS2017.pdf Medium trust Read in large part.
- Keiserås, B. I., Markussen, B., Yu, I. C., Larsen, K. F., Kirkeby, M. H., & Thomsen, M. K. (2026). Does GCC Compiler Development Pay for Itself? GCC Versions' Impact on Energy Consumption. 20th International Symposium on Empirical Software Engineering and Measurement, Article 38. https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.ESEM.2026.38 Solid source Peer-reviewed, read in large part.
- Knuth, D. E. (1965). On the translation of languages from left to right. Information and Control, 8(6), 607–639. https://harrymoreno.com/assets/greatPapersInCompSci/2.5_-_On_the_translation_of_languages_from_left_to_right-Donald_E._Knuth.pdf Solid source Peer-reviewed, read in large part.
- Knuth, D. E., & Trabb Pardo, L. (1976). The Early Development of Programming Languages. Stanford University. https://bitsavers.trailing-edge.com/pdf/stanford/cs_techReports/STAN-CS-76-562_EarlyDevelPgmgLang_Aug76.pdf Solid source Read in large part.
- Laning, J. H., & Zierler, N. (1954). A program for translation of mathematical equations for Whirlwind I. Instrumentation Laboratory, Massachusetts Institute of Technology, Engineering Memorandum E-364. https://web.mit.edu/digitalapollo/Documents/Chapter5/laningwhirlwind.pdf Solid source Read in large part.
- Lattner, C., & Adve, V. (2003). LLVM: A Compilation Framework for Lifelong Program Analysis & Transformation. University of Illinois at Urbana-Champaign. https://llvm.org/pubs/2003-09-30-LifelongOptimizationTR.pdf Medium trust Read in large part.
- LLVM Project (n.d.a). LLVM Language Reference Manual. LLVM. https://llvm.org/docs/LangRef.html Solid source Documentation, read in large part.
- Marcozzi, M., Tang, Q., Donaldson, A. F., & Cadar, C. (2019). Compiler fuzzing: How much does it matter? Proceedings of the ACM on Programming Languages, 3(OOPSLA), Article 155. https://www.doc.ic.ac.uk/~afd/papers/2019/OOPSLA.pdf Solid source Peer-reviewed, read in large part.
- Monniaux, D., & Boulmé, S. (2022). The trusted computing base of the CompCert verified compiler. Programming Languages and Systems, Lecture Notes in Computer Science, 13240, 204–233. https://link.springer.com/chapter/10.1007/978-3-030-99336-8_8 Solid source Peer-reviewed, abstract only.
- Mytkowicz, T., Diwan, A., Hauswirth, M., & Sweeney, P. F. (2009). Producing wrong data without doing anything obviously wrong! ACM SIGPLAN Notices. https://john.cs.olemiss.edu/~hcc/researchMethods/notes/localcopy/mytkowicz-wrong-data.pdf Solid source Peer-reviewed, read in large part.
- Naur, P., Backus, J. W., Bauer, F. L., Green, J., Katz, C., McCarthy, J., et al. (1960). Report on the Algorithmic Language ALGOL 60. Communications of the ACM, 3(5), 299–314. https://softwarepreservation.computerhistory.org/ALGOL/report/Algol60_report_CACM_1960_June.pdf Solid source Documentation, read in large part.
- Perumal, S., & Karkare, A. (2013). Retargeting GCC: Do We Reinvent the Wheel Every Time? APPLC’13. https://arxiv.org/abs/1309.7685 Medium trust Preprint, read in large part.
- Pfenning, F., Simmons, R., & Hoffmann, J. (2026). Lecture Notes on Basic Optimizations. Carnegie Mellon University, 15-411: Compiler Design. https://www.cs.cmu.edu/~411/lectures/17-opt-1.pdf Medium trust Read in large part.
- Pizlo, F. (2020). Speculation in JavaScriptCore. WebKit. https://webkit.org/blog/10308/speculation-in-javascriptcore/ Medium trust Blog post, read in large part.
- Reproducible Builds (2019). Reproducible bootstrap of Mes C compiler. Reproducible Builds. https://reproducible-builds.org/news/2019/12/21/reproducible-bootstrap-of-mes-c-compiler/ Medium trust Blog post, read in large part.
- Santos, E. A., & Becker, B. A. (2024). Not the Silver Bullet: LLM-enhanced Programming Error Messages are Ineffective in Practice. 2024 UK and Ireland Computing Education Research Conference. https://arxiv.org/abs/2409.18661 Solid source Peer-reviewed, abstract only.
- Stallman, R. M. (1987). GCC first release email. Computer Genome. https://www.computergenome.com/open-source/gcc-first-release-email Medium trust Read in large part.
- Sun, C., Le, V., Zhang, Q., & Su, Z. (2016). Toward understanding compiler bugs in GCC and LLVM. Proceedings of the 25th International Symposium on Software Testing and Analysis, 294–305. https://web.cs.ucdavis.edu/~su/publications/issta16-compiler-bug-study.pdf Solid source Peer-reviewed, read in large part.
- Svoboda, D. (n.d.). N3974 - Undefined Behavior in the C Programming Language with Examples. ISO/IEC JTC1/SC22/WG14. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3974.htm Solid source Documentation, read in large part.
- Swirski, L. (2021). Sparkplug — a non-optimizing JavaScript compiler. V8. https://v8.dev/blog/sparkplug Medium trust Vendor page, read in large part.
- Tan, Y. K., Myreen, M. O., Kumar, R., Fox, A., Owens, S., & Norrish, M. (2019). The Verified CakeML Compiler Backend. Journal of Functional Programming. https://kar.kent.ac.uk/71304/ Solid source Peer-reviewed, read in large part.
- Thompson, K. (1984). Reflections on trusting trust. Communications of the ACM, 27(8), 761–763. https://crysp.uwaterloo.ca/courses/cs458/W10-lectures/local/www.acm.org/classics/sep95/ Medium trust Peer-reviewed, read in large part.
- TypeScript Team (2026). Using Babel with TypeScript. TypeScript Documentation. https://www.typescriptlang.org/docs/handbook/babel-with-typescript.html Solid source Documentation, read in large part.
- Universidad Politécnica de Cartagena (2022). Tema 5. Lenguajes del computador: alto nivel, ensamblador y máquina. Fundamentos de Computadores, Curso 2022/23. https://ocw.bib.upct.es/pluginfile.php/15799/mod_resource/content/5/tema5-transparencias.pdf Solid source Read in large part.
- Wheeler, D. A. (2009). Fully countering trusting trust through diverse double-compiling. George Mason University. https://dwheeler.com/trusting-trust/dissertation/html/wheeler-trusting-trust-ddc.html Medium trust Read in large part.
- Xu, J. (2025b). Redesigning the initial bootstrap sequence. Inside Rust. https://blog.rust-lang.org/inside-rust/2025/05/29/redesigning-the-initial-bootstrap-sequence/ Solid source Blog post, read in large part.
- Yang, X., Chen, Y., Eide, E., & Regehr, J. (2011). Finding and understanding bugs in C compilers. Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation, 283–294. https://www.cs.tufts.edu/comp/150FP/archive/john-regehr/finding-c-bugs.pdf Solid source Peer-reviewed, read in large part.
- Zhong, H. (2025). Understanding compiler bugs in real development. Proceedings of the IEEE/ACM International Conference on Software Engineering. https://drhaozhong.github.io/paper/understandingbug.pdf Solid source Peer-reviewed, read in large part.