World Library  
Flag as Inappropriate
Email this Article


Article Id: WHEBN0012407970
Reproduction Date:

Title: Clang  
Author: World Heritage Encyclopedia
Language: English
Subject: Xcode, History of FreeBSD, C11 (C standard revision), ANSI C, OpenCL
Publisher: World Heritage Encyclopedia


Original author(s) Chris Lattner and others
Developer(s) Apple Inc. and others
Stable release 3.5[1] / 4 September 2014 (2014-09-04)
Development status Active
Written in C++
Operating system Unix-like
Platform Cross-platform
Type Compiler
License University of Illinois/NCSA Open Source License[2]
Website .org.llvmclang

Clang [3] is a compiler front end for the C, C++, Objective-C and Objective-C++ programming languages. It uses LLVM as its back end and has been part of the LLVM release cycle since LLVM 2.6.

It is designed to offer a complete replacement to the GNU Compiler Collection (GCC). It is open-source,[4] developed by Apple; other companies such as Google, ARM, Sony and Intel are involved. Its source code is available under the University of Illinois/NCSA License.

The Clang project includes the Clang front end and the Clang static analyzer and several code analysis tools.[5]


Starting in 2005, Apple has made extensive use of LLVM in a number of commercial systems,[6] including the iPhone development kit and Xcode 3.1.

One of the first uses of LLVM was an OpenGL code compiler for Mac OS X that converts OpenGL calls into more fundamental calls for graphics processing units (GPU) that do not support certain features. This allowed Apple to support the entire OpenGL application programming interface (API) on computers using Intel Graphics Media Accelerator (GMA) chipsets, increasing performance on those machines.[7] For sufficiently capable GPUs, the code is compiled to take full advantage of the underlying hardware, but on GMA machines, LLVM compiles the same OpenGL code into subroutines to ensure it continues to work properly.

LLVM was originally intended to use GCC's front end, but GCC turned out to cause some problems for both the LLVM developers and Apple. The GCC source code is a large and somewhat cumbersome system for developers to work with; as one long-time GCC developer put it, "Trying to make the hippo dance is not really a lot of fun".[8]

Apple software makes heavy use of Objective-C, but the Objective-C front-end in GCC is a low priority for the current GCC developers. Also, GCC does not fit smoothly into Apple's IDE.[9] Finally, GCC is GPL version 3 licensed, which requires developers who distribute extensions for (or modified versions of) GCC to make their source code available, whereas LLVM has a BSD-like license[10] which permits including the source into proprietary software.

Apple chose to develop a new compiler front end from scratch, supporting C, Objective-C and C++.[9] This "clang" project was open-sourced in July 2007.[11]


Clang is intended specifically to work on top of LLVM.[10] The combination of Clang and LLVM provides the majority of a toolchain, allowing the replacement of the whole GCC stack. Because it is built with a library-based design, like the rest of LLVM, Clang is easy to embed into other applications. This is one reason why a majority of the OpenCL implementations are built with Clang and LLVM.

One of Clang's primary goals is to better support incremental compilation to allow the compiler to be more tightly tied to the IDE GUI. GCC is designed to work in a "classic" compile-link-debug cycle, and although it provides useful ways to support incremental and interrupted compiling on-the-fly, integrating them with other tools is not always easy. For instance, GCC uses a step called "fold" that is key to the overall compile process, which has the side effect of translating the code tree into a form that does not look very much like the original source code. If an error is found during or after the fold step, it can be difficult to translate that back into a single location in the original source. Additionally, vendors using the GCC stack within IDEs used separate tools to index the code to provide features like syntax highlighting and autocomplete.

Clang is designed to retain more information during the compilation process than GCC, and preserve the overall form of the original code. The objective of this is to make it easier to map errors back into the original source. The error reports offered by Clang are also aimed to be more detailed and specific, as well as machine-readable, so IDEs can index the output of the compiler during compilation. Modular design of the compiler can offer source code indexing, syntax checking, and other features normally associated with rapid application development systems. The parse tree is also more suitable for supporting automated code refactoring, as it remains in a parsable text form at all times.

