Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 1 | <!-- 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
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 20 | to avoid controversy where possible. Also, since software is infinitely
|
| 21 | mutable, so focus on architectural issues that are impractical to fix
|
| 22 | without a major rewrite, instead of talking about little details that
|
| 23 | can be fixed with a reasonable amount of effort.</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
|
| 28 | idea for your specific goals.</p>
|
| 29 |
|
| 30 | <p>Please email cfe-dev if you think we should add another compiler to this
|
| 31 | list or if you think some characterization is unfair here.</p>
|
| 32 |
|
Chris Lattner | ac7e090 | 2007-12-10 05:23:01 +0000 | [diff] [blame] | 33 | <ul>
|
| 34 | <li><a href="#gcc">Clang vs GCC</a> (GNU Compiler Collection)</li>
|
| 35 | <li><a href="#elsa">Clang vs Elsa</a> (Elkhound-based C++ Parser)</li>
|
| 36 | <li><a href="#pcc">Clang vs PCC</a> (Portable C Compiler)</li>
|
| 37 | </ul>
|
| 38 |
|
| 39 |
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 40 | <!--=====================================================================-->
|
| 41 | <h2><a name="gcc">Clang vs GCC (GNU Compiler Collection)</a></h2>
|
| 42 | <!--=====================================================================-->
|
| 43 |
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 44 | <p>Pro's of GCC vs clang:</p>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 45 |
|
| 46 | <ul>
|
| 47 | <li>GCC supports languages that clang does not aim to, such as Java, Ada,
|
| 48 | FORTRAN, etc.</li>
|
| 49 | <li>GCC front-ends are very mature and already support C/C++/ObjC and all
|
| 50 | the variants we are interested in. clang's support for C++ in
|
| 51 | particular is nowhere near what GCC supports.</li>
|
| 52 | <li>GCC is popular and widely adopted.</li>
|
Chris Lattner | 6c9a70d | 2007-12-10 02:18:15 +0000 | [diff] [blame] | 53 | <li>GCC does not require a C++ compiler to build it.</li>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 54 | </ul>
|
| 55 |
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 56 | <p>Pro's of clang vs GCC:</p>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 57 |
|
| 58 | <ul>
|
Chris Lattner | 6c9a70d | 2007-12-10 02:18:15 +0000 | [diff] [blame] | 59 | <li>The Clang ASTs and design are intended to be easily understandable to
|
| 60 | anyone who is familiar with the languages involved and who have a basic
|
| 61 | understanding of how a compiler works. GCC has a very old codebase
|
| 62 | which presents a steep learning curve to new developers.</li>
|
| 63 | <li>Clang is designed as an API from its inception, allowing it to be reused
|
| 64 | by source analysis tools, refactoring, IDEs (etc) as well as for code
|
| 65 | generation. GCC is built as a monolithic static compiler, which makes
|
| 66 | it extremely difficult to use as an API and integrate into other tools.
|
| 67 | Further, its historic design and <a
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 68 | 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] | 69 | <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] | 70 | makes it difficult to decouple the front-end from the rest of the
|
| 71 | compiler. </li>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 72 | <li>Various GCC design decisions make it very difficult to reuse: its build
|
| 73 | system is difficult to modify, you can't link multiple targets into one
|
| 74 | binary, you can't link multiple front-ends into one binary, it uses a
|
| 75 | custom garbage collector, uses global variables extensively, is not
|
| 76 | reentrant or multi-threadable, etc. Clang has none of these problems.
|
| 77 | </li>
|
Chris Lattner | 42f956b | 2007-12-10 02:24:44 +0000 | [diff] [blame] | 78 | <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] | 79 | 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] | 80 | GCC does not track information about macro instantiations when parsing
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 81 | source code. This makes it very difficult for source rewriting tools
|
| 82 | (e.g. for refactoring) to work in the presence of (even simple)
|
| 83 | macros.</li>
|
Chris Lattner | 42f956b | 2007-12-10 02:24:44 +0000 | [diff] [blame] | 84 | <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] | 85 | Doing so causes many problems for source analysis tools: as one simple
|
Chris Lattner | 42f956b | 2007-12-10 02:24:44 +0000 | [diff] [blame] | 86 | example, if you write "x-x" in your source code, the GCC AST will
|
| 87 | contain "0", with no mention of 'x'. This is extremely bad for a
|
| 88 | refactoring tool that wants to rename 'x'.</li>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 89 | <li>GCC does not have a way to serialize the AST of a file out to disk and
|
| 90 | read it back into another program. Its PCH mechanism is architecturally
|
Chris Lattner | 6c9a70d | 2007-12-10 02:18:15 +0000 | [diff] [blame] | 91 | only able to read the dump back into the exact same executable as the
|
| 92 | one that produced it.</li>
|
| 93 | <li>Clang is <a href="features.html#performance">much faster and uses far
|
| 94 | less memory</a> than GCC.</li>
|
| 95 | <li>Clang aims to provide extremely clear and concise diagnostics (error and
|
| 96 | warning messages), and includes support for <a
|
| 97 | href="features.html#expressivediags">expressive diagnostics</a>. GCC's
|
| 98 | warnings are acceptable, but are often confusing and it does not support
|
| 99 | expressive diagnostics. Clang also preserves typedefs in diagnostics
|
| 100 | consistently.</li>
|
Chris Lattner | ff11fa3 | 2007-12-10 02:05:32 +0000 | [diff] [blame] | 101 | <li>GCC is licensed under the GPL license. clang uses a BSD license, which
|
| 102 | allows it to be used by projects that do not themselves want to be
|
| 103 | GPL.</li>
|
Chris Lattner | 6c9a70d | 2007-12-10 02:18:15 +0000 | [diff] [blame] | 104 | <li>Clang inherits a number of features from its use of LLVM as a backend,
|
| 105 | including support for a bytecode representation for intermediate code,
|
| 106 | pluggable optimizers, link-time optimization support, Just-In-Time
|
| 107 | compilation, etc.</li>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 108 | </ul>
|
| 109 |
|
| 110 | <!--=====================================================================-->
|
| 111 | <h2><a name="elsa">Clang vs Elsa (Elkhound-based C++ Parser)</a></h2>
|
| 112 | <!--=====================================================================-->
|
| 113 |
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 114 | <p>Pro's of Elsa vs clang:</p>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 115 |
|
| 116 | <ul>
|
| 117 | <li>Elsa's support for C++ is far beyond what clang provides. If you need
|
| 118 | C++ support in the next year, Elsa is a great way to get it. That said,
|
| 119 | Elsa is missing important support for templates and other pieces: for
|
| 120 | example, it is not capable of compiling the GCC STL headers from any
|
| 121 | version newer than GCC 3.4.</li>
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 122 | <li>Elsa's parser and AST is designed to be easily extensible by adding
|
| 123 | grammar rules. Clang has a very simple and easily hackable parser,
|
| 124 | but requires you to write C++ code to do it.</li>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 125 | </ul>
|
| 126 |
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 127 | <p>Pro's of clang vs Elsa:</p>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 128 |
|
| 129 | <ul>
|
| 130 | <li>The Elsa community is extremely small and major development work seems
|
| 131 | to have ceased in 2005, though it continues to be used by other projects
|
| 132 | (e.g. Oink). Clang has a vibrant community including developers that
|
| 133 | are paid to work on it full time.</li>
|
| 134 | <li>Elsa is not built as a stack of reusable libraries like clang is. It is
|
| 135 | very difficult to use part of elsa without the whole front-end. For
|
| 136 | example, you cannot use Elsa to parse C/ObjC code without building an
|
| 137 | AST. You can do this in Clang and it is much faster than building an
|
| 138 | AST.</li>
|
| 139 | <li>Elsa does not have an integrated preprocessor, which makes it extremely
|
| 140 | 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] | 141 | its original position before preprocessing. Like GCC, it does not keep
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 142 | track of macro expansions.</li>
|
| 143 | <li>Elsa is slower and uses more memory than GCC, which requires far more
|
| 144 | space and time than clang.</li>
|
| 145 | <li>Elsa only does partial semantic analysis. It is intended to work on
|
| 146 | code that is already validated by GCC, so it does not do many semantic
|
| 147 | checks required by the languages it implements.</li>
|
| 148 | <li>Elsa does not support Objective-C.</li>
|
| 149 | <li>Elsa does not support native code generation.</li>
|
| 150 | </ul>
|
| 151 |
|
| 152 |
|
| 153 | <!--=====================================================================-->
|
| 154 | <h2><a name="pcc">Clang vs PCC (Portable C Compiler)</a></h2>
|
| 155 | <!--=====================================================================-->
|
| 156 |
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 157 | <p>Pro's of PCC vs clang:</p>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 158 |
|
| 159 | <ul>
|
| 160 | <li>The PCC source base is very small and builds quickly with just a C
|
| 161 | compiler.</li>
|
| 162 | </ul>
|
| 163 |
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 164 | <p>Pro's of clang vs PCC:</p>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 165 |
|
| 166 | <ul>
|
| 167 | <li>PCC dates from the 1970's and has been dormant for most of that time.
|
| 168 | The clang + llvm community are very active.</li>
|
Chris Lattner | 6c9a70d | 2007-12-10 02:18:15 +0000 | [diff] [blame] | 169 | <li>PCC doesn't support C99, Objective-C, and doesn't aim to support
|
| 170 | C++.</li>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 171 | <li>PCC's code generation is very limited compared to LLVM, it produces very
|
| 172 | inefficient code and does not support many important targets.</li>
|
Chris Lattner | 40ae32f | 2007-12-10 05:06:15 +0000 | [diff] [blame] | 173 | <li>Like Elsa, PCC's does not have an integrated preprocessor, making it
|
| 174 | extremely difficult to use it for source analysis tools.</li>
|
Chris Lattner | 8310967 | 2007-12-10 01:44:24 +0000 | [diff] [blame] | 175 | </div>
|
| 176 | </body>
|
| 177 | </html>
|