Jump to content

Clang

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Ef3 (talk | contribs) at 22:06, 30 April 2018 (scope="col" style="position:sticky;top:0;"). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Clang
Original author(s)Chris Lattner and others
Developer(s)Apple Inc. and others
Initial releaseSeptember 26, 2007; 16 years ago (2007-09-26)[1]
Stable release
6.0.0[2] / 8 March 2018; 6 years ago (2018-03-08)
Repository
Written inC++
Operating systemUnix-like
PlatformCross-platform
TypeCompiler
LicenseUniversity of Illinois/NCSA Open Source License[3]
Websiteclang.llvm.org

Clang /ˈklæŋ/[4] is a compiler front end for the programming languages C, C++, Objective-C, Objective-C++, OpenMP,[5] OpenCL, and CUDA. It uses LLVM as its back end and has been part of the LLVM release cycle since LLVM 2.6.

It is designed to act as a drop-in replacement for the GNU Compiler Collection, supporting most of its compilation flags and unofficial language extensions.[6][7] Its contributors include Apple, Microsoft, Google, ARM, Sony, Intel and Advanced Micro Devices (AMD). It is open-source software,[8] with source code released under the University of Illinois/NCSA License, a permissive free software licence.

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

Background

Starting in 2005, Apple made extensive use of LLVM in a number of commercial systems,[10] including the iPhone software development kit (SDK) and integrated development environment (IDE) Xcode 3.1.

One of the first uses of LLVM was an OpenGL code compiler for 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.[11] For GPUs that support it, the code is compiled to exploit fully the underlying hardware, but on GMA machines, LLVM compiles the same OpenGL code into subroutines to ensure continued proper function.

LLVM was intended originally to use GCC's front end, but GCC turned out to cause some problems for developers of LLVM and at 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".[12]

Apple software makes heavy use of Objective-C, but the Objective-C front-end in GCC is a low priority for GCC developers. Also, GCC does not integrate smoothly into Apple's IDE.[13] Finally, GCC is licensed under the GNU General Public License (GPL) version 3, 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[14] which does not require users to release their source code changes when publishing compiled binaries of those changes.

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

Design

Clang is intended to work atop LLVM.[14] The combination of Clang and LLVM provides most of the toolchain, to allow replacing the full 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 most OpenCL implementations are built with Clang and LLVM.[citation needed]

One of Clang's main goals is to provide a library-based architecture,[16] to allow the compiler to be more tightly tied to tools that interact with source code, such as an integrated development environment (IDE) graphical user interface (GUI). In contrast, GCC is designed to work in a classic compile-link-debug cycle, and integrating it 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 looks unlike the original source code. If an error is found during or after the fold step, it can be difficult to translate that back into one location in the original source. Also, vendors using the GCC stack within IDEs use separate tools to index the code, to provide features like syntax highlighting and autocomplete.

Clang is designed to retain more information during the compiling process than GCC, and to preserve the overall form of the original code. The goal 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 compiling. 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 directly represents the original source code.

Clang is a compiler for only C-like languages, including C, C++, Objective-C, Objective-C++, OpenCL, and CUDA. For other languages, like Ada, LLVM remains dependent on GCC or another compiler frontend. In many cases, Clang can be used or swapped out for GCC as needed, with no other effects on the toolchain as a whole.[citation needed] It supports most of the commonly used GCC options. An unofficial sub-project Flang by Nvidia added Fortran support.[17]

Performance and GCC compatibility

Clang is designed to be highly compatible with GCC.[7] 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.[citation needed]

Clang's developers aim to reduce memory footprint and increase compilation speed compared to competing compilers, such as GCC. In October 2007, they report that Clang compiled the Carbon libraries more than twice as fast as GCC, while using about one-sixth GCC's memory and disk space.[18] However, as of 2011 this was not a typical result.[19][20] As of mid-2014, Clang won more than a third of the benchmarks, with GCC winning most.[21] As of 2014, performance of Clang-compiled programs lagged behind performance of the GCC-compiled program, sometimes by large factors (up to 5.5x),[21], replicating earlier reports of slower performance.[19]

More recent comparisons indicate that both compilers have evolved to increase their performance. As of GCC 4.8.1 versus clang 3.3, on a large harness of test files, clang had improved significantly, outperforming GCC by ~ 25%. Test results are code-specific, and optimized C source code can reverse such differences. The two compilers now seem broadly comparable.[22]

Status history

This table presents only significant steps and releases in Clang history.

