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, bulleted 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 Clang front-end.

If you are new to the Clang 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

Key Features

There are several key features which we believe make Clang an exciting front-end. 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 keeping the libraries independent of any specific client."
Currently, the LLVM front-end is divided into the following libraries: As an example of the power of this library based design.... If you wanted to build a preprocessor, you would take the Basic and Lexer libraries. If you want an indexer, you would take the previous two and add the Parser library and some actions for indexing. If you want a refactoring, static analysis, or source-to-source compiler tool, you would then add the AST building and semantic analyzer libraries. In the end, LLVM's library based design will provide developers with many more possibilities.

Speed and Memory

Another major focus of LLVM's frontend is speed (for all libraries). Even at this early stage, the clang 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 large headers are one of the worst case scenarios for GCC, they are very common and it shows how clang's implemenation is significantly more memory efficient.
Performance:
Even at this early stage, the C parser for Clang is able to achieve significantly better performance. Many optimizations are still possible of course.
Performance:
By using very trivial file-system caching, clang can significantly speed up preprocessing-bound applications like distcc. (more details)

Expressive Diagnostics

Clang is designed to efficiently capture range information for expressions and statements, which allows it to emit very detailed diagnostic information when a problem is detected.
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.

Better Integration with IDEs

Another design goal of Clang is to integrate extremely well with IDEs. IDEs often have very different requirements than code generation, often requiring information that a codegen-only frontend can throw away. Clang is specifically designed and built to capture this information.