Clang: Difference between revisions
Revert change in IPA pronunciation changed a while back. The cited source states the vowel sound is "ă", which is another way to write "æ" in English pronunciation. |
|||
(28 intermediate revisions by 20 users not shown) | |||
Line 1: | Line 1: | ||
{{Short description|Compiler front-end}} |
{{Short description|Compiler front-end}} |
||
{{About|the compiler| |
{{About|the compiler|other uses|Clang (disambiguation)}} |
||
{{Not to be confused with|C (programming language)}} |
|||
{{Use mdy dates|date=January 2021}} |
{{Use mdy dates|date=January 2021}} |
||
{{Infobox software |
{{Infobox software |
||
| name |
| name = Clang |
||
| logo |
| logo = |
||
| screenshot |
| screenshot = Clang 13.0.1 version information screenshot.png |
||
| caption |
| caption = Clang 13.0.1 |
||
| author |
| author = [[Chris Lattner]] |
||
| developer |
| developer = LLVM Developer Group |
||
| released |
| released = {{Start date and age|2007|09|26}}<ref>{{Cite web|url=https://www.llvm.org/releases/2.1/docs/ReleaseNotes.html|title=LLVM 2.1 Release Notes|website=llvm.org|publisher=LLVM Developer Group|date=27 September 2007|access-date=April 30, 2018|archive-date=November 17, 2016|archive-url=https://web.archive.org/web/20161117042311/http://llvm.org/releases/2.1/docs/ReleaseNotes.html|url-status=live}}</ref> |
||
| latest release version = {{wikidata|property|preferred|references|edit |
| latest release version = {{wikidata|property|preferred|references|edit|P348|P548=Q2804309}} |
||
| latest release date |
| latest release date = {{Start date and age|{{wikidata|qualifier|preferred|single|P348|P548=Q2804309|P577}}|df=yes}} |
||
| latest preview version = {{wikidata|property|preferred|references|edit|Q864915|P348|P548= |
| latest preview version = {{wikidata|property|preferred|references|edit|Q864915|P348|P548=Q1072356}} |
||
| latest preview date |
| latest preview date = {{wikidata|qualifier|preferred|single|Q864915|P348|P548=Q1072356|P577}} |
||
| programming language |
| programming language = [[C++]] |
||
| operating system |
| operating system = [[Unix-like]] |
||
| platform |
| platform = [[AArch64]], [[ARMv7]], [[IA-32]], [[x86-64]], [[ppc64le]]<ref name="GitRepo">{{Cite web |url=https://github.com/llvm/llvm-project/releases |title=Releases |work=llvm – llvm-project repo |publisher=LLVM Developer Group |via=[[GitHub.com]] |date=27 August 2021 |access-date=September 12, 2021 |archive-date=September 12, 2021 |archive-url=https://web.archive.org/web/20210912214255/https://github.com/llvm/llvm-project/releases |url-status=live}}</ref> |
||
| language |
| language = |
||
| genre |
| genre = [[Compiler front end]] |
||
| license |
| license = [[Apache License 2.0|Apache 2.0]] with LLVM Exceptions<ref name="License"/><ref name="Relicensing_efforts"/> |
||
| website |
| website = {{URL|https://clang.llvm.org}} |
||
}} |
}} |
||
'''Clang''' ({{IPAc-en|ˈ|k|l|æ|ŋ}})<ref>{{Cite mailing list |url=https://lists.llvm.org/pipermail/llvm-dev/2008-July/015629.html |title=simply wonder pronunciation of Clang |date=3 July 2008 |access-date=2015-09-22 |mailing-list=LLVMdev |last=Christopher |first=Eric}}</ref> is a [[compiler front end]] for the [[C (programming language)|C]], [[C++]], [[Objective-C]], |
'''Clang''' ({{IPAc-en|ˈ|k|l|æ|ŋ}})<ref>{{Cite mailing list |url=https://lists.llvm.org/pipermail/llvm-dev/2008-July/015629.html |title=simply wonder pronunciation of Clang |date=3 July 2008 |access-date=2015-09-22 |mailing-list=LLVMdev |last=Christopher |first=Eric}}</ref> is a [[compiler front end]] for the [[programming language]]s [[C (programming language)|C]], [[C++]], [[Objective-C]], [[Objective-C++]], and the [[software framework]]s [[OpenMP]],<ref>{{cite web |title=OpenMP Support |url=http://blog.llvm.org/2015/05/openmp-support_22.html |website=LLVM Project Blog |date=May 22, 2015 |access-date=28 March 2016 |archive-date=March 26, 2016 |archive-url=https://web.archive.org/web/20160326042624/http://blog.llvm.org/2015/05/openmp-support_22.html |url-status=live}}</ref> [[OpenCL]], [[RenderScript]], [[CUDA]], [[SYCL]], and [[GPUOpen#AMD Boltzmann Initiative|HIP]].<ref>{{cite web |title=C++ Heterogeneous-Compute Interface for Portability |website=[[GitHub]] |url=https://github.com/ROCm-Developer-Tools/HIP |access-date=18 February 2020 |archive-date=June 27, 2020 |archive-url=https://web.archive.org/web/20200627204139/https://github.com/ROCm-Developer-Tools/HIP |url-status=live}}</ref> It acts as a [[drop-in replacement]] for the [[GNU Compiler Collection]] (GCC), supporting most of its [[Command-line interface#Command-line option|compiling flags]] and unofficial language extensions.<ref>{{cite web |url=https://clang.llvm.org/docs/LanguageExtensions.html |title=Clang Language Extensions |access-date=2017-11-08 |quote=In addition to the language extensions listed here, Clang aims to support a broad range of GCC extensions. |archive-date=February 24, 2014 |archive-url=https://web.archive.org/web/20140224002333/http://clang.llvm.org/docs/LanguageExtensions.html |url-status=live}}</ref><ref name="GCCCompat" /> It includes a [[static program analysis|static analyzer]], and several code analysis tools.<ref>{{cite web |url=https://clang-analyzer.llvm.org/ |title=Clang Static Analyzer |publisher=LLVM |access-date=3 September 2009 |archive-date=April 30, 2018 |archive-url=https://web.archive.org/web/20180430013035/http://clang-analyzer.llvm.org/ |url-status=live}}</ref> |
||
Clang operates in tandem with the [[LLVM]] [[compiler back end]] and has been a subproject of LLVM 2.6 and later.<ref>{{citation |url=https://clang.llvm.org/get_involved.html |title=Getting Involved with the Clang Project |website=clang.llvm.org |publisher=LLVM Developer Group |access-date=2012-09-18 |quote=Clang is a subproject of the LLVM Project, but has its own mailing lists because the communities have people with different interests. |archive-date=April 27, 2018 |archive-url=https://web.archive.org/web/20180427112311/http://clang.llvm.org/get_involved.html |url-status=live |
Clang operates in tandem with the [[LLVM]] [[compiler back end]] and has been a subproject of LLVM 2.6 and later.<ref>{{citation |url=https://clang.llvm.org/get_involved.html |title=Getting Involved with the Clang Project |website=clang.llvm.org |publisher=LLVM Developer Group |access-date=2012-09-18 |quote=Clang is a subproject of the LLVM Project, but has its own mailing lists because the communities have people with different interests. |archive-date=April 27, 2018 |archive-url=https://web.archive.org/web/20180427112311/http://clang.llvm.org/get_involved.html |url-status=live}}</ref> As with LLVM, it is [[free and open-source software]] under the [[Apache License 2.0|Apache 2.0]] [[software license]].<ref name="License">{{citation |url=https://releases.llvm.org/9.0.0/LICENSE.TXT |title=LICENSE.TXT |website=llvm.org |publisher=LLVM Developer Group |access-date=2019-09-24 |archive-date=November 11, 2020 |archive-url=https://web.archive.org/web/20201111220059/https://releases.llvm.org/9.0.0/LICENSE.TXT |url-status=live}}</ref><ref name="Relicensing_efforts">{{Citation |url=https://llvm.org/docs/DeveloperPolicy.html#copyright-license-and-patents |title=LLVM Developer Policy |website=llvm.org |publisher=LLVM Developer Group |at=§ Copyright, License, and Patents |access-date=September 12, 2021 |archive-date=November 13, 2012 |archive-url=https://web.archive.org/web/20121113204817/https://www.llvm.org/docs/DeveloperPolicy.html#copyright-license-and-patents |url-status=live}}</ref> Its contributors include [[Apple Inc.|Apple]], [[Microsoft]], [[Google]], [[ARM Holdings|ARM]], [[Sony]], [[Intel]], and [[Advanced Micro Devices|AMD]]. |
||
Clang |
Clang 17, the latest major version of Clang as of October 2023, has full support for all published C++ standards up to [[C++17]], implements most features of [[C++20]], and has initial support for the upcoming [[C++23]] standard.<ref name=cxx_status /> Since v16.0.0, Clang compiles C++ using the GNU++17 dialect by default, which includes features from the [[C++17]] standard and conforming GNU extensions.<ref>{{cite web |title=Clang 17.0.1 Release Notes |url=https://releases.llvm.org/17.0.1/tools/clang/docs/ReleaseNotes.html|archive-url= |archive-date= |access-date=October 25, 2023 |publisher=LLVM}}</ref> |
||
== Background == |
== Background == |
||
In 2005, [[Apple Inc.]] made extensive use of LLVM in several commercial products,<ref>{{cite mailing list|first=Adam|last=Treat|date=19 February 2005|url=http://lists.trolltech.com/qt4-preview-feedback/2005-02/msg00691.html|title=mkspecs and patches for LLVM compile of Qt4|mailing-list=Qt4-preview-feedback|url-status=dead|archive-url=https://web.archive.org/web/20111004073001/http://lists.trolltech.com/qt4-preview-feedback/2005-02/msg00691.html|archive-date=4 October 2011}}</ref> including the [[iOS SDK]] and [[Xcode]] 3.1. An [[OpenGL]] code compiler for [[OS X]] that converts OpenGL calls into more fundamental calls for [[graphics processing unit]]s (GPU) that do not support certain features, was one of the first uses of LLVM. This enabled Apple to support OpenGL on computers using [[Intel GMA]] chipsets, increasing performance on those machines.<ref>{{cite conference |
|||
|first=Chris |
|first=Chris |
||
|last=Lattner |
|last=Lattner |
||
Line 70: | Line 71: | ||
}}</ref> Finally, GCC's license agreement, the [[GNU General Public License#Version 3|GNU General Public License (GPL) version 3]], requires developers who distribute extensions or modified versions of GCC to make their [[source code]] available, but LLVM's [[permissive software license]] doesn't require this.<ref name="License" /><ref name="Relicensing_efforts" /> |
}}</ref> Finally, GCC's license agreement, the [[GNU General Public License#Version 3|GNU General Public License (GPL) version 3]], requires developers who distribute extensions or modified versions of GCC to make their [[source code]] available, but LLVM's [[permissive software license]] doesn't require this.<ref name="License" /><ref name="Relicensing_efforts" /> |
||
For these reasons, Apple developed Clang, a new compiler front end which supports C, Objective-C and C++.<ref name="SN0705" /> In July 2007, the project received the approval for becoming open-source.<ref>{{cite mailing list |
|||
| first=Chris |
| first=Chris |
||
| last=Lattner |
| last=Lattner |
||
Line 84: | Line 85: | ||
== Design == |
== Design == |
||
Clang works in tandem with LLVM.<ref name="clang">Clang team, ''[https://clang.llvm.org/ clang: a C language family frontend for LLVM] {{Webarchive|url=https://web.archive.org/web/20171112232029/http://clang.llvm.org/ |date=November 12, 2017 }}''</ref> The combination of Clang and LLVM provides most of the [[toolchain]] for replacing the GCC [[Solution stack|stack]]. One of Clang's main goals is to provide a library-based architecture,<ref>{{Cite web |url=https://clang.llvm.org/features.html#libraryarch |title=Clang: Utility and Applications: Library Based Architecture |access-date=April 30, 2018 |archive-date=April 27, 2018 |archive-url=https://web.archive.org/web/20180427121756/http://clang.llvm.org/features.html#libraryarch |url-status=live |
Clang works in tandem with LLVM.<ref name="clang">Clang team, ''[https://clang.llvm.org/ clang: a C language family frontend for LLVM] {{Webarchive|url=https://web.archive.org/web/20171112232029/http://clang.llvm.org/ |date=November 12, 2017 }}''</ref> The combination of Clang and LLVM provides most of the [[toolchain]] for replacing the GCC [[Solution stack|stack]]. One of Clang's main goals is to provide a library-based architecture,<ref>{{Cite web |url=https://clang.llvm.org/features.html#libraryarch |title=Clang: Utility and Applications: Library Based Architecture |access-date=April 30, 2018 |archive-date=April 27, 2018 |archive-url=https://web.archive.org/web/20180427121756/http://clang.llvm.org/features.html#libraryarch |url-status=live}}</ref> so that the compiler could interoperate with other tools that interact with source code, such as [[integrated development environment]]s (IDE). In contrast, GCC works in a compile-[[Linker (computing)|link]]-[[Debugging|debug]] workflow; 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. Besides, vendors using the GCC stack within IDEs must use separate tools to index the code, to provide features like [[syntax highlighting]] and [[intelligent code completion]]. |
||
Clang retains more information during the compiling process than GCC, and preserves the overall form of the original code, making it easier to map errors back into the original source. Clang's error reports are more detailed, specific, and machine-readable, so IDEs can index the compiler's output. 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 retains more information during the compiling process than GCC, and preserves the overall form of the original code, making it easier to map errors back into the original source. Clang's error reports are more detailed, specific, and machine-readable, so IDEs can index the compiler's output. 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. |
||
Line 91: | Line 92: | ||
===Flang - Fortran=== |
===Flang - Fortran=== |
||
The ''Flang'' project by [[Nvidia]] and [[The Portland Group]] adds [[Fortran]] support.<ref>{{Cite web |url=https://phoronix.com/scan.php?page=news_item&px=LLVM-NVIDIA-Fortran-Flang |title=FLANG: NVIDIA Brings Fortran To LLVM |access-date=May 18, 2017 |archive-date=May 20, 2017 |archive-url=https://web.archive.org/web/20170520182339/http://www.phoronix.com/scan.php?page=news_item&px=LLVM-NVIDIA-Fortran-Flang |url-status=live |
The ''Flang'' project by [[Nvidia]] and [[The Portland Group]] adds [[Fortran]] support.<ref>{{Cite web |url=https://phoronix.com/scan.php?page=news_item&px=LLVM-NVIDIA-Fortran-Flang |title=FLANG: NVIDIA Brings Fortran To LLVM |access-date=May 18, 2017 |archive-date=May 20, 2017 |archive-url=https://web.archive.org/web/20170520182339/http://www.phoronix.com/scan.php?page=news_item&px=LLVM-NVIDIA-Fortran-Flang |url-status=live}}</ref> Flang is LLVM's Fortran frontend. It is often referred to as "LLVM Flang" to differentiate itself from "Classic Flang" – these are two separate and independent Fortran compilers. "LLVM Flang" is under active development. Development versions of Flang were in progress {{As of|2023|10|lc=y}} and could be downloaded from the LLVM Project.<ref>{{Cite web |url=https://flang.llvm.org/docs/ |title=Welcome to Flang's documentation — the Flang Compiler}}</ref> |
||
== Performance and GCC compatibility == |
== Performance and GCC compatibility == |
||
[[File:Clang 12.0.1 compiling htop.png|upright=1.4|thumb|Clang compiling [[htop]]]] |
[[File:Clang 12.0.1 compiling htop.png|upright=1.4|thumb|Clang compiling [[htop]]]] |
||
Clang is compatible with GCC.<ref name="GCCCompat">{{citation |url=https://clang.llvm.org/features.html#gcccompat |title=Clang - Features and Goals: GCC Compatibility |date=15 April 2013 |access-date=April 30, 2018 |archive-date=April 27, 2018 |archive-url=https://web.archive.org/web/20180427121756/http://clang.llvm.org/features.html#gcccompat |url-status=live }}</ref> Its [[command-line interface]] shares many of GCC's [[Command- |
Clang is compatible with GCC.<ref name="GCCCompat">{{citation |url=https://clang.llvm.org/features.html#gcccompat |title=Clang - Features and Goals: GCC Compatibility |date=15 April 2013 |access-date=April 30, 2018 |archive-date=April 27, 2018 |archive-url=https://web.archive.org/web/20180427121756/http://clang.llvm.org/features.html#gcccompat |url-status=live }}</ref> Its [[command-line interface]] shares many of GCC's [[Command-line interface#Command-line option|flag]]s and options. Clang implements many GNU language extensions and [[Intrinsic function|compiler intrinsics]], some of which are purely for compatibility. For example, even though Clang implements atomic intrinsics which correspond exactly with C11 [[atomic operations|atomics]], it also implements GCC's <code>__sync_*</code> intrinsics for compatibility with GCC and the [[C++ Standard Library]] (libstdc++). Clang also maintains [[application binary interface]] (ABI) compatibility with GCC-generated [[object code]]. In practice, Clang is a drop-in replacement for GCC.<ref>{{citation |url=https://clang.llvm.org/get_started.html#driver |title=Clang can often be used as a drop-in replacement for GCC |date=May 2020 |access-date=May 9, 2020 |archive-date=May 8, 2020 |archive-url=https://web.archive.org/web/20200508185500/http://clang.llvm.org/get_started.html#driver |url-status=live}}</ref> |
||
Clang's developers aim to reduce [[memory footprint]] and increase |
Clang's developers aim to reduce [[memory footprint]] and increase compiling speed compared to other compilers, such as GCC. In October 2007, they report that Clang compiled the [[Carbon (API)|Carbon]] libraries more than twice as fast as GCC, while using about one-sixth GCC's memory and disk space.<ref>{{citation |url=https://clang.llvm.org/features.html |title=Clang - Features and Goals: Fast compiles and Low Memory Use |date=October 2007 |access-date=April 30, 2018 |archive-date=April 27, 2018 |archive-url=https://web.archive.org/web/20180427121756/http://clang.llvm.org/features.html |url-status=live }}</ref> By 2011, Clang seemed to retain this advantage in compiler performance.<ref name="Simonis">{{cite web|url=https://weblogs.java.net/blog/simonis/archive/2011/02/10/compiling-hotspot-vm-clang |first=Volker |last=Simonis |title=Compiling the HotSpot VM with Clang |date=10 February 2011 |quote=''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. '' |access-date=13 February 2011 |url-status=dead |archive-url=https://web.archive.org/web/20110218013535/http://weblogs.java.net/blog/simonis/archive/2011/02/10/compiling-hotspot-vm-clang |archive-date=18 February 2011 }}</ref><ref>{{cite web |
||
| url=https://www.phoronix.com/scan.php?page=article&item=gcc_llvm_clang&num=6 |
| url=https://www.phoronix.com/scan.php?page=article&item=gcc_llvm_clang&num=6 |
||
| publisher=[[Phoronix]] |
| publisher=[[Phoronix]] |
||
Line 121: | Line 122: | ||
* Comparisons in November 2016 between GCC 4.8.2 versus clang 3.4, on a large harness of test files shows that GCC outperforms clang by approximately 17% on well-optimized source code. Test results are code-specific, and unoptimized C source code can reverse such differences. The two compilers thus seem broadly comparable.<ref>{{Cite web|url=https://stackoverflow.com/questions/3187414/clang-vs-gcc-which-produces-better-binaries#15043814|title=Clang vs GCC - which produces better binaries?|website=stackoverflow.com|access-date=2018-10-01|archive-date=June 1, 2017|archive-url=https://web.archive.org/web/20170601085417/https://stackoverflow.com/questions/3187414/clang-vs-gcc-which-produces-better-binaries#15043814|url-status=live}}</ref>{{Unreliable source?|certain=y|date=October 2018}} |
* Comparisons in November 2016 between GCC 4.8.2 versus clang 3.4, on a large harness of test files shows that GCC outperforms clang by approximately 17% on well-optimized source code. Test results are code-specific, and unoptimized C source code can reverse such differences. The two compilers thus seem broadly comparable.<ref>{{Cite web|url=https://stackoverflow.com/questions/3187414/clang-vs-gcc-which-produces-better-binaries#15043814|title=Clang vs GCC - which produces better binaries?|website=stackoverflow.com|access-date=2018-10-01|archive-date=June 1, 2017|archive-url=https://web.archive.org/web/20170601085417/https://stackoverflow.com/questions/3187414/clang-vs-gcc-which-produces-better-binaries#15043814|url-status=live}}</ref>{{Unreliable source?|certain=y|date=October 2018}} |
||
* Comparisons in 2019 on [[Ice Lake (microprocessor)|Intel Ice Lake]] has shown that programs generated by Clang 10 has achieved 96% of the performance of GCC 10 over 41 different benchmarks (while winning 22 and losing 19 out of them).<ref name=clang10-ph>{{cite web|url=https://www.phoronix.com/scan.php?page=news_item&px=GCC-LLVM-Clang-Icelake-Tests|title=LLVM Clang Achieves ~96% The Performance Of GCC On Intel Ice Lake|author=Michael Larabel|date=Dec 23, 2019|access-date=January 14, 2021|archive-date=January 15, 2021|archive-url=https://web.archive.org/web/20210115185420/https://www.phoronix.com/scan.php?page=news_item&px=GCC-LLVM-Clang-Icelake-Tests|url-status=live}}</ref> |
* Comparisons in 2019 on [[Ice Lake (microprocessor)|Intel Ice Lake]] has shown that programs generated by Clang 10 has achieved 96% of the performance of GCC 10 over 41 different benchmarks (while winning 22 and losing 19 out of them).<ref name=clang10-ph>{{cite web|url=https://www.phoronix.com/scan.php?page=news_item&px=GCC-LLVM-Clang-Icelake-Tests|title=LLVM Clang Achieves ~96% The Performance Of GCC On Intel Ice Lake|author=Michael Larabel|date=Dec 23, 2019|access-date=January 14, 2021|archive-date=January 15, 2021|archive-url=https://web.archive.org/web/20210115185420/https://www.phoronix.com/scan.php?page=news_item&px=GCC-LLVM-Clang-Icelake-Tests|url-status=live}}</ref> |
||
* In 2023, another comparison conducted four years later revealed that programs compiled using Clang now match the performance of those compiled with GCC. On average, Clang 16 surpasses GCC 13 by 6%.<ref>{{cite web|url=https://www.phoronix.com/review/gcc13-clang16-raptorlake/5|title=LLVM Clang 16 vs. GCC 13 Compiler Performance On Intel Raptor Lake|author=Michael Larabel|date=May 11, 2023|access-date=April 24, 2024}}</ref> |
|||
== Interface == |
== Interface == |
||
Line 140: | Line 142: | ||
| url=https://lists.freebsd.org/pipermail/freebsd-current/2009-February/003743.html |
| url=https://lists.freebsd.org/pipermail/freebsd-current/2009-February/003743.html |
||
| title=[Announce] clang/llvm can compile booting FreeBSD kernel on i386/amd64 |
| title=[Announce] clang/llvm can compile booting FreeBSD kernel on i386/amd64 |
||
| date=February 25, 2009 |
|||
| access-date=April 30, 2018 |
| access-date=April 30, 2018 |
||
| archive-date=May 1, 2018 |
| archive-date=May 1, 2018 |
||
Line 198: | Line 201: | ||
| last=Davis |
| last=Davis |
||
| url=https://www.freebsd.org/news/status/report-2010-04-2010-06.html#Clang-Replacing-GCC-in-the-Base-System |
| url=https://www.freebsd.org/news/status/report-2010-04-2010-06.html#Clang-Replacing-GCC-in-the-Base-System |
||
| title=FreeBSD Status Reports April–June |
| title=FreeBSD Status Reports April–June, 2010 |
||
| access-date=April 30, 2018 |
| access-date=April 30, 2018 |
||
| archive-date=June 24, 2018 |
| archive-date=June 24, 2018 |
||
Line 254: | Line 257: | ||
| first=Daniel |
| first=Daniel |
||
| last=Gerzo |
| last=Gerzo |
||
| title=FreeBSD Quarterly Status Report |
| title=FreeBSD Quarterly Status Report January–March, 2012 |
||
| date=12 May 2012 |
| date=12 May 2012 |
||
| access-date=14 May 2012 |
| access-date=14 May 2012 |
||
Line 391: | Line 394: | ||
|- |
|- |
||
|29 February 2020 |
|29 February 2020 |
||
|Clang becomes the only C compiler in the [[FreeBSD]] base system, with the removal of [[GNU Compiler Collection|GCC]].<ref>{{Cite web|url=https://lists.freebsd.org/pipermail/svn-src-all/2020-February/194446.html|title=FreeBSD svn commit r358454|access-date=March 7, 2020|archive-date=March 10, 2020|archive-url=https://web.archive.org/web/20200310155542/https://lists.freebsd.org/pipermail/svn-src-all/2020-February/194446.html|url-status=live}}</ref> |
|Clang becomes the only C compiler in the [[FreeBSD]] base system, with the removal of [[GNU Compiler Collection|GCC]].<ref>{{Cite web|url=https://lists.freebsd.org/pipermail/svn-src-all/2020-February/194446.html|title=FreeBSD svn commit r358454|date=February 29, 2020 |access-date=March 7, 2020|archive-date=March 10, 2020|archive-url=https://web.archive.org/web/20200310155542/https://lists.freebsd.org/pipermail/svn-src-all/2020-February/194446.html|url-status=live}}</ref> |
||
|- |
|- |
||
|24 March 2020 |
|24 March 2020 |
||
Line 437: | Line 440: | ||
|17 March 2023 |
|17 March 2023 |
||
|Clang 16.0.0 [https://releases.llvm.org/16.0.0/tools/clang/docs/ReleaseNotes.html released] |
|Clang 16.0.0 [https://releases.llvm.org/16.0.0/tools/clang/docs/ReleaseNotes.html released] |
||
|- |
|||
|9 September 2023 |
|||
|Clang 17.0.1 [https://releases.llvm.org/17.0.1/tools/clang/docs/ReleaseNotes.html released] |
|||
|- |
|||
|8 March 2024 |
|||
|Clang 18.1.1 [https://releases.llvm.org/18.1.1/tools/clang/docs/ReleaseNotes.html released] |
|||
|- |
|||
|17 September 2024 |
|||
|Clang 19.1.0 [https://releases.llvm.org/19.1.0/tools/clang/docs/ReleaseNotes.html released] |
|||
|} |
|} |
||
</div> |
</div> |
||
Line 443: | Line 455: | ||
{{Portal|Free and open-source software}} |
{{Portal|Free and open-source software}} |
||
* [[AMD Optimizing C/C++ Compiler]] |
* [[AMD Optimizing C/C++ Compiler]] |
||
* [[LLDB (debugger) |
* [[LLDB (debugger)]] |
||
* [[Portable C Compiler]] |
* [[Portable C Compiler]] |
||
Line 455: | Line 467: | ||
[[Category:C (programming language) compilers]] |
[[Category:C (programming language) compilers]] |
||
[[Category:C++ compilers]] |
[[Category:C++ compilers]] |
||
[[Category:Free |
[[Category:Free and open source compilers]] |
||
[[Category:Software using the NCSA license]] |
[[Category:Software using the NCSA license]] |
||
[[Category:Software using the Apache license]] |
[[Category:Software using the Apache license]] |
Latest revision as of 12:21, 11 November 2024
Original author(s) | Chris Lattner |
---|---|
Developer(s) | LLVM Developer Group |
Initial release | September 26, 2007[1] |
Stable release | 19.1.3[2]
/ 30 October 2024 |
Repository | |
Written in | C++ |
Operating system | Unix-like |
Platform | AArch64, ARMv7, IA-32, x86-64, ppc64le[3] |
Type | Compiler front end |
License | Apache 2.0 with LLVM Exceptions[4][5] |
Website | clang |
Clang (/ˈklæŋ/)[6] is a compiler front end for the programming languages C, C++, Objective-C, Objective-C++, and the software frameworks OpenMP,[7] OpenCL, RenderScript, CUDA, SYCL, and HIP.[8] It acts as a drop-in replacement for the GNU Compiler Collection (GCC), supporting most of its compiling flags and unofficial language extensions.[9][10] It includes a static analyzer, and several code analysis tools.[11]
Clang operates in tandem with the LLVM compiler back end and has been a subproject of LLVM 2.6 and later.[12] As with LLVM, it is free and open-source software under the Apache 2.0 software license.[4][5] Its contributors include Apple, Microsoft, Google, ARM, Sony, Intel, and AMD.
Clang 17, the latest major version of Clang as of October 2023, has full support for all published C++ standards up to C++17, implements most features of C++20, and has initial support for the upcoming C++23 standard.[13] Since v16.0.0, Clang compiles C++ using the GNU++17 dialect by default, which includes features from the C++17 standard and conforming GNU extensions.[14]
Background
[edit]In 2005, Apple Inc. made extensive use of LLVM in several commercial products,[15] including the iOS SDK and Xcode 3.1. 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, was one of the first uses of LLVM. This enabled Apple to support OpenGL on computers using Intel GMA chipsets, increasing performance on those machines.[16]
The LLVM project originally intended to use GCC's front end. The GCC source code, however, is large and somewhat cumbersome; as one long-time GCC developer put it referring to LLVM, "Trying to make the hippo dance is not really a lot of fun".[17] Besides, Apple software uses Objective-C, which is a low priority for GCC developers. As such, GCC does not integrate smoothly into Apple's integrated development environment (IDE).[18] Finally, GCC's license agreement, the GNU General Public License (GPL) version 3, requires developers who distribute extensions or modified versions of GCC to make their source code available, but LLVM's permissive software license doesn't require this.[4][5]
For these reasons, Apple developed Clang, a new compiler front end which supports C, Objective-C and C++.[18] In July 2007, the project received the approval for becoming open-source.[19]
Design
[edit]Clang works in tandem with LLVM.[20] The combination of Clang and LLVM provides most of the toolchain for replacing the GCC stack. One of Clang's main goals is to provide a library-based architecture,[21] so that the compiler could interoperate with other tools that interact with source code, such as integrated development environments (IDE). In contrast, GCC works in a compile-link-debug workflow; 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. Besides, vendors using the GCC stack within IDEs must use separate tools to index the code, to provide features like syntax highlighting and intelligent code completion.
Clang retains more information during the compiling process than GCC, and preserves the overall form of the original code, making it easier to map errors back into the original source. Clang's error reports are more detailed, specific, and machine-readable, so IDEs can index the compiler's output. 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 compiles only C-like languages, such as C, C++, Objective-C, and Objective-C++. In many cases, Clang can replace GCC as needed, with no other effects on the toolchain as a whole.[citation needed] It supports most of the commonly used GCC options. A Fortran project, Flang was in-progress in 2022. However, for other languages, such as Ada, LLVM remains dependent on GCC or another compiler front end.
Flang - Fortran
[edit]The Flang project by Nvidia and The Portland Group adds Fortran support.[22] Flang is LLVM's Fortran frontend. It is often referred to as "LLVM Flang" to differentiate itself from "Classic Flang" – these are two separate and independent Fortran compilers. "LLVM Flang" is under active development. Development versions of Flang were in progress as of October 2023[update] and could be downloaded from the LLVM Project.[23]
Performance and GCC compatibility
[edit]Clang is compatible with GCC.[10] Its command-line interface shares many of GCC's flags and options. Clang implements many GNU language extensions and compiler intrinsics, some of which are 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 the C++ Standard Library (libstdc++). Clang also maintains application binary interface (ABI) compatibility with GCC-generated object code. In practice, Clang is a drop-in replacement for GCC.[24]
Clang's developers aim to reduce memory footprint and increase compiling speed compared to other 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.[25] By 2011, Clang seemed to retain this advantage in compiler performance.[26][27] As of mid-2014, Clang still consistently compiles faster than GCC in a mixed compile time and program performance benchmark.[28] However, by 2019, Clang is significantly slower at compiling the Linux Kernel than GCC while remaining slightly faster at compiling LLVM.[29]
While Clang has historically been faster than GCC at compiling, the output quality has lagged behind. As of 2014, performance of Clang-compiled programs lagged behind performance of the GCC-compiled program, sometimes by large factors (up to 5.5x),[28] replicating earlier reports of slower performance.[26] Both compilers have evolved to increase their performance since then, with the gap narrowing:
- Comparisons in November 2016 between GCC 4.8.2 versus clang 3.4, on a large harness of test files shows that GCC outperforms clang by approximately 17% on well-optimized source code. Test results are code-specific, and unoptimized C source code can reverse such differences. The two compilers thus seem broadly comparable.[30][unreliable source]
- Comparisons in 2019 on Intel Ice Lake has shown that programs generated by Clang 10 has achieved 96% of the performance of GCC 10 over 41 different benchmarks (while winning 22 and losing 19 out of them).[29]
- In 2023, another comparison conducted four years later revealed that programs compiled using Clang now match the performance of those compiled with GCC. On average, Clang 16 surpasses GCC 13 by 6%.[31]
Interface
[edit]libclang
provides a C interface, providing a relatively small API. Exposed functionality includes: parsing source code into an AST, loading ASTs, traversing the AST, associating source locations with elements within the AST.
Status history
[edit]This table presents only significant steps and releases in Clang history.
Date | Highlights |
---|---|
11 July 2007 | Clang front-end released under open-source licence |
25 February 2009 | Clang/LLVM can compile a working FreeBSD kernel.[32][33] |
16 March 2009 | Clang/LLVM can compile a working DragonFly BSD kernel.[34][35] |
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,[20] and can compile itself.[36] |
2 February 2010 | Clang self-hosting.[37] |
20 May 2010 | Clang latest version built the Boost C++ libraries successfully, and passed nearly all tests.[38] |
10 June 2010 | Clang/LLVM becomes integral part of FreeBSD, but default compiler is still GCC.[39] |
25 October 2010 | Clang/LLVM can compile a working modified Linux kernel.[40] |
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.[41][13] |
10 February 2011 | Clang can compile a working HotSpot Java virtual machine.[26] |
19 January 2012 | Clang becomes an optional component in NetBSD cross-platform build system, but GCC is still default.[42] |
29 February 2012 | Clang 3.0 can rebuild 91.2% of the Debian archive.[43] |
29 February 2012 | Clang becomes default compiler in MINIX 3[44] |
12 May 2012 | Clang/LLVM announced to replace GCC in FreeBSD.[45] |
5 November 2012 | Clang becomes default compiler in FreeBSD 10.x on amd64/i386.[46] |
18 February 2013 | Clang/LLVM can compile a working modified Android Linux Kernel for Nexus 7.[47][48] |
19 April 2013 | Clang is C++11 feature complete.[49] |
6 November 2013 | Clang is C++14 feature complete.[50] |
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.[51] |
October 2016 | Clang becomes default compiler for Android[52] (and later only compiler supported by Android NDK[53]). |
13 March 2017 | Clang 4.0.0 released |
26 July 2017 | Clang becomes default compiler in OpenBSD 6.2 on amd64/i386.[54] |
7 September 2017 | Clang 5.0.0 released |
19 January 2018 | Clang becomes default compiler in OpenBSD 6.3 on arm.[55] |
5 March 2018 | Clang is now used to build Google Chrome for Windows.[56] |
8 March 2018 | Clang 6.0.0 released |
5 September 2018 | Clang is now used to build Firefox for Windows.[57] |
19 September 2018 | Clang 7.0.0 released |
20 March 2019 | Clang 8.0.0 released |
1 July 2019 | Clang becomes default compiler in OpenBSD 6.6 on mips64.[58] |
19 September 2019 | Clang 9.0.0 released with official RISC-V target support.[59] |
29 February 2020 | Clang becomes the only C compiler in the FreeBSD base system, with the removal of GCC.[60] |
24 March 2020 | Clang 10.0.0 released |
2 April 2020 | Clang becomes default compiler in OpenBSD 6.7 on powerpc.[61] |
12 October 2020 | Clang 11.0.0 released |
21 December 2020 | Clang becomes default compiler in OpenBSD 6.9 on mips64el.[62] |
14 April 2021 | Clang 12.0.0 released |
4 October 2021 | Clang 13.0.0 released |
25 March 2022 | Clang 14.0.0 released |
6 September 2022 | Clang 15.0.0 released |
17 March 2023 | Clang 16.0.0 released |
9 September 2023 | Clang 17.0.1 released |
8 March 2024 | Clang 18.1.1 released |
17 September 2024 | Clang 19.1.0 released |
See also
[edit]References
[edit]- ^ "LLVM 2.1 Release Notes". llvm.org. LLVM Developer Group. September 27, 2007. Archived from the original on November 17, 2016. Retrieved April 30, 2018.
- ^ "LLVM 19.1.3". October 30, 2024. Retrieved October 30, 2024.
- ^ "Releases". llvm – llvm-project repo. LLVM Developer Group. August 27, 2021. Archived from the original on September 12, 2021. Retrieved September 12, 2021 – via GitHub.com.
- ^ a b c "LICENSE.TXT", llvm.org, LLVM Developer Group, archived from the original on November 11, 2020, retrieved September 24, 2019
- ^ a b c "LLVM Developer Policy", llvm.org, LLVM Developer Group, § Copyright, License, and Patents, archived from the original on November 13, 2012, retrieved September 12, 2021
- ^ Christopher, Eric (July 3, 2008). "simply wonder pronunciation of Clang". LLVMdev (Mailing list). Retrieved September 22, 2015.
- ^ "OpenMP Support". LLVM Project Blog. May 22, 2015. Archived from the original on March 26, 2016. Retrieved March 28, 2016.
- ^ "C++ Heterogeneous-Compute Interface for Portability". GitHub. Archived from the original on June 27, 2020. Retrieved February 18, 2020.
- ^ "Clang Language Extensions". Archived from the original on February 24, 2014. Retrieved November 8, 2017.
In addition to the language extensions listed here, Clang aims to support a broad range of GCC extensions.
- ^ a b Clang - Features and Goals: GCC Compatibility, April 15, 2013, archived from the original on April 27, 2018, retrieved April 30, 2018
- ^ "Clang Static Analyzer". LLVM. Archived from the original on April 30, 2018. Retrieved September 3, 2009.
- ^ "Getting Involved with the Clang Project", clang.llvm.org, LLVM Developer Group, archived from the original on April 27, 2018, retrieved September 18, 2012,
Clang is a subproject of the LLVM Project, but has its own mailing lists because the communities have people with different interests.
- ^ a b "C++ and C++'0x Support in Clang". LLVM. Archived from the original on July 4, 2013. Retrieved March 12, 2023.
- ^ "Clang 17.0.1 Release Notes". LLVM. Retrieved October 25, 2023.
- ^ Treat, Adam (February 19, 2005). "mkspecs and patches for LLVM compile of Qt4". Qt4-preview-feedback (Mailing list). Archived from the original on October 4, 2011.
- ^ Lattner, Chris (May 25, 2007). LLVM for OpenGL and other stuff (Slides). LLVM Developers' Meeting. Archived (PDF) from the original on May 8, 2016. Retrieved April 30, 2018.
- ^ Zadeck, Kenneth (November 19, 2005). "Re: LLVM/GCC Integration Proposal". GCC development (Mailing list). Archived from the original on March 10, 2016. Retrieved July 25, 2016.
- ^ a b Naroff, Steve (May 25, 2007). New LLVM C Front-end (Slides). LLVM Developers' Meeting. Archived (PDF) from the original on April 3, 2019. Retrieved April 30, 2018.
- ^ Lattner, Chris (July 11, 2007). "New LLVM C front-end: "clang"". cfe-dev (Mailing list). Archived from the original on March 26, 2020. Retrieved March 26, 2020.
- ^ a b Clang team, clang: a C language family frontend for LLVM Archived November 12, 2017, at the Wayback Machine
- ^ "Clang: Utility and Applications: Library Based Architecture". Archived from the original on April 27, 2018. Retrieved April 30, 2018.
- ^ "FLANG: NVIDIA Brings Fortran To LLVM". Archived from the original on May 20, 2017. Retrieved May 18, 2017.
- ^ "Welcome to Flang's documentation — the Flang Compiler".
- ^ Clang can often be used as a drop-in replacement for GCC, May 2020, archived from the original on May 8, 2020, retrieved May 9, 2020
- ^ Clang - Features and Goals: Fast compiles and Low Memory Use, October 2007, archived from the original on April 27, 2018, retrieved April 30, 2018
- ^ a b c Simonis, Volker (February 10, 2011). "Compiling the HotSpot VM with Clang". Archived from the original on February 18, 2011. Retrieved February 13, 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.
- ^ "Benchmarking LLVM & Clang Against GCC 4.5". Phoronix. April 21, 2010. Archived from the original on November 2, 2016. Retrieved February 13, 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
- ^ a b "GCC 4.9 VS. LLVM Clang 3.5 Linux Compiler Benchmarks". OpenBenchmarking.org. April 14, 2014. Archived from the original on October 23, 2017. Retrieved June 25, 2014.
- ^ a b Michael Larabel (December 23, 2019). "LLVM Clang Achieves ~96% The Performance Of GCC On Intel Ice Lake". Archived from the original on January 15, 2021. Retrieved January 14, 2021.
- ^ "Clang vs GCC - which produces better binaries?". stackoverflow.com. Archived from the original on June 1, 2017. Retrieved October 1, 2018.
- ^ Michael Larabel (May 11, 2023). "LLVM Clang 16 vs. GCC 13 Compiler Performance On Intel Raptor Lake". Retrieved April 24, 2024.
- ^ Divacky, Roman (February 25, 2009). "[Announce] clang/llvm can compile booting FreeBSD kernel on i386/amd64". Archived from the original on May 1, 2018. Retrieved April 30, 2018.
- ^ Building FreeBSD with Clang, Wiki.freebsd.org, August 24, 2012, archived from the original on April 30, 2018, retrieved September 18, 2012
- ^ Hornung, Alex. "llvm/clang once more". Archived from the original on April 30, 2018. Retrieved April 30, 2018.
- ^ Clang, DragonFly BSD, archived from the original on April 30, 2018, retrieved September 18, 2012
- ^ "Clang can compile LLVM and Clang". LLVM Project Blog. December 24, 2009. Archived from the original on April 26, 2012. Retrieved December 31, 2009.
- ^ "Clang Successfully Self-Hosts". LLVM Project Blog. February 4, 2010. Archived from the original on April 26, 2012. Retrieved February 5, 2010.
- ^ Gregor, Doug (May 20, 2010). "Clang++ Builds Boost!". LLVM Project Blog. Archived from the original on April 26, 2012. Retrieved May 21, 2010.
- ^ Davis, Brad. "FreeBSD Status Reports April–June, 2010". Archived from the original on June 24, 2018. Retrieved April 30, 2018.
- ^ 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 September 7, 2015, retrieved September 18, 2012
- ^ Gregor, Douglas (January 26, 2011). "New C++0x feature support in Clang" (Mailing list). Archived from the original on January 30, 2011. Retrieved January 29, 2011.
- ^ Sonnenberger, Jörg (January 19, 2012). "Status of NetBSD and LLVM". Archived from the original on September 21, 2016. Retrieved February 26, 2014.
- ^ Ledru, Sylvestre. "Rebuild of the Debian archive with clang". Archived from the original on May 1, 2018. Retrieved April 30, 2018.
- ^ "Official Minix 3 website: News". Archived from the original on December 17, 2009. Retrieved December 7, 2012.
- ^ Gerzo, Daniel (May 12, 2012). "FreeBSD Quarterly Status Report January–March, 2012" (Mailing list). Archived from the original on February 18, 2018. Retrieved May 14, 2012.
- ^ Davis, Brooks (November 5, 2012). "Heads Up: Clang now the default on x86" (Mailing list). Archived from the original on April 30, 2018. Retrieved November 7, 2012.
- ^ Webster, Behan (February 18, 2013). "LLVMLinux: Compiling Android with LLVM" (PDF). Archived from the original (PDF) on May 12, 2014. Retrieved May 11, 2013.
- ^ Tinti, Vinicius (March 17, 2013). "LLVMLinux: Nexus 7". Archived from the original on June 11, 2014. Retrieved May 11, 2013.
- ^ Du Toit, Stefanus. "Clang is C++11 feature complete as of *just now*!". Archived from the original on September 24, 2019. Retrieved April 20, 2013.
- ^ "[llvm-project] Revision 194194". Archived from the original on November 18, 2018. Retrieved April 30, 2018.
- ^ Ledru, Sylvestre. "Rebuild of Debian using Clang 3.5.0". Archived from the original on May 1, 2018. Retrieved April 30, 2018.
- ^ "NDK Revision History | Android Developers". developer.android.com. Archived from the original on March 6, 2018. Retrieved March 6, 2018.
- ^ "NDK Revision History | Android NDK | Android Developers". Android Developers. Archived from the original on April 5, 2019. Retrieved April 30, 2018.
- ^ Nagy, Robert (July 26, 2017). "switch the default compiler on amd64 and i386 to clang" (Mailing list). Archived from the original on October 25, 2018. Retrieved September 30, 2017.
- ^ Kettenis, Mark (January 19, 2018). "Switch the default compiler on armv7 to clang" (Mailing list). Archived from the original on April 8, 2022. Retrieved August 27, 2020.
- ^ "Clang is now used to build Chrome for Windows". blog.llvm.org. March 5, 2018. Archived from the original on March 5, 2018. Retrieved April 7, 2018.
- ^ "Firefox Beta 63.0beta, See All New Features, Updates and Fixes". www.mozilla.org. Archived from the original on April 19, 2021. Retrieved March 18, 2020.
- ^ Hankala, Visa (July 1, 2019). "Switch the default compiler on octeon to clang" (Mailing list). Archived from the original on April 8, 2022. Retrieved August 27, 2020.
- ^ "LLVM 9 Releases With Official RISC-V Target Support, Asm Goto, Clang 9, And More". riscv.org. September 26, 2019. Archived from the original on December 28, 2019. Retrieved September 26, 2019.
- ^ "FreeBSD svn commit r358454". February 29, 2020. Archived from the original on March 10, 2020. Retrieved March 7, 2020.
- ^ Kettenis, Mark (April 2, 2020). "Switch the default compiler on powerpc to clang" (Mailing list). Archived from the original on April 8, 2022. Retrieved August 27, 2020.
- ^ Hankala, Visa (December 21, 2020). "Make clang the default compiler on loongson" (Mailing list). Archived from the original on January 13, 2021. Retrieved January 1, 2021.