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
|
| 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>
|
| 44 | </ul>
|
| 45 |
|
| 46 | <p>Cons of GCC vs clang:</p>
|
| 47 |
|
| 48 | <ul>
|
| 49 | <li>GCC has a very old codebase which presents a steep learning curve to new
|
| 50 | developers. The Clang ASTs and design are intended to be easily
|
| 51 | understandable to anyone who is familiar with the languages involved
|
| 52 | and have a basic understanding of how a compiler works.</li>
|
| 53 | <li>GCC is built as a monolithic static compiler, which makes it extremely
|
| 54 | difficult to use as an API and integrate into other tools (e.g. an IDE).
|
| 55 | Its historic design and <a
|
| 56 | href="http://gcc.gnu.org/ml/gcc/2007-11/msg00460.html">current</a>
|
| 57 | <a href="http://gcc.gnu.org/ml/gcc/2004-12/msg00888.html">policy</a> was
|
| 58 | intended to make it difficult to decouple the front-end from
|
| 59 | the rest of the compiler. Clang is designed as an API from its
|
| 60 | inception.</li>
|
| 61 | <li>Various GCC design decisions make it very difficult to reuse: its build
|
| 62 | system is difficult to modify, you can't link multiple targets into one
|
| 63 | binary, you can't link multiple front-ends into one binary, it uses a
|
| 64 | custom garbage collector, uses global variables extensively, is not
|
| 65 | reentrant or multi-threadable, etc. Clang has none of these problems.
|
| 66 | </li>
|
| 67 | <li>GCC does not track information about macro instantiations when parsing
|
| 68 | source code, this makes it very difficult for static analysis and
|
| 69 | refactoring tools to work in the presense of (even simple) macros.</li>
|
| 70 | <li>GCC simplifies code as it parses it. As one simple example, if you
|
| 71 | write "x-x" in your source code, the GCC AST will contain "0", with no
|
| 72 | mention of x. This is extremely bad for a refactoring tool that wants
|
| 73 | to rename 'x' for example.</li>
|
| 74 | <li>GCC does not have a way to serialize the AST of a file out to disk and
|
| 75 | read it back into another program. Its PCH mechanism is architecturally
|
| 76 | only able to read the dump back into the exact same binary.</li>
|
| 77 | <li>GCC is <a href="features.html#performance">very slow and uses a large
|
| 78 | amount of memory</a>.</li>
|
| 79 | <li>The diagnostics produced by GCC are acceptable, but are often confusing
|
| 80 | and it does not support <a
|
| 81 | href="features.html#expressivediags">expressive diagnostics</a>.</li>
|
| 82 | <li>GCC is licensed under the GPL license, which makes it difficult to use
|
| 83 | for projects that do not themselves want to be GPL. clang uses a BSD
|
| 84 | license.</li>
|
| 85 | </ul>
|
| 86 |
|
| 87 | <!--=====================================================================-->
|
| 88 | <h2><a name="elsa">Clang vs Elsa (Elkhound-based C++ Parser)</a></h2>
|
| 89 | <!--=====================================================================-->
|
| 90 |
|
| 91 | <p>Pros of Elsa vs clang:</p>
|
| 92 |
|
| 93 | <ul>
|
| 94 | <li>Elsa's support for C++ is far beyond what clang provides. If you need
|
| 95 | C++ support in the next year, Elsa is a great way to get it. That said,
|
| 96 | Elsa is missing important support for templates and other pieces: for
|
| 97 | example, it is not capable of compiling the GCC STL headers from any
|
| 98 | version newer than GCC 3.4.</li>
|
| 99 | <li>Elsa's parser and AST is designed to be easily composable by adding
|
| 100 | grammar rules. Clang has a very simple and easily extensible parser,
|
| 101 | but requires you to write C++ code to extend it.</li>
|
| 102 | </ul>
|
| 103 |
|
| 104 | <p>Cons of Elsa vs clang:</p>
|
| 105 |
|
| 106 | <ul>
|
| 107 | <li>The Elsa community is extremely small and major development work seems
|
| 108 | to have ceased in 2005, though it continues to be used by other projects
|
| 109 | (e.g. Oink). Clang has a vibrant community including developers that
|
| 110 | are paid to work on it full time.</li>
|
| 111 | <li>Elsa is not built as a stack of reusable libraries like clang is. It is
|
| 112 | very difficult to use part of elsa without the whole front-end. For
|
| 113 | example, you cannot use Elsa to parse C/ObjC code without building an
|
| 114 | AST. You can do this in Clang and it is much faster than building an
|
| 115 | AST.</li>
|
| 116 | <li>Elsa does not have an integrated preprocessor, which makes it extremely
|
| 117 | difficult to accurately map from a source location in the AST back to
|
| 118 | its original position before preprocessing. Likewise, it does not keep
|
| 119 | track of macro expansions.</li>
|
| 120 | <li>Elsa is slower and uses more memory than GCC, which requires far more
|
| 121 | space and time than clang.</li>
|
| 122 | <li>Elsa only does partial semantic analysis. It is intended to work on
|
| 123 | code that is already validated by GCC, so it does not do many semantic
|
| 124 | checks required by the languages it implements.</li>
|
| 125 | <li>Elsa does not support Objective-C.</li>
|
| 126 | <li>Elsa does not support native code generation.</li>
|
| 127 | </ul>
|
| 128 |
|
| 129 |
|
| 130 | <!--=====================================================================-->
|
| 131 | <h2><a name="pcc">Clang vs PCC (Portable C Compiler)</a></h2>
|
| 132 | <!--=====================================================================-->
|
| 133 |
|
| 134 | <p>Pros of PCC vs clang:</p>
|
| 135 |
|
| 136 | <ul>
|
| 137 | <li>The PCC source base is very small and builds quickly with just a C
|
| 138 | compiler.</li>
|
| 139 | </ul>
|
| 140 |
|
| 141 | <p>Cons of PCC vs clang:</p>
|
| 142 |
|
| 143 | <ul>
|
| 144 | <li>PCC dates from the 1970's and has been dormant for most of that time.
|
| 145 | The clang + llvm community are very active.</li>
|
| 146 | <li>PCC doesn't support Objective-C and doesn't aim to support C++.</li>
|
| 147 | <li>PCC's code generation is very limited compared to LLVM, it produces very
|
| 148 | inefficient code and does not support many important targets.</li>
|
| 149 | <li>PCC's does not have an integrated preprocessor, so it is extremely
|
| 150 | difficult to use it for source analysis tools.</li>
|
| 151 | </div>
|
| 152 | </body>
|
| 153 | </html>
|