Clang is modularized, well documented, and based almost entirely on replaceable link-time libraries — as opposed to source-code modules that are combined at compile time. In some cases the libraries are provided in several versions that can be swapped out at runtime; for instance the parser comes with a version that offers performance measurement of the compile process.

Clang, as the name implies, is a compiler only for C and C-like languages. It does not offer compiler front-ends for languages other than C, C++, Objective-C, and Objective-C++. For other languages, including Java, Fortran, and Ada, LLVM remains dependent on GCC. In many cases, Clang can be used or swapped out for GCC as needed, with no other effects on the toolchain as a whole. It supports most of the commonly used GCC options.

Performance and GCC compatibility

Clang is designed to be highly compatible with GCC.[12] Clang's command-line interface is similar to and shares many flags and options with GCC. Clang implements many GNU language extensions and enables them by default. Clang implements many GCC compiler intrinsics purely for compatibility. For example, even though Clang implements atomic intrinsics which correspond exactly with C11 atomics, it also implements GCC's __sync_* intrinsics for compatibility with GCC and libstdc++. Clang also maintains ABI compatibility with GCC-generated object code. In practice Clang can often be used as a drop-in replacement for GCC.

Clang's developers claim that it provides reduced memory footprint and increased compilation speed compared to competing compilers, such as GCC. To support their claim, they present that, as of October 2007, Clang compiled the Carbon libraries well over twice as fast as GCC, while using about one-sixth GCC's memory and disk space.[13] It has been independently verified that Clang's compilation speed is typically better than GCC's.[14]

The runtime performance of Clang/LLVM output was reported to be worse than GCC's,[14][15] but as of the middle of 2014, runtime performance has improved to the point where Clang wins more than a third of the benchmarks, with GCC winning a majority.[16] While there are still a few tests where performance of Clang-compiled program lags behind performance of the GCC-compiled program by large factors (up to 5.5x),[16] it has been reported that Clang "continues to be under very active development" and a hope was expressed for further improvement.[14]

Status history

This table presents only significant steps and releases in Clang history.
Date Highlights
11 July 2007 Clang frontend released under an open-source license
25 February 2009 Clang/LLVM able to compile a working FreeBSD kernel.[17][18]
16 March 2009 Clang/LLVM able to compile a working DragonFly BSD kernel.[19][20]
23 October 2009 Clang 1.0 released along with LLVM 2.6 for the first time.
December 2009 Code generation for C and Objective-C reach production quality (support for C++ and Objective-C++ still incomplete). Clang C++ able to parse GCC 4.2 libstdc++ and generate working code for non-trivial programs[10] and was able to compile itself[21]
2 February 2010 Clang self-hosting.[22]
20 February 2010 The source code of HelenOS was modified to successfully compile with Clang, and passed all kernel and user space regression tests on IA-32.[23]
20 May 2010 The latest version of Clang successfully built the Boost C++ libraries, and passed nearly all tests.[24]
10 June 2010 Clang/LLVM became an integral part of FreeBSD (The default compiler is still GCC)[25]
25 October 2010 Clang/LLVM able to compile a working modified Linux Kernel.[26]
January 2011 Preliminary work completed to support the draft C++0x standard, with a few of the draft's new features supported in the development version of Clang.[27][28]
10 February 2011 Clang able to compile a working HotSpot Java Virtual Machine[14]
19 January 2012 Clang becomes an optional component in NetBSD's cross-platform build system (GCC is still default)[29]
28 February 2012 Clang 3.0 able to rebuild more than 91% of the Debian archive[30]
29 February 2012 Clang becomes the default compiler in MINIX 3[31]
12 May 2012 Clang/LLVM is announced to replace GCC in FreeBSD[32]
5 November 2012 Clang becomes the default compiler in FreeBSD 10.x[33]
18 February 2013 Clang/LLVM able to compile a working modified Android Linux Kernel for Nexus 7.[34][35]
19 April 2013 Clang is C++11 feature complete.[36]
6 November 2013 Clang is C++14 feature complete.[37]

