xref: /minix3/external/bsd/llvm/dist/clang/www/comparison.html (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2f4a2713aSLionel Sambuc          "http://www.w3.org/TR/html4/strict.dtd">
3f4a2713aSLionel Sambuc<!-- Material used from: HTML 4.01 specs: http://www.w3.org/TR/html401/ -->
4f4a2713aSLionel Sambuc<html>
5f4a2713aSLionel Sambuc<head>
6f4a2713aSLionel Sambuc  <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7f4a2713aSLionel Sambuc  <title>Comparing clang to other open source compilers</title>
8f4a2713aSLionel Sambuc  <link type="text/css" rel="stylesheet" href="menu.css">
9f4a2713aSLionel Sambuc  <link type="text/css" rel="stylesheet" href="content.css">
10f4a2713aSLionel Sambuc</head>
11f4a2713aSLionel Sambuc<body>
12f4a2713aSLionel Sambuc  <!--#include virtual="menu.html.incl"-->
13f4a2713aSLionel Sambuc  <div id="content">
14f4a2713aSLionel Sambuc    <h1>Clang vs Other Open Source Compilers</h1>
15f4a2713aSLionel Sambuc
16f4a2713aSLionel Sambuc    <p>Building an entirely new compiler front-end is a big task, and it isn't
17f4a2713aSLionel Sambuc       always clear to people why we decided to do this.  Here we compare clang
18f4a2713aSLionel Sambuc       and its goals to other open source compiler front-ends that are
19f4a2713aSLionel Sambuc       available.  We restrict the discussion to very specific objective points
20f4a2713aSLionel Sambuc       to avoid controversy where possible.  Also, software is infinitely
21f4a2713aSLionel Sambuc       mutable, so we don't talk about little details that can be fixed with
22f4a2713aSLionel Sambuc       a reasonable amount of effort: we'll talk about issues that are
23f4a2713aSLionel Sambuc       difficult to fix for architectural or political reasons.</p>
24f4a2713aSLionel Sambuc
25f4a2713aSLionel Sambuc    <p>The goal of this list is to describe how differences in goals lead to
26f4a2713aSLionel Sambuc       different strengths and weaknesses, not to make some compiler look bad.
27f4a2713aSLionel Sambuc       This will hopefully help you to evaluate whether using clang is a good
28f4a2713aSLionel Sambuc       idea for your personal goals.  Because we don't know specifically what
29f4a2713aSLionel Sambuc       <em>you</em> want to do, we describe the features of these compilers in
30f4a2713aSLionel Sambuc       terms of <em>our</em> goals: if you are only interested in static
31f4a2713aSLionel Sambuc       analysis, you may not care that something lacks codegen support, for
32f4a2713aSLionel Sambuc       example.</p>
33f4a2713aSLionel Sambuc
34*0a6a1f1dSLionel Sambuc    <p>Please email <a href="get_involved.html">cfe-dev</a> if you think we should add another compiler to this
35f4a2713aSLionel Sambuc       list or if you think some characterization is unfair here.</p>
36f4a2713aSLionel Sambuc
37f4a2713aSLionel Sambuc    <ul>
38f4a2713aSLionel Sambuc    <li><a href="#gcc">Clang vs GCC</a> (GNU Compiler Collection)</li>
39f4a2713aSLionel Sambuc    <li><a href="#elsa">Clang vs Elsa</a> (Elkhound-based C++ Parser)</li>
40f4a2713aSLionel Sambuc    <li><a href="#pcc">Clang vs PCC</a> (Portable C Compiler)</li>
41f4a2713aSLionel Sambuc    </ul>
42f4a2713aSLionel Sambuc
43f4a2713aSLionel Sambuc
44f4a2713aSLionel Sambuc    <!--=====================================================================-->
45f4a2713aSLionel Sambuc    <h2><a name="gcc">Clang vs GCC (GNU Compiler Collection)</a></h2>
46f4a2713aSLionel Sambuc    <!--=====================================================================-->
47f4a2713aSLionel Sambuc
48f4a2713aSLionel Sambuc    <p>Pro's of GCC vs clang:</p>
49f4a2713aSLionel Sambuc
50f4a2713aSLionel Sambuc    <ul>
51f4a2713aSLionel Sambuc    <li>GCC supports languages that clang does not aim to, such as Java, Ada,
52*0a6a1f1dSLionel Sambuc        FORTRAN, Go, etc.</li>
53f4a2713aSLionel Sambuc    <li>GCC supports more targets than LLVM.</li>
54*0a6a1f1dSLionel Sambuc    <li>GCC supports many language extensions, some of which are not implemented
55*0a6a1f1dSLionel Sambuc    by Clang. For instance, in C mode, GCC supports
56*0a6a1f1dSLionel Sambuc    <a href="http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html">nested
57*0a6a1f1dSLionel Sambuc    functions</a> and has an
58*0a6a1f1dSLionel Sambuc    <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37428">undocumented
59*0a6a1f1dSLionel Sambuc    extension allowing VLAs in structs</a>.
60f4a2713aSLionel Sambuc    </ul>
61f4a2713aSLionel Sambuc
62f4a2713aSLionel Sambuc    <p>Pro's of clang vs GCC:</p>
63f4a2713aSLionel Sambuc
64f4a2713aSLionel Sambuc    <ul>
65f4a2713aSLionel Sambuc    <li>The Clang ASTs and design are intended to be <a
66f4a2713aSLionel Sambuc        href="features.html#simplecode">easily understandable</a> by
67f4a2713aSLionel Sambuc        anyone who is familiar with the languages involved and who has a basic
68f4a2713aSLionel Sambuc        understanding of how a compiler works.  GCC has a very old codebase
69f4a2713aSLionel Sambuc        which presents a steep learning curve to new developers.</li>
70f4a2713aSLionel Sambuc    <li>Clang is designed as an API from its inception, allowing it to be reused
71f4a2713aSLionel Sambuc        by source analysis tools, refactoring, IDEs (etc) as well as for code
72f4a2713aSLionel Sambuc        generation.  GCC is built as a monolithic static compiler, which makes
73f4a2713aSLionel Sambuc        it extremely difficult to use as an API and integrate into other tools.
74f4a2713aSLionel Sambuc        Further, its historic design and <a
75f4a2713aSLionel Sambuc        href="http://gcc.gnu.org/ml/gcc/2007-11/msg00460.html">current</a>
76f4a2713aSLionel Sambuc        <a href="http://gcc.gnu.org/ml/gcc/2004-12/msg00888.html">policy</a>
77f4a2713aSLionel Sambuc        makes it difficult to decouple the front-end from the rest of the
78f4a2713aSLionel Sambuc        compiler. </li>
79f4a2713aSLionel Sambuc    <li>Various GCC design decisions make it very difficult to reuse: its build
80f4a2713aSLionel Sambuc        system is difficult to modify, you can't link multiple targets into one
81f4a2713aSLionel Sambuc        binary, you can't link multiple front-ends into one binary, it uses a
82f4a2713aSLionel Sambuc        custom garbage collector, uses global variables extensively, is not
83f4a2713aSLionel Sambuc        reentrant or multi-threadable, etc.  Clang has none of these problems.
84f4a2713aSLionel Sambuc        </li>
85f4a2713aSLionel Sambuc    <li>Clang does not implicitly simplify code as it parses it like GCC does.
86f4a2713aSLionel Sambuc        Doing so causes many problems for source analysis tools: as one simple
87f4a2713aSLionel Sambuc        example, if you write "x-x" in your source code, the GCC AST will
88f4a2713aSLionel Sambuc        contain "0", with no mention of 'x'.  This is extremely bad for a
89f4a2713aSLionel Sambuc        refactoring tool that wants to rename 'x'.</li>
90f4a2713aSLionel Sambuc    <li>Clang can serialize its AST out to disk and read it back into another
91f4a2713aSLionel Sambuc        program, which is useful for whole program analysis.  GCC does not have
92f4a2713aSLionel Sambuc        this.  GCC's PCH mechanism (which is just a dump of the compiler
93f4a2713aSLionel Sambuc        memory image) is related, but is architecturally only
94f4a2713aSLionel Sambuc        able to read the dump back into the exact same executable as the one
95f4a2713aSLionel Sambuc        that produced it (it is not a structured format).</li>
96f4a2713aSLionel Sambuc    <li>Clang is <a href="features.html#performance">much faster and uses far
97f4a2713aSLionel Sambuc        less memory</a> than GCC.</li>
98f4a2713aSLionel Sambuc    <li>Clang aims to provide extremely clear and concise diagnostics (error and
99f4a2713aSLionel Sambuc        warning messages), and includes support for <a
100f4a2713aSLionel Sambuc        href="diagnostics.html">expressive diagnostics</a>.  GCC's warnings are
101f4a2713aSLionel Sambuc        sometimes acceptable, but are often confusing and it does not support
102f4a2713aSLionel Sambuc        expressive diagnostics.  Clang also preserves typedefs in diagnostics
103f4a2713aSLionel Sambuc        consistently, showing macro expansions and many other features.</li>
104f4a2713aSLionel Sambuc    <li>GCC is licensed under the GPL license. <a href="features.html#license">
105f4a2713aSLionel Sambuc        clang uses a BSD license,</a> which allows it to be embedded in
106f4a2713aSLionel Sambuc        software that is not GPL-licensed.</li>
107f4a2713aSLionel Sambuc    <li>Clang inherits a number of features from its use of LLVM as a backend,
108f4a2713aSLionel Sambuc        including support for a bytecode representation for intermediate code,
109f4a2713aSLionel Sambuc        pluggable optimizers, link-time optimization support, Just-In-Time
110f4a2713aSLionel Sambuc        compilation, ability to link in multiple code generators, etc.</li>
111*0a6a1f1dSLionel Sambuc    <li><a href="compatibility.html#cxx">Clang's support for C++</a> is more
112*0a6a1f1dSLionel Sambuc        compliant than GCC's in many ways.</li>
113*0a6a1f1dSLionel Sambuc    <li>Clang supports
114*0a6a1f1dSLionel Sambuc        <a href="http://clang.llvm.org/docs/LanguageExtensions.html">many language
115*0a6a1f1dSLionel Sambuc        extensions</a>, some of which are not implemented by GCC. For instance,
116*0a6a1f1dSLionel Sambuc        Clang provides attributes for checking thread safety and extended vector
117*0a6a1f1dSLionel Sambuc        types.</li>
118f4a2713aSLionel Sambuc    </ul>
119f4a2713aSLionel Sambuc
120f4a2713aSLionel Sambuc    <!--=====================================================================-->
121f4a2713aSLionel Sambuc    <h2><a name="elsa">Clang vs Elsa (Elkhound-based C++ Parser)</a></h2>
122f4a2713aSLionel Sambuc    <!--=====================================================================-->
123f4a2713aSLionel Sambuc
124f4a2713aSLionel Sambuc    <p>Pro's of Elsa vs clang:</p>
125f4a2713aSLionel Sambuc
126f4a2713aSLionel Sambuc    <ul>
127f4a2713aSLionel Sambuc    <li>Elsa's parser and AST is designed to be easily extensible by adding
128f4a2713aSLionel Sambuc        grammar rules.  Clang has a very simple and easily hackable parser,
129f4a2713aSLionel Sambuc        but requires you to write C++ code to do it.</li>
130f4a2713aSLionel Sambuc    </ul>
131f4a2713aSLionel Sambuc
132f4a2713aSLionel Sambuc    <p>Pro's of clang vs Elsa:</p>
133f4a2713aSLionel Sambuc
134f4a2713aSLionel Sambuc    <ul>
135f4a2713aSLionel Sambuc    <li>Clang's C and C++ support is far more mature and practically useful than
136f4a2713aSLionel Sambuc        Elsa's, and includes many C++'11 features.</li>
137f4a2713aSLionel Sambuc    <li>The Elsa community is extremely small and major development work seems
138f4a2713aSLionel Sambuc        to have ceased in 2005. Work continued to be used by other small
139f4a2713aSLionel Sambuc        projects (e.g. Oink), but Oink is apparently dead now too.  Clang has a
140f4a2713aSLionel Sambuc        vibrant community including developers that
141f4a2713aSLionel Sambuc        are paid to work on it full time.  In practice this means that you can
142f4a2713aSLionel Sambuc        file bugs against Clang and they will often be fixed for you.  If you
143f4a2713aSLionel Sambuc        use Elsa, you are (mostly) on your own for bug fixes and feature
144f4a2713aSLionel Sambuc        enhancements.</li>
145f4a2713aSLionel Sambuc    <li>Elsa is not built as a stack of reusable libraries like clang is.  It is
146f4a2713aSLionel Sambuc        very difficult to use part of Elsa without the whole front-end.  For
147f4a2713aSLionel Sambuc        example, you cannot use Elsa to parse C/ObjC code without building an
148f4a2713aSLionel Sambuc        AST.  You can do this in Clang and it is much faster than building an
149f4a2713aSLionel Sambuc        AST.</li>
150f4a2713aSLionel Sambuc    <li>Elsa does not have an integrated preprocessor, which makes it extremely
151f4a2713aSLionel Sambuc        difficult to accurately map from a source location in the AST back to
152f4a2713aSLionel Sambuc        its original position before preprocessing.  Like GCC, it does not keep
153f4a2713aSLionel Sambuc        track of macro expansions.</li>
154f4a2713aSLionel Sambuc    <li>Elsa is even slower and uses more memory than GCC, which itself requires
155f4a2713aSLionel Sambuc        far more space and time than clang.</li>
156f4a2713aSLionel Sambuc    <li>Elsa only does partial semantic analysis.  It is intended to work on
157f4a2713aSLionel Sambuc        code that is already validated by GCC, so it does not do many semantic
158f4a2713aSLionel Sambuc        checks required by the languages it implements.</li>
159f4a2713aSLionel Sambuc    <li>Elsa does not support Objective-C.</li>
160f4a2713aSLionel Sambuc    <li>Elsa does not support native code generation.</li>
161f4a2713aSLionel Sambuc    </ul>
162f4a2713aSLionel Sambuc
163f4a2713aSLionel Sambuc
164f4a2713aSLionel Sambuc    <!--=====================================================================-->
165f4a2713aSLionel Sambuc    <h2><a name="pcc">Clang vs PCC (Portable C Compiler)</a></h2>
166f4a2713aSLionel Sambuc    <!--=====================================================================-->
167f4a2713aSLionel Sambuc
168f4a2713aSLionel Sambuc    <p>Pro's of PCC vs clang:</p>
169f4a2713aSLionel Sambuc
170f4a2713aSLionel Sambuc    <ul>
171f4a2713aSLionel Sambuc    <li>The PCC source base is very small and builds quickly with just a C
172f4a2713aSLionel Sambuc        compiler.</li>
173f4a2713aSLionel Sambuc    </ul>
174f4a2713aSLionel Sambuc
175f4a2713aSLionel Sambuc    <p>Pro's of clang vs PCC:</p>
176f4a2713aSLionel Sambuc
177f4a2713aSLionel Sambuc    <ul>
178f4a2713aSLionel Sambuc    <li>PCC dates from the 1970's and has been dormant for most of that time.
179f4a2713aSLionel Sambuc        The clang + llvm communities are very active.</li>
180f4a2713aSLionel Sambuc    <li>PCC doesn't support Objective-C or C++ and doesn't aim to support
181f4a2713aSLionel Sambuc        C++.</li>
182f4a2713aSLionel Sambuc    <li>PCC's code generation is very limited compared to LLVM.  It produces very
183f4a2713aSLionel Sambuc        inefficient code and does not support many important targets.</li>
184f4a2713aSLionel Sambuc    <li>Like Elsa, PCC's does not have an integrated preprocessor, making it
185f4a2713aSLionel Sambuc        extremely difficult to use it for source analysis tools.</li>
186f4a2713aSLionel Sambuc    </ul>
187f4a2713aSLionel Sambuc  </div>
188f4a2713aSLionel Sambuc</body>
189f4a2713aSLionel Sambuc</html>
190