blob: 7e6c1dfd6a9c92a535e718a9ec17da4f58b8d075 [file] [log] [blame]
Chris Lattner83109672007-12-10 01:44:24 +00001<!-- Material used from: HTML 4.01 specs: http://www.w3.org/TR/html401/ -->
2<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
3 "http://www.w3.org/TR/html4/strict.dtd">
4<html>
5<head>
6 <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
7 <title>Comparing clang to other compilers</title>
8 <link type="text/css" rel="stylesheet" href="menu.css" />
9 <link type="text/css" rel="stylesheet" href="content.css" />
10</head>
11<body>
12 <!--#include virtual="menu.html.incl"-->
13 <div id="content">
14 <h1>Clang vs Other Compilers</h1>
15
16 <p>Building an entirely new compiler front-end is a big task, and it isn't
17 always clear to people why we decided to do this. Here we compare clang
18 and its goals to other open source compiler front-ends that are
19 available. We restrict the discussion to very specific technical points
20 to avoid controversy where possible. Also, software is infinitely
21 mutable, so we avoid mentioning anything that would be easy to fix.</p>
22
23 <p>The goal of this list is to describe how differences in goals lead to
24 different strengths and weaknesses, not to make some compiler look bad.
25 This will hopefully help you to evaluate whether using clang is a good
26 idea for your specific goals.</p>
27
28 <p>Please email cfe-dev if you think we should add another compiler to this
29 list or if you think some characterization is unfair here.</p>
30
31 <!--=====================================================================-->
32 <h2><a name="gcc">Clang vs GCC (GNU Compiler Collection)</a></h2>
33 <!--=====================================================================-->
34
35 <p>Pros of GCC vs clang:</p>
36
37 <ul>
38 <li>GCC supports languages that clang does not aim to, such as Java, Ada,
39 FORTRAN, etc.</li>
40 <li>GCC front-ends are very mature and already support C/C++/ObjC and all
41 the variants we are interested in. clang's support for C++ in
42 particular is nowhere near what GCC supports.</li>
43 <li>GCC is popular and widely adopted.</li>
Chris Lattner6c9a70d2007-12-10 02:18:15 +000044 <li>GCC does not require a C++ compiler to build it.</li>
Chris Lattner83109672007-12-10 01:44:24 +000045 </ul>
46
Chris Lattnerb0c4c632007-12-10 01:52:24 +000047 <p>Pros of clang vs GCC:</p>
Chris Lattner83109672007-12-10 01:44:24 +000048
49 <ul>
Chris Lattner6c9a70d2007-12-10 02:18:15 +000050 <li>The Clang ASTs and design are intended to be easily understandable to
51 anyone who is familiar with the languages involved and who have a basic
52 understanding of how a compiler works. GCC has a very old codebase
53 which presents a steep learning curve to new developers.</li>
54 <li>Clang is designed as an API from its inception, allowing it to be reused
55 by source analysis tools, refactoring, IDEs (etc) as well as for code
56 generation. GCC is built as a monolithic static compiler, which makes
57 it extremely difficult to use as an API and integrate into other tools.
58 Further, its historic design and <a
Chris Lattner83109672007-12-10 01:44:24 +000059 href="http://gcc.gnu.org/ml/gcc/2007-11/msg00460.html">current</a>
Chris Lattnerff11fa32007-12-10 02:05:32 +000060 <a href="http://gcc.gnu.org/ml/gcc/2004-12/msg00888.html">policy</a>
Chris Lattner6c9a70d2007-12-10 02:18:15 +000061 makes it difficult to decouple the front-end from the rest of the
62 compiler. </li>
Chris Lattner83109672007-12-10 01:44:24 +000063 <li>Various GCC design decisions make it very difficult to reuse: its build
64 system is difficult to modify, you can't link multiple targets into one
65 binary, you can't link multiple front-ends into one binary, it uses a
66 custom garbage collector, uses global variables extensively, is not
67 reentrant or multi-threadable, etc. Clang has none of these problems.
68 </li>
69 <li>GCC does not track information about macro instantiations when parsing
70 source code, this makes it very difficult for static analysis and
71 refactoring tools to work in the presense of (even simple) macros.</li>
72 <li>GCC simplifies code as it parses it. As one simple example, if you
73 write "x-x" in your source code, the GCC AST will contain "0", with no
74 mention of x. This is extremely bad for a refactoring tool that wants
Chris Lattner6c9a70d2007-12-10 02:18:15 +000075 to rename 'x'.</li>
Chris Lattner83109672007-12-10 01:44:24 +000076 <li>GCC does not have a way to serialize the AST of a file out to disk and
77 read it back into another program. Its PCH mechanism is architecturally
Chris Lattner6c9a70d2007-12-10 02:18:15 +000078 only able to read the dump back into the exact same executable as the
79 one that produced it.</li>
80 <li>Clang is <a href="features.html#performance">much faster and uses far
81 less memory</a> than GCC.</li>
82 <li>Clang aims to provide extremely clear and concise diagnostics (error and
83 warning messages), and includes support for <a
84 href="features.html#expressivediags">expressive diagnostics</a>. GCC's
85 warnings are acceptable, but are often confusing and it does not support
86 expressive diagnostics. Clang also preserves typedefs in diagnostics
87 consistently.</li>
Chris Lattnerff11fa32007-12-10 02:05:32 +000088 <li>GCC is licensed under the GPL license. clang uses a BSD license, which
89 allows it to be used by projects that do not themselves want to be
90 GPL.</li>
Chris Lattner6c9a70d2007-12-10 02:18:15 +000091 <li>Clang inherits a number of features from its use of LLVM as a backend,
92 including support for a bytecode representation for intermediate code,
93 pluggable optimizers, link-time optimization support, Just-In-Time
94 compilation, etc.</li>
Chris Lattner83109672007-12-10 01:44:24 +000095 </ul>
96
97 <!--=====================================================================-->
98 <h2><a name="elsa">Clang vs Elsa (Elkhound-based C++ Parser)</a></h2>
99 <!--=====================================================================-->
100
101 <p>Pros of Elsa vs clang:</p>
102
103 <ul>
104 <li>Elsa's support for C++ is far beyond what clang provides. If you need
105 C++ support in the next year, Elsa is a great way to get it. That said,
106 Elsa is missing important support for templates and other pieces: for
107 example, it is not capable of compiling the GCC STL headers from any
108 version newer than GCC 3.4.</li>
109 <li>Elsa's parser and AST is designed to be easily composable by adding
110 grammar rules. Clang has a very simple and easily extensible parser,
111 but requires you to write C++ code to extend it.</li>
112 </ul>
113
Chris Lattnerb0c4c632007-12-10 01:52:24 +0000114 <p>Pros of clang vs Elsa:</p>
Chris Lattner83109672007-12-10 01:44:24 +0000115
116 <ul>
117 <li>The Elsa community is extremely small and major development work seems
118 to have ceased in 2005, though it continues to be used by other projects
119 (e.g. Oink). Clang has a vibrant community including developers that
120 are paid to work on it full time.</li>
121 <li>Elsa is not built as a stack of reusable libraries like clang is. It is
122 very difficult to use part of elsa without the whole front-end. For
123 example, you cannot use Elsa to parse C/ObjC code without building an
124 AST. You can do this in Clang and it is much faster than building an
125 AST.</li>
126 <li>Elsa does not have an integrated preprocessor, which makes it extremely
127 difficult to accurately map from a source location in the AST back to
128 its original position before preprocessing. Likewise, it does not keep
129 track of macro expansions.</li>
130 <li>Elsa is slower and uses more memory than GCC, which requires far more
131 space and time than clang.</li>
132 <li>Elsa only does partial semantic analysis. It is intended to work on
133 code that is already validated by GCC, so it does not do many semantic
134 checks required by the languages it implements.</li>
135 <li>Elsa does not support Objective-C.</li>
136 <li>Elsa does not support native code generation.</li>
137 </ul>
138
139
140 <!--=====================================================================-->
141 <h2><a name="pcc">Clang vs PCC (Portable C Compiler)</a></h2>
142 <!--=====================================================================-->
143
144 <p>Pros of PCC vs clang:</p>
145
146 <ul>
147 <li>The PCC source base is very small and builds quickly with just a C
148 compiler.</li>
149 </ul>
150
Chris Lattnerb0c4c632007-12-10 01:52:24 +0000151 <p>Pros of clang vs PCC:</p>
Chris Lattner83109672007-12-10 01:44:24 +0000152
153 <ul>
154 <li>PCC dates from the 1970's and has been dormant for most of that time.
155 The clang + llvm community are very active.</li>
Chris Lattner6c9a70d2007-12-10 02:18:15 +0000156 <li>PCC doesn't support C99, Objective-C, and doesn't aim to support
157 C++.</li>
Chris Lattner83109672007-12-10 01:44:24 +0000158 <li>PCC's code generation is very limited compared to LLVM, it produces very
159 inefficient code and does not support many important targets.</li>
160 <li>PCC's does not have an integrated preprocessor, so it is extremely
161 difficult to use it for source analysis tools.</li>
162 </div>
163</body>
164</html>