Clang vs Other Open Source Compilers

分享一篇文章, clang官方文章:https://clang.llvm.org/comparison.html

Clang vs Other Open Source Compilers

Building an entirely new compiler front-end is a big task, and it isn't always clear to people why we decided to do this. Here we compare Clang and its goals to other open source compiler front-ends that are available. We restrict the discussion to very specific objective points to avoid controversy where possible. Also, software is infinitely mutable, so we don't talk about little details that can be fixed with a reasonable amount of effort: we'll talk about issues that are difficult to fix for architectural or political reasons.

The goal of this list is to describe how differences in goals lead to different strengths and weaknesses, not to make some compiler look bad. This will hopefully help you to evaluate whether using Clang is a good idea for your personal goals. Because we don't know specifically what you want to do, we describe the features of these compilers in terms of our goals: if you are only interested in static analysis, you may not care that something lacks codegen support, for example.

Please email cfe-dev if you think we should add another compiler to this list or if you think some characterization is unfair here.

Clang vs GCC (GNU Compiler Collection)

Pro's of GCC vs Clang:

  • GCC supports languages that Clang does not aim to, such as Java, Ada, FORTRAN, Go, etc.
  • GCC supports more targets than LLVM.
  • GCC supports many language extensions, some of which are not implemented by Clang. For instance, in C mode, GCC supports nested functions and has an extension allowing VLAs in structs.

Pro's of Clang vs GCC:

  • The Clang ASTs and design are intended to be easily understandable by anyone who is familiar with the languages involved and who has a basic understanding of how a compiler works. GCC has a very old codebase which presents a steep learning curve to new developers.
  • Clang is designed as an API from its inception, allowing it to be reused by source analysis tools, refactoring, IDEs (etc) as well as for code generation. GCC is built as a monolithic static compiler, which makes it extremely difficult to use as an API and integrate into other tools. Further, its historic design and current policy makes it difficult to decouple the front-end from the rest of the compiler.
  • Various GCC design decisions make it very difficult to reuse: its build system is difficult to modify, you can't link multiple targets into one binary, you can't link multiple front-ends into one binary, it uses a custom garbage collector, uses global variables extensively, is not reentrant or multi-threadable, etc. Clang has none of these problems.
  • Clang does not implicitly simplify code as it parses it like GCC does. Doing so causes many problems for source analysis tools: as one simple example, if you write "x-x" in your source code, the GCC AST will contain "0", with no mention of 'x'. This is extremely bad for a refactoring tool that wants to rename 'x'.
  • Clang can serialize its AST out to disk and read it back into another program, which is useful for whole program analysis. GCC does not have this. GCC's PCH mechanism (which is just a dump of the compiler memory image) is related, but is architecturally only able to read the dump back into the exact same executable as the one that produced it (it is not a structured format).
  • Clang is much faster and uses far less memory than GCC.
  • Clang has been designed from the start to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. Modern versions of GCC have made significant advances in this area, incorporating various Clang features such as preserving typedefs in diagnostics and showing macro expansions, but GCC is still catching up.
  • GCC is licensed under the GPL license. Clang uses a BSD license, which allows it to be embedded in software that is not GPL-licensed.
  • Clang inherits a number of features from its use of LLVM as a backend, including support for a bytecode representation for intermediate code, pluggable optimizers, link-time optimization support, Just-In-Time compilation, ability to link in multiple code generators, etc.
  • Clang's support for C++ is more compliant than GCC's in many ways.
  • Clang supports many language extensions, some of which are not implemented by GCC. For instance, Clang provides attributes for checking thread safety and extended vector types.

Clang vs Elsa (Elkhound-based C++ Parser)

Pro's of Elsa vs Clang:

  • Elsa's parser and AST is designed to be easily extensible by adding grammar rules. Clang has a very simple and easily hackable parser, but requires you to write C++ code to do it.

Pro's of Clang vs Elsa:

  • Clang's C and C++ support is far more mature and practically useful than Elsa's, and includes many C++'11 features.
  • The Elsa community is extremely small and major development work seems to have ceased in 2005. Work continued to be used by other small projects (e.g. Oink), but Oink is apparently dead now too. Clang has a vibrant community including developers that are paid to work on it full time. In practice this means that you can file bugs against Clang and they will often be fixed for you. If you use Elsa, you are (mostly) on your own for bug fixes and feature enhancements.
  • Elsa is not built as a stack of reusable libraries like Clang is. It is very difficult to use part of Elsa without the whole front-end. For example, you cannot use Elsa to parse C/ObjC code without building an AST. You can do this in Clang and it is much faster than building an AST.
  • Elsa does not have an integrated preprocessor, which makes it extremely difficult to accurately map from a source location in the AST back to its original position before preprocessing. Like GCC, it does not keep track of macro expansions.
  • Elsa is even slower and uses more memory than GCC, which itself requires far more space and time than Clang.
  • Elsa only does partial semantic analysis. It is intended to work on code that is already validated by GCC, so it does not do many semantic checks required by the languages it implements.
  • Elsa does not support Objective-C.
  • Elsa does not support native code generation.

Clang vs PCC (Portable C Compiler)

Pro's of PCC vs Clang:

  • The PCC source base is very small and builds quickly with just a C compiler.

Pro's of Clang vs PCC:

  • PCC dates from the 1970's and has been dormant for most of that time. The Clang and LLVM communities are very active.
  • PCC doesn't support Objective-C or C++ and doesn't aim to support C++.
  • PCC's code generation is very limited compared to LLVM. It produces very inefficient code and does not support many important targets.
  • Like Elsa, PCC's does not have an integrated preprocessor, making it extremely difficult to use it for source analysis tools.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
gcc/clang是常见的C/C++编译器,而VS Code和Vim则是两种流行的文本编辑器。下面我将分别介绍它们的特点和用途。 gccclang是两种开源的编译器,用于将C/C++源代码转换为可执行文件。它们都具有高度的兼容性和优化功能,支持多个操作系统。gcc是GNU编译器集合的一部分,被广泛用于Linux系统,而clang则是一个较新的编译器,具有更好的错误报告和诊断功能。它们都有广泛的社区支持,并且被广泛应用于C/C++开发。 VS Code是一种功能强大的源代码编辑器,由微软开发,并支持各种编程语言。它具有丰富的插件生态系统,可以通过安装插件来扩展其功能。VS Code具有智能代码补全、调试功能、版本控制集成等特点,能够提高开发效率。它还支持多种操作系统,因此非常适合团队合作和跨平台开发。 Vim是一种经典的文本编辑器, UNIX系统上的“vi”的改进版本。它是一个模态编辑器,使用键盘快捷键进行操作,具有高度的定制性和可扩展性。Vim提供各种高级编辑功能,如宏录制、多重撤销和自动完成。由于其高效的编辑方式和卓越的性能,Vim经常被程序员用于编写代码和编辑文本文件。 总结来说,gcc/clang是用于编译C/C++代码的工具,而VS Code和Vim则是常见的代码编辑器。它们分别具有不同的特点和用途,根据个人需求和偏好可以选择适合自己的工具和编辑器。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值