What are the pros and cons of GCC vs clang/LLVM?
closed as not constructive by gnat, user40980, Kilian Foth, Dynamic, Jalayn May 27 '13 at 19:23
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. If this question can be reworded to fit the rules in the help center, please edit the question.
gcc is very mature, easy to install (at least for most systems), and is the default compiler for lots of systems so in many cases people have it installed almost without even realizing it. Its been ported to a zillion architectures, so it's much more likely to work out of the box if you have to target obscure hardware.
clang is much newer. It frequently produces much better error messages, especially for C++ templates. In many cases, it runs a lot faster. It's built primarily as a set of libraries, so there are quite a few other projects (e.g., code analyzers) that use the same front-end, understand the same inputs, etc. Using llvm as its back end gives it some extra flexibility in how you generate code from it.
Clang has much better error reporting. E.g. if you make a typo in a function name you call, Clang will report that this is likely a typo (and suggest the correct name), while GCC will complain about unknown function name.
GCC usually produces faster code if you target x86/x86-64. For ARM the situation is ambiguous, often Clang optimizes better. Also, AFAIK Clang does not support optimization for code size.
GCC uses a lot of heuristics. This is good for performance (in a typical case), but awful if you want to do some source-level optimization (e.g. loop unrolling). Even small source code changes can make GCC generate a completely different output. Clang is more predictable, and usually it generates the code you expect.
Unlike Jerry Coffin, I find building GCC from source much harder than Clang. The procedure from Clang's Getting Started page always worked for me. Similar manual for GCC never worked in the first try. GCC has dependencies on particular versions of GMP, MPFR, MPC, Parma Polyhedra Library, and CLooG, and I needed several iterations to find the versions which would work for a particular GCC release (yes, using the latest versions of those libraries does not work).
I have a feeling that Clang is better tested than GCC. Even though I only use official releases of GCC, it sometimes produced faulty code. For Clang I usually use the trunk version (again, because it is easy to build), but I never saw it generating wrong output.
GCC is nearly standard in Linux world, and it adds a lot of non-standard features which are widely used in Linux software. Clang tries to be compatible with GCC, but sometimes it just quietly ignores them. Most importantly, Clang does not support OpenMP. However, it also has extensions which are not supported by GCC, but can be useful (e.g. add-with-carry intrinsic functions __buildin_addc).
If you want to do compiler research, or just curious about how it works, you will find Clang/LLVM source code more accessible. Clang/LLVM code is human-readable, not just compiler-readable.
(AINAL declaimer applies) Clang/LLVM license gives you more freedom about what you can do with the code, e.g. use in commercial or closed-source product. License for GCC runtime libraries adds another layer of restrictions while Clang compiler runtime (compiler-rt library) is under permissive MIT license.
Summary: compile with Clang when you develop the program, and with GCC for the final build (but make sure that its faster and doesn't break). Stick with Clang/LLVM if you do compiler research.
If you have a new CPU architecture or new optimizations, and want to open source them under the GPL, you can contribute them to gcc. However, gcc is less modular, so this may involve more work to add one's modifications/additions. If you want to contribute new architectures or optimizations to an open source project, but under a non-GPL license, you can contribute them to the LLVM/clang. There exist corporations whose legal departments only allow the latter.