Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
| 2 | "http://www.w3.org/TR/html4/strict.dtd">
|
Kevin | a675133 | 2007-12-14 05:47:49 +0000 | [diff] [blame] | 3 | <!-- Material used from: HTML 4.01 specs: http://www.w3.org/TR/html401/ -->
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 4 | <html>
|
| 5 | <head>
|
| 6 | <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
|
Chris Lattner | 0fcc09e | 2007-12-11 22:26:03 +0000 | [diff] [blame] | 7 | <title>Comparing clang to other open source compilers</title>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 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">
|
Chris Lattner | 0fcc09e | 2007-12-11 22:26:03 +0000 | [diff] [blame] | 14 | <h1>Clang vs Other Open Source Compilers</h1>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 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
|
Chris Lattner | 74a165b | 2007-12-10 17:38:50 +0000 | [diff] [blame] | 19 | available. We restrict the discussion to very specific objective points
|
| 20 | to avoid controversy where possible. Also, software is infinitely
|
| 21 | mutable, so we don't talk about little details that can be fixed with
|
| 22 | a reasonable amount of effort: we'll talk about issues that are
|
| 23 | difficult to fix for architectural or political reasons.</p>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 24 |
|
| 25 | <p>The goal of this list is to describe how differences in goals lead to
|
| 26 | different strengths and weaknesses, not to make some compiler look bad.
|
| 27 | This will hopefully help you to evaluate whether using clang is a good
|
Chris Lattner | c222f93 | 2007-12-10 06:01:32 +0000 | [diff] [blame] | 28 | idea for your personal goals. Because we don't know specifically what
|
| 29 | <em>you</em> want to do, we describe the features of these compilers in
|
| 30 | terms of <em>our</em> goals: if you are only interested in static
|
| 31 | analysis, you may not care that something lacks codegen support, for
|
| 32 | example.</p>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 33 |
|
| 34 | <p>Please email cfe-dev if you think we should add another compiler to this
|
| 35 | list or if you think some characterization is unfair here.</p>
|
| 36 |
|
Chris Lattner | ac7e090 | 2007-12-10 05:23:01 +0000 | [diff] [blame] | 37 | <ul>
|
| 38 | <li><a href="#gcc">Clang vs GCC</a> (GNU Compiler Collection)</li>
|
| 39 | <li><a href="#elsa">Clang vs Elsa</a> (Elkhound-based C++ Parser)</li>
|
| 40 | <li><a href="#pcc">Clang vs PCC</a> (Portable C Compiler)</li>
|
| 41 | </ul>
|
| 42 |
|
| 43 |
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 44 | <!--=====================================================================-->
|
| 45 | <h2><a name="gcc">Clang vs GCC (GNU Compiler Collection)</a></h2>
|
| 46 | <!--=====================================================================-->
|
| 47 |
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 48 | <p>Pro's of GCC vs clang:</p>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 49 |
|
| 50 | <ul>
|
| 51 | <li>GCC supports languages that clang does not aim to, such as Java, Ada,
|
| 52 | FORTRAN, etc.</li>
|
| 53 | <li>GCC front-ends are very mature and already support C/C++/ObjC and all
|
Chris Lattner | 3b88ce8 | 2008-08-24 05:44:37 +0000 | [diff] [blame^] | 54 | the variants we are interested in. <a href="cxx_status.html">clang's
|
| 55 | support for C++</a> in particular is nowhere near what GCC supports.</li>
|
Chris Lattner | 3e820af | 2008-08-24 05:42:07 +0000 | [diff] [blame] | 56 | <li>GCC's codegen is much more mature than clang's right now and supports
|
| 57 | more targets than LLVM.</li>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 58 | <li>GCC is popular and widely adopted.</li>
|
Chris Lattner | 6c9a70d | 2007-12-10 02:18:15 +0000 | [diff] [blame] | 59 | <li>GCC does not require a C++ compiler to build it.</li>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 60 | </ul>
|
| 61 |
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 62 | <p>Pro's of clang vs GCC:</p>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 63 |
|
| 64 | <ul>
|
Chris Lattner | b5604af | 2007-12-10 07:23:52 +0000 | [diff] [blame] | 65 | <li>The Clang ASTs and design are intended to be <a
|
| 66 | href="features.html#simplecode">easily understandable</a> by
|
Chris Lattner | 0d1638e | 2007-12-10 08:21:12 +0000 | [diff] [blame] | 67 | anyone who is familiar with the languages involved and who has a basic
|
Chris Lattner | 6c9a70d | 2007-12-10 02:18:15 +0000 | [diff] [blame] | 68 | understanding of how a compiler works. GCC has a very old codebase
|
| 69 | which presents a steep learning curve to new developers.</li>
|
| 70 | <li>Clang is designed as an API from its inception, allowing it to be reused
|
| 71 | by source analysis tools, refactoring, IDEs (etc) as well as for code
|
| 72 | generation. GCC is built as a monolithic static compiler, which makes
|
| 73 | it extremely difficult to use as an API and integrate into other tools.
|
| 74 | Further, its historic design and <a
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 75 | href="http://gcc.gnu.org/ml/gcc/2007-11/msg00460.html">current</a>
|
Chris Lattner | ff11fa3 | 2007-12-10 02:05:32 +0000 | [diff] [blame] | 76 | <a href="http://gcc.gnu.org/ml/gcc/2004-12/msg00888.html">policy</a>
|
Chris Lattner | 6c9a70d | 2007-12-10 02:18:15 +0000 | [diff] [blame] | 77 | makes it difficult to decouple the front-end from the rest of the
|
| 78 | compiler. </li>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 79 | <li>Various GCC design decisions make it very difficult to reuse: its build
|
| 80 | system is difficult to modify, you can't link multiple targets into one
|
| 81 | binary, you can't link multiple front-ends into one binary, it uses a
|
| 82 | custom garbage collector, uses global variables extensively, is not
|
| 83 | reentrant or multi-threadable, etc. Clang has none of these problems.
|
| 84 | </li>
|
Chris Lattner | 42f956b | 2007-12-10 02:24:44 +0000 | [diff] [blame] | 85 | <li>For every token, clang tracks information about where it was written and
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 86 | where it was ultimately expanded into if it was involved in a macro.
|
Chris Lattner | 42f956b | 2007-12-10 02:24:44 +0000 | [diff] [blame] | 87 | GCC does not track information about macro instantiations when parsing
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 88 | source code. This makes it very difficult for source rewriting tools
|
| 89 | (e.g. for refactoring) to work in the presence of (even simple)
|
| 90 | macros.</li>
|
Chris Lattner | 42f956b | 2007-12-10 02:24:44 +0000 | [diff] [blame] | 91 | <li>Clang does not implicitly simplify code as it parses it like GCC does.
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 92 | Doing so causes many problems for source analysis tools: as one simple
|
Chris Lattner | 42f956b | 2007-12-10 02:24:44 +0000 | [diff] [blame] | 93 | example, if you write "x-x" in your source code, the GCC AST will
|
| 94 | contain "0", with no mention of 'x'. This is extremely bad for a
|
| 95 | refactoring tool that wants to rename 'x'.</li>
|
Chris Lattner | 45918f3 | 2007-12-12 03:33:41 +0000 | [diff] [blame] | 96 | <li>Clang can serialize its AST out to disk and read it back into another
|
Chris Lattner | 0b11baa | 2007-12-11 22:29:38 +0000 | [diff] [blame] | 97 | program, which is useful for whole program analysis. GCC does not have
|
| 98 | this, but its current PCH mechanism is close. However, GCC's current
|
| 99 | PCH support is architecturally only able to read the dump back into
|
| 100 | the exact same executable as the one that produced it.</li>
|
Chris Lattner | 6c9a70d | 2007-12-10 02:18:15 +0000 | [diff] [blame] | 101 | <li>Clang is <a href="features.html#performance">much faster and uses far
|
| 102 | less memory</a> than GCC.</li>
|
| 103 | <li>Clang aims to provide extremely clear and concise diagnostics (error and
|
| 104 | warning messages), and includes support for <a
|
| 105 | href="features.html#expressivediags">expressive diagnostics</a>. GCC's
|
| 106 | warnings are acceptable, but are often confusing and it does not support
|
| 107 | expressive diagnostics. Clang also preserves typedefs in diagnostics
|
| 108 | consistently.</li>
|
Chris Lattner | ff11fa3 | 2007-12-10 02:05:32 +0000 | [diff] [blame] | 109 | <li>GCC is licensed under the GPL license. clang uses a BSD license, which
|
| 110 | allows it to be used by projects that do not themselves want to be
|
| 111 | GPL.</li>
|
Chris Lattner | 6c9a70d | 2007-12-10 02:18:15 +0000 | [diff] [blame] | 112 | <li>Clang inherits a number of features from its use of LLVM as a backend,
|
| 113 | including support for a bytecode representation for intermediate code,
|
| 114 | pluggable optimizers, link-time optimization support, Just-In-Time
|
| 115 | compilation, etc.</li>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 116 | </ul>
|
| 117 |
|
| 118 | <!--=====================================================================-->
|
| 119 | <h2><a name="elsa">Clang vs Elsa (Elkhound-based C++ Parser)</a></h2>
|
| 120 | <!--=====================================================================-->
|
| 121 |
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 122 | <p>Pro's of Elsa vs clang:</p>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 123 |
|
| 124 | <ul>
|
| 125 | <li>Elsa's support for C++ is far beyond what clang provides. If you need
|
| 126 | C++ support in the next year, Elsa is a great way to get it. That said,
|
| 127 | Elsa is missing important support for templates and other pieces: for
|
| 128 | example, it is not capable of compiling the GCC STL headers from any
|
| 129 | version newer than GCC 3.4.</li>
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 130 | <li>Elsa's parser and AST is designed to be easily extensible by adding
|
| 131 | grammar rules. Clang has a very simple and easily hackable parser,
|
| 132 | but requires you to write C++ code to do it.</li>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 133 | </ul>
|
| 134 |
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 135 | <p>Pro's of clang vs Elsa:</p>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 136 |
|
| 137 | <ul>
|
| 138 | <li>The Elsa community is extremely small and major development work seems
|
| 139 | to have ceased in 2005, though it continues to be used by other projects
|
| 140 | (e.g. Oink). Clang has a vibrant community including developers that
|
Chris Lattner | c222f93 | 2007-12-10 06:01:32 +0000 | [diff] [blame] | 141 | are paid to work on it full time. In practice this means that you can
|
| 142 | file bugs against Clang and they will often be fixed for you. If you
|
| 143 | use Elsa, you are (mostly) on your own for bug fixes and feature
|
| 144 | enhancements.</li>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 145 | <li>Elsa is not built as a stack of reusable libraries like clang is. It is
|
| 146 | very difficult to use part of elsa without the whole front-end. For
|
| 147 | example, you cannot use Elsa to parse C/ObjC code without building an
|
| 148 | AST. You can do this in Clang and it is much faster than building an
|
| 149 | AST.</li>
|
| 150 | <li>Elsa does not have an integrated preprocessor, which makes it extremely
|
| 151 | difficult to accurately map from a source location in the AST back to
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 152 | its original position before preprocessing. Like GCC, it does not keep
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 153 | track of macro expansions.</li>
|
| 154 | <li>Elsa is slower and uses more memory than GCC, which requires far more
|
| 155 | space and time than clang.</li>
|
| 156 | <li>Elsa only does partial semantic analysis. It is intended to work on
|
| 157 | code that is already validated by GCC, so it does not do many semantic
|
| 158 | checks required by the languages it implements.</li>
|
| 159 | <li>Elsa does not support Objective-C.</li>
|
| 160 | <li>Elsa does not support native code generation.</li>
|
| 161 | </ul>
|
| 162 |
|
Chris Lattner | c030f00 | 2007-12-11 07:59:50 +0000 | [diff] [blame] | 163 | <p>Note that there is a fork of Elsa known as "Pork". It addresses some of
|
Chris Lattner | aeae19c | 2007-12-12 04:22:37 +0000 | [diff] [blame] | 164 | these shortcomings by loosely integrating a preprocessor. This allows it
|
Chris Lattner | c030f00 | 2007-12-11 07:59:50 +0000 | [diff] [blame] | 165 | to map from a source location in the AST to the original position before
|
| 166 | preprocessing, providing it better support for static analysis and
|
| 167 | refactoring. For more details, please see the Pork page.</p>
|
| 168 |
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 169 |
|
| 170 | <!--=====================================================================-->
|
| 171 | <h2><a name="pcc">Clang vs PCC (Portable C Compiler)</a></h2>
|
| 172 | <!--=====================================================================-->
|
| 173 |
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 174 | <p>Pro's of PCC vs clang:</p>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 175 |
|
| 176 | <ul>
|
| 177 | <li>The PCC source base is very small and builds quickly with just a C
|
| 178 | compiler.</li>
|
| 179 | </ul>
|
| 180 |
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 181 | <p>Pro's of clang vs PCC:</p>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 182 |
|
| 183 | <ul>
|
| 184 | <li>PCC dates from the 1970's and has been dormant for most of that time.
|
Chris Lattner | 0d1638e | 2007-12-10 08:21:12 +0000 | [diff] [blame] | 185 | The clang + llvm communities are very active.</li>
|
Chris Lattner | 6c9a70d | 2007-12-10 02:18:15 +0000 | [diff] [blame] | 186 | <li>PCC doesn't support C99, Objective-C, and doesn't aim to support
|
| 187 | C++.</li>
|
Chris Lattner | 0d1638e | 2007-12-10 08:21:12 +0000 | [diff] [blame] | 188 | <li>PCC's code generation is very limited compared to LLVM. It produces very
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 189 | inefficient code and does not support many important targets.</li>
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 190 | <li>Like Elsa, PCC's does not have an integrated preprocessor, making it
|
| 191 | extremely difficult to use it for source analysis tools.</li>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 192 | </div>
|
| 193 | </body>
|
| 194 | </html>
|