Features of Clang
This page outlines the main goals of Clang, as well as some compelling reasons why you should consider using Clang. In the "Goals" section below, you will find a brief, bulletted overview of the goals and features that we are striving for in the development of Clang. However, in the "Key Features" section you will find a more detailed presentation on what we believe are some key drawing points for the LLVM front-end. If you are new to Clang and the LLVM front-end, and you want a reason for considering working on or using the new front-end, then make sure you check out the "Key Features" section.Goals
- Unified parser for C-based languagesWe are only focusing on the C languages (C,C++,ObjC); however, if someone wants to work on another language, they are free to take charge of such a project.
- Language conformance with C99, ObjC, C++
- Real-world, production quality compiler
- GCC compatibility
- Library based architecture with finely crafted C++ APIs
Makes Clang easier to work with and more flexible.(more details on this in the "Key Features" section)
- Easy to extend
(because of the library based architecture)
- Multipurpose
Can be used for: Indexing, static analysis, code generation Source to source tools, refactoring(because of library based architecture)
- High performance
Faster than GCC (parse time), Low memory footprint, lazy evaluation(more details in the "Key Features" section)
- Better integration with IDEs
(more details in the "Key Features" section)
- Expressive diagnostics
Error reporting and diagnostic messages are more detailed an accurate than GCC.(more details in the "Key Features" section)
- BSD License
Fewer restrictions on developers; allows for use in commercial products.
Key Features
There are several key features which we believe will make Clang a compelling alternative. These features are designed to make things easier for both the compiler developer (people working on Clang and derivative products) and the application developer (those who use Clang/LLVM).Library based architecture
A major design concept for the LLVM front-end involves using a library based architecture. In this library based architecture, various parts of the front-end can be cleanly divided into separate libraries which can then be mixed up for different needs and uses. In addition, the library based approach makes it much easier for new developers to get involved and extend LLVM to do new and unique things. In the words of Chris,"The world needs better compiler tools, tools which are built as libraries. This design point allows reuse of the tools in new and novel ways. However, building the tools as libraries isn't enough: they must have clean APIs, be as decoupled from each other as possible, and be easy to modify/extend. This requires clean layering, decent design, and avoiding tying the libraries to a specific use."
Currently, the LLVM front-end is divided into the following libraries:
- libsupport - Basic support library, reused from LLVM.
- libsystem - System abstraction library, reused from LLVM.
- libbasic - Diagnostics, SourceLocations, SourceBuffer abstraction, file system caching for input source files. (depends on above libraries)
- libast - Provides classes to represent the C AST, the C type system, builtin functions, and various helpers for analyzing and manipulating the AST (visitors, pretty printers, etc). (depends on above libraries)
- liblex - C/C++/ObjC lexing and preprocessing, identifier hash table, pragma handling, tokens, and macros. (depends on above libraries)
- libparse - Parsing and local semantic analysis. This library invokes coarse-grained 'Actions' provided by the client to do stuff (e.g. libsema builds ASTs). (depends on above libraries)
- libsema - Provides a set of parser actions to build a standardized AST for programs. AST's are 'streamed' out a top-level declaration at a time, allowing clients to use decl-at-a-time processing, build up entire translation units, or even build 'whole program' ASTs depending on how they use the APIs. (depends on libast and libparse)
- libcodegen - Lower the AST to LLVM IR for optimization & codegen. (depends on libast)
- clang - An example driver, client of the libraries at various levels. (depends on above libraries, and LLVM VMCore)
Speed & Memory
Another major focus of LLVM's frontend is speed (for all libraries). Even at this early stage, the LLVM front-end is quicker than gcc and uses less memory.Memory:

This test was run using Mac OS X's Carbon.h header, which is 12.3MB spread across 558 files!
Although this is one of the worst case scenarios for GCC, it shows how clang's implemenation is significantly more memory efficient.
Notes:
Most of the additional memory used by GCC is due to extra data that is added in, which is not needed by the Clang front-end.
Performance:

Even at this early stage, the C parser for Clang is able to achieve significantly better performance.
Performance:

By moving to distributed compiling using distcc, the performance improvement also becomes noticeable.
Notes:
These are SPEC2006 benchmarks using Distcc.
Expressive Diagnostics
The design of the Clang driver (one of the LLVM front_end libraries) provies more detailed diagnostic information.Clang vs GCC:

There are several things to take note of in this example:
- The error messages from Clang are more detailed.
- Clang shows you exactly where the error is, plus the range it has a problem with.
Notes:The first results are from clang; the second results are from gcc.