Home | History | Annotate | Download | only in www
      1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
      2           "http://www.w3.org/TR/html4/strict.dtd">
      3 <!-- Material used from: HTML 4.01 specs: http://www.w3.org/TR/html401/ -->
      4 <html>
      5 <head>
      6   <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      7   <title>Comparing clang to other open source 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 Open Source 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 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>
     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 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>
     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     
     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     
     44     <!--=====================================================================-->
     45     <h2><a name="gcc">Clang vs GCC (GNU Compiler Collection)</a></h2>
     46     <!--=====================================================================-->
     47     
     48     <p>Pro's of GCC vs clang:</p>
     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 supports more targets than LLVM.</li>
     54     <li>GCC is popular and widely adopted.</li>
     55     <li>GCC does not require a C++ compiler to build it.</li>
     56     </ul>
     57     
     58     <p>Pro's of clang vs GCC:</p>
     59     
     60     <ul>
     61     <li>The Clang ASTs and design are intended to be <a 
     62         href="features.html#simplecode">easily understandable</a> by
     63         anyone who is familiar with the languages involved and who has a basic
     64         understanding of how a compiler works.  GCC has a very old codebase
     65         which presents a steep learning curve to new developers.</li>
     66     <li>Clang is designed as an API from its inception, allowing it to be reused
     67         by source analysis tools, refactoring, IDEs (etc) as well as for code
     68         generation.  GCC is built as a monolithic static compiler, which makes
     69         it extremely difficult to use as an API and integrate into other tools.
     70         Further, its historic design and <a 
     71         href="http://gcc.gnu.org/ml/gcc/2007-11/msg00460.html">current</a>
     72         <a href="http://gcc.gnu.org/ml/gcc/2004-12/msg00888.html">policy</a> 
     73         makes it difficult to decouple the front-end from the rest of the
     74         compiler. </li>
     75     <li>Various GCC design decisions make it very difficult to reuse: its build
     76         system is difficult to modify, you can't link multiple targets into one
     77         binary, you can't link multiple front-ends into one binary, it uses a
     78         custom garbage collector, uses global variables extensively, is not
     79         reentrant or multi-threadable, etc.  Clang has none of these problems.
     80         </li>
     81     <li>For every token, clang tracks information about where it was written and
     82         where it was ultimately expanded into if it was involved in a macro.
     83         GCC does not track information about macro instantiations when parsing
     84         source code.  This makes it very difficult for source rewriting tools
     85         (e.g. for refactoring) to work in the presence of (even simple) 
     86         macros.</li>
     87     <li>Clang does not implicitly simplify code as it parses it like GCC does.
     88         Doing so causes many problems for source analysis tools: as one simple
     89         example, if you write "x-x" in your source code, the GCC AST will
     90         contain "0", with no mention of 'x'.  This is extremely bad for a
     91         refactoring tool that wants to rename 'x'.</li>
     92     <li>Clang can serialize its AST out to disk and read it back into another 
     93         program, which is useful for whole program analysis.  GCC does not have
     94         this.  GCC's PCH mechanism (which is just a dump of the compiler 
     95         memory image) is related, but is architecturally only 
     96         able to read the dump back into the exact same executable as the one 
     97         that produced it (it is not a structured format).</li>
     98     <li>Clang is <a href="features.html#performance">much faster and uses far
     99         less memory</a> than GCC.</li>
    100     <li>Clang aims to provide extremely clear and concise diagnostics (error and
    101         warning messages), and includes support for <a
    102         href="diagnostics.html">expressive diagnostics</a>.  GCC's warnings are 
    103         sometimes acceptable, but are often confusing and it does not support
    104         expressive diagnostics.  Clang also preserves typedefs in diagnostics
    105         consistently, showing macro expansions and many other features.</li>
    106     <li>GCC is licensed under the GPL license. <a href="features.html#license">
    107         clang uses a BSD license,</a> which allows it to be embedded in
    108         software that is not GPL-licensed.</li>
    109     <li>Clang inherits a number of features from its use of LLVM as a backend,
    110         including support for a bytecode representation for intermediate code,
    111         pluggable optimizers, link-time optimization support, Just-In-Time
    112         compilation, ability to link in multiple code generators, etc.</li>
    113     <li><a href="compatibility.html#c++">Clang's support for C++</a> is more
    114         compliant than GCC's in many ways (e.g. conformant two phase name
    115         lookup).</li>
    116     </ul>
    117 
    118     <!--=====================================================================-->
    119     <h2><a name="elsa">Clang vs Elsa (Elkhound-based C++ Parser)</a></h2>
    120     <!--=====================================================================-->
    121     
    122     <p>Pro's of Elsa vs clang:</p>
    123     
    124     <ul>
    125     <li>Elsa's parser and AST is designed to be easily extensible by adding
    126         grammar rules.  Clang has a very simple and easily hackable parser,
    127         but requires you to write C++ code to do it.</li>
    128     </ul>
    129     
    130     <p>Pro's of clang vs Elsa:</p>
    131     
    132     <ul>
    133     <li>Clang's C and C++ support is far more mature and practically useful than
    134         Elsa's, and includes many C++'11 features.</li>
    135     <li>The Elsa community is extremely small and major development work seems
    136         to have ceased in 2005. Work continued to be used by other small 
    137         projects (e.g. Oink), but Oink is apparently dead now too.  Clang has a
    138         vibrant community including developers that
    139         are paid to work on it full time.  In practice this means that you can
    140         file bugs against Clang and they will often be fixed for you.  If you
    141         use Elsa, you are (mostly) on your own for bug fixes and feature
    142         enhancements.</li>
    143     <li>Elsa is not built as a stack of reusable libraries like clang is.  It is
    144         very difficult to use part of Elsa without the whole front-end.  For
    145         example, you cannot use Elsa to parse C/ObjC code without building an
    146         AST.  You can do this in Clang and it is much faster than building an
    147         AST.</li>
    148     <li>Elsa does not have an integrated preprocessor, which makes it extremely
    149         difficult to accurately map from a source location in the AST back to
    150         its original position before preprocessing.  Like GCC, it does not keep
    151         track of macro expansions.</li>
    152     <li>Elsa is even slower and uses more memory than GCC, which itself requires 
    153         far more space and time than clang.</li>
    154     <li>Elsa only does partial semantic analysis.  It is intended to work on
    155         code that is already validated by GCC, so it does not do many semantic
    156         checks required by the languages it implements.</li>
    157     <li>Elsa does not support Objective-C.</li>
    158     <li>Elsa does not support native code generation.</li>
    159     </ul>
    160     
    161     
    162     <!--=====================================================================-->
    163     <h2><a name="pcc">Clang vs PCC (Portable C Compiler)</a></h2>
    164     <!--=====================================================================-->
    165     
    166     <p>Pro's of PCC vs clang:</p>
    167     
    168     <ul>
    169     <li>The PCC source base is very small and builds quickly with just a C
    170         compiler.</li>
    171     </ul>
    172     
    173     <p>Pro's of clang vs PCC:</p>
    174     
    175     <ul>
    176     <li>PCC dates from the 1970's and has been dormant for most of that time.
    177         The clang + llvm communities are very active.</li>
    178     <li>PCC doesn't support Objective-C or C++ and doesn't aim to support
    179         C++.</li>
    180     <li>PCC's code generation is very limited compared to LLVM.  It produces very
    181         inefficient code and does not support many important targets.</li>
    182     <li>Like Elsa, PCC's does not have an integrated preprocessor, making it
    183         extremely difficult to use it for source analysis tools.</li>
    184     </ul>
    185   </div>
    186 </body>
    187 </html>
    188