Date Highlights
11 July 2007 Clang frontend released under open-source licence
25 February 2009 Clang/LLVM can compile a working FreeBSD kernel.[23][24]
16 March 2009 Clang/LLVM can compile a working DragonFly BSD kernel.[25][26]
23 October 2009 Clang 1.0 released, 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++ can parse GCC 4.2 libstdc++ and generate working code for non-trivial programs,[14] and can compile itself.[27]
2 February 2010 Clang self-hosting.[28]
20 February 2010 HelenOS source code is modified to compile with Clang successfully, and passes all kernel and user space regression tests on IA-32 processors.[29]
20 May 2010 Clang latest version built the Boost C++ libraries successfully, and passed nearly all tests.[30]
10 June 2010 Clang/LLVM becomes integral part of FreeBSD, but default compiler is still GCC.[31]
25 October 2010 Clang/LLVM can compile a working modified Linux kernel.[32]
January 2011 Preliminary work completed to support the draft C++0x standard, with a few of the draft's new features supported in Clang development version.[33][34]
10 February 2011 Clang can compile a working HotSpot Java virtual machine.[19]
19 January 2012 Clang becomes an optional component in NetBSD cross-platform build system, but GCC is still default.[35]
29 February 2012 Clang 3.0 can rebuild 91.2% of the Debian archive.[36]
29 February 2012 Clang becomes default compiler in MINIX 3[37]
12 May 2012 Clang/LLVM announced to replace GCC in FreeBSD.[38]
5 November 2012 Clang becomes default compiler in FreeBSD 10.x.[39]
18 February 2013 Clang/LLVM can compile a working modified Android Linux Kernel for Nexus 7.[40][41]
19 April 2013 Clang is C++11 feature complete.[42]
6 November 2013 Clang is C++14 feature complete.[43]
11 September 2014 Clang 3.5 can rebuild 94.3% of the Debian archive. The percentage of failures has dropped by 1.2% per release since January 2013, mainly due to increased compatibility with GCC flags.[44]
October 2016 Clang becomes default compiler for Android[45] (and later only compiler supported by Android

[46] ).

13 March 2017 Clang 4.0.0 released
26 July 2017 Clang becomes default compiler in OpenBSD 6.2.[47]
7 September 2017 Clang 5.0.0 released
5 March 2018 Clang is now used to build Chrome for Windows.[48] Mozilla has similar plans for Firefox.[49]
8 March 2018 Clang 6.0.0 released

See also

