Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What are the pros and cons of GCC vs clang/LLVM?

share|improve this question

closed as not constructive by gnat, MichaelT, 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.

3  
Pros/Cons for whom? LLVM is clearly superior as backend for compilers, except if you require a ridiculous amount of supported architectures. But I assume you're talking about end users. –  delnan Apr 22 '11 at 22:52

4 Answers 4

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.

share|improve this answer
  1. 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.

  2. 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.

  3. 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.

  4. 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).

  5. 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.

  6. 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).

  7. 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.

  8. (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.

share|improve this answer

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 ones 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.

share|improve this answer
    
+1 for expressing the legality of the matter. –  user54262 May 17 '12 at 7:36

Today (8/11/2011), GCC supports a lot more of the C++0x features than Clang does. If you want those features, it's a no-brainer; GCC is your option.

share|improve this answer
    
This answer is accurate and informative within the time frame specified according to my research. –  user54262 May 17 '12 at 7:35
7  
But is not a very good answer really, because as of today (28/07/2012) it's point is no longer valid. Clang supports more than GCC, if anything. –  DeadMG Jul 28 '12 at 1:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.