See also


  1. ^
  2. ^ LLVM License, retrieved 2014-07-24 
  3. ^ Christopher, Eric (3 July 2008). "simply wonder pronunciation of Clang". LLVMdev mailing list. Retrieved 9 July 2008.
  4. ^ Clang "Getting started" instructions,, retrieved 2012-09-18 
  5. ^ "Clang Static Analyzer". LLVM. Retrieved 3 September 2009. 
  6. ^ Treat, Adam (19 February 2005). "mkspecs and patches for LLVM compile of Qt4". Qt4-preview-feedback mailing list.
  7. ^ Lattner, Chris (25 May 2007). "LLVM for OpenGL and other stuff" (Slides). LLVM Developers' Meeting. 
  8. ^ Zadeck, Kenneth (19 November 2005). "Re: LLVM/GCC Integration Proposal". GCC development mailing list.
  9. ^ a b Naroff, Steve (25 May 2007). "New LLVM C Front-end" (Slides). LLVM Developers' Meeting. 
  10. ^ a b c Clang team, clang: a C language family frontend for LLVM
  11. ^ Lattner, Chris (11 July 2007). "New LLVM C front-end: "clang"". cfe-dev mailing list.
  12. ^ Clang - Features and Goals: GCC Compatibility, 15 April 2013 
  13. ^ Clang - Features and Goals: Fast compiles and Low Memory Use, October 2007 
  14. ^ a b c d Simonis, Volker (10 February 2011). "Compiling the HotSpot VM with Clang". Retrieved 13 February 2011. While the overall GCC compatibility is excellent and the compile times are impressive, the performance of the generated code is still lacking behind a recent GCC version.  
  15. ^ "Benchmarking LLVM & Clang Against GCC 4.5".  
  16. ^ a b "GCC 4.9 VS. LLVM CLANG 3.5 LINUX COMPILER BENCHMARKS". 14 April 2014. Retrieved 25 June 2014. 
  17. ^ Divacky, Roman. "[ANNOUNCE] clang/llvm can compile booting FreeBSD kernel on i386/amd64". 
  18. ^ Building FreeBSD with Clang,, 2012-08-24, retrieved 2012-09-18 
  19. ^ Hornung, Alex. "llvm/clang once more". 
  20. ^ Clang, DragonFlyBSD, retrieved 2012-09-18 
  21. ^ "Clang can compile LLVM and Clang". LLVM Project Blog. 
  22. ^ "Clang Successfully Self-Hosts". LLVM Project Blog. 
  23. ^ "HelenOS mainline changeset head,294". 
  24. ^ Gregor, Doug. "Clang++ Builds Boost!". LLVM Project Blog. 
  25. ^ Davis, Brad. "FreeBSD Status Reports April - June, 2010". 
  26. ^ Clang builds a working Linux Kernel (Boots to RL5 with SMP, networking and X, self hosts),, retrieved 2012-09-18 
  27. ^ Gregor, Douglas (26 January 2011). "New C++0x feature support in Clang". Retrieved 29 January 2011.
  28. ^ "C++ and C++'0x Support in Clang". LLVM. 
  29. ^ Sonnenberger, Jörg (2012-01-19). "Status of NetBSD and LLVM". Retrieved 2014-02-26. 
  30. ^ Ledru, Sylvestre. "Rebuild of the Debian archive with clang". 
  31. ^ "Official Minix 3 website: News". 
  32. ^ Gerzo, Daniel (12 May 2012). "FreeBSD Quarterly Status Report January-March, 2012". Retrieved 14 May 2012.
  33. ^ Davis, Brooks (5 November 2012). "HEADS UP: Clang now the default on x86". Retrieved 7 November 2012.
  34. ^ Webster, Behan (18 February 2013). "LLVMLinux: Compiling Android with LLVM". Retrieved 11 May 2013. 
  35. ^ Tinti, Vinicius (17 March 2013). "LLVMLinux: Nexus 7". Retrieved 11 May 2013. 
  36. ^ Du Toit, Stefanus. "Clang is C++11 feature complete as of *just now*!". 
  37. ^ "[llvm-project] Revision 194194". 

External links

  • Official website
  • LLVMdev: New LLVM C front-end: "clang", announcement (11 July 2007)
  • Presentation: Ted Kremenek - Finding Bugs with the Clang Static Analyzer, Slides
    • Clang Static Analyzer list of checkers
  • Presentation: Steve Naroff - Clang Internals, Slides
  • 2009 DevMtg Clang presentation
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.