References

  1. ^ https://www.llvm.org/releases/2.1/docs/ReleaseNotes.html
  2. ^ https://llvm.org/releases/
  3. ^ LLVM License, retrieved 24 July 2014
  4. ^ Christopher, Eric (3 July 2008). "simply wonder pronunciation of Clang". LLVMdev (Mailing list). Retrieved 22 September 2015. {{cite mailing list}}: Unknown parameter |mailinglist= ignored (|mailing-list= suggested) (help)
  5. ^ "OpenMP Support". LLVM Project Blog. Retrieved 28 March 2016.
  6. ^ "Clang Language Extensions". Retrieved 8 November 2017. In addition to the language extensions listed here, Clang aims to support a broad range of GCC extensions.
  7. ^ a b Clang - Features and Goals: GCC Compatibility, 15 April 2013
  8. ^ Clang "Getting started" instructions, Clang.llvm.org, retrieved 18 September 2012
  9. ^ "Clang Static Analyzer". LLVM. Retrieved 3 September 2009.
  10. ^ Treat, Adam (19 February 2005). "mkspecs and patches for LLVM compile of Qt4". Qt4-preview-feedback (Mailing list). Archived from the original on 4 October 2011. {{cite mailing list}}: Unknown parameter |deadurl= ignored (|url-status= suggested) (help); Unknown parameter |mailinglist= ignored (|mailing-list= suggested) (help)
  11. ^ Lattner, Chris (25 May 2007). LLVM for OpenGL and other stuff (Slides). LLVM Developers' Meeting. {{cite conference}}: External link in |conferenceurl= (help); Unknown parameter |conferenceurl= ignored (|conference-url= suggested) (help)
  12. ^ Zadeck, Kenneth (19 November 2005). "Re: LLVM/GCC Integration Proposal". GCC development (Mailing list). {{cite mailing list}}: Unknown parameter |mailinglist= ignored (|mailing-list= suggested) (help)
  13. ^ a b Naroff, Steve (25 May 2007). New LLVM C Front-end (Slides). LLVM Developers' Meeting. {{cite conference}}: External link in |conferenceurl= (help); Unknown parameter |conferenceurl= ignored (|conference-url= suggested) (help)
  14. ^ a b c Clang team, clang: a C language family frontend for LLVM
  15. ^ Lattner, Chris (11 July 2007). "New LLVM C front-end: "clang"". cfe-dev (Mailing list). Archived from the original on 25 March 2015. {{cite mailing list}}: Unknown parameter |mailinglist= ignored (|mailing-list= suggested) (help)
  16. ^ Clang: Utility and Applications: Library Based Architecture
  17. ^ FLANG: NVIDIA Brings Fortran To LLVM
  18. ^ Clang - Features and Goals: Fast compiles and Low Memory Use, October 2007
  19. ^ a b c Simonis, Volker (10 February 2011). "Compiling the HotSpot VM with Clang". Archived from the original on 18 February 2011. 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. {{cite web}}: Unknown parameter |deadurl= ignored (|url-status= suggested) (help)
  20. ^ "Benchmarking LLVM & Clang Against GCC 4.5". Phoronix. 21 April 2010. Retrieved 13 February 2011. Binaries from LLVM-GCC and Clang both struggled to compete with GCC 4.5.0 in the timed HMMer benchmark of a Pfam database search. LLVM-GCC and Clang were about 23% slower(...)Though LLVM / Clang isn't the performance champion at this point, both components continue to be under very active development and there will hopefully be more news to report in the coming months
  21. ^ a b "GCC 4.9 VS. LLVM Clang 3.5 Linux Compiler Benchmarks". OpenBenchmarking.org. 14 April 2014. Retrieved 25 June 2014.
  22. ^ "Clang vs GCC - which produces better binaries?". stackoverflow.com. Retrieved 7 September 2017.
  23. ^ Divacky, Roman. "[Announce] clang/llvm can compile booting FreeBSD kernel on i386/amd64".
  24. ^ Building FreeBSD with Clang, Wiki.freebsd.org, 24 August 2012, retrieved 18 September 2012
  25. ^ Hornung, Alex. "llvm/clang once more".
  26. ^ Clang, DragonFly BSD, retrieved 18 September 2012
  27. ^ "Clang can compile LLVM and Clang". LLVM Project Blog.
  28. ^ "Clang Successfully Self-Hosts". LLVM Project Blog.
  29. ^ "HelenOS mainline changeset head,294".
  30. ^ Gregor, Doug. "Clang++ Builds Boost!". LLVM Project Blog.
  31. ^ Davis, Brad. "FreeBSD Status Reports April - June, 2010".
  32. ^ Clang builds a working Linux Kernel (Boots to RL5 with SMP, networking and X, self hosts), Lists.cs.uiuc.edu, archived from the original on 7 September 2015, retrieved 18 September 2012 {{citation}}: Unknown parameter |deadurl= ignored (|url-status= suggested) (help)
  33. ^ Gregor, Douglas (26 January 2011). "New C++0x feature support in Clang" (Mailing list). Archived from the original on 30 January 2011. Retrieved 29 January 2011. {{cite mailing list}}: Unknown parameter |deadurl= ignored (|url-status= suggested) (help)
  34. ^ "C++ and C++'0x Support in Clang". LLVM.
  35. ^ Sonnenberger, Jörg (19 January 2012). "Status of NetBSD and LLVM". Retrieved 26 February 2014.
  36. ^ Ledru, Sylvestre. "Rebuild of the Debian archive with clang".
  37. ^ "Official Minix 3 website: News".
  38. ^ Gerzo, Daniel (12 May 2012). "FreeBSD Quarterly Status Report January-March, 2012" (Mailing list). Retrieved 14 May 2012.
  39. ^ Davis, Brooks (5 November 2012). "Heads Up: Clang now the default on x86" (Mailing list). Retrieved 7 November 2012.
  40. ^ Webster, Behan (18 February 2013). "LLVMLinux: Compiling Android with LLVM" (PDF). Retrieved 11 May 2013.
  41. ^ Tinti, Vinicius (17 March 2013). "LLVMLinux: Nexus 7". Retrieved 11 May 2013.
  42. ^ Du Toit, Stefanus. "Clang is C++11 feature complete as of *just now*!".
  43. ^ "[llvm-project] Revision 194194".
  44. ^ Ledru, Sylvestre. "Rebuild of Debian using Clang 3.5.0".
  45. ^ "NDK Revision History | Android Developers". developer.android.com. Retrieved 6 March 2018.
  46. ^ "NDK Revision History  |  Android NDK |  Android Developers". Android Developers. Retrieved 30 April 2018. {{cite web}}: no-break space character in |title= at position 22 (help)
  47. ^ Nagy, Robert (26 July 2017). "switch the default compiler on amd64 and i386 to clang" (Mailing list). Retrieved 30 September 2017.
  48. ^ "Clang is now used to build Chrome for Windows". blog.llvm.org. Retrieved 7 April 2018.
  49. ^ "1443590 - Use clang-cl for Windows builds we ship to users". bugzilla.mozilla.org. Retrieved 7 April 2018.

External links