Clang

is a compiler for C family of languages using LLVM as a backend and optimizer. It aims to be GCC compatible yet stricter.

Using clang with portage
Although Gentoo package tree is not designed to be used with compiler other than GCC, clang can be enforced on most of the packages through CC and CXX variables.

Please note, however, that many of Gentoo packages still don't build with clang and a few don't work correctly after being built. That's why we suggest using /etc/portage/env file to enable the use of clang per-package.

In order to do that, first create a new environment override to use:

Then you can enable use of clang for packages using /etc/portage/package.env file:

If you have installed, the /etc/portage/package.env file could be modified using:

Enabling link-time optimizations
The link-time optimization feature defers optimizing the resulting executables to linking phase. This can result in better optimization of packages but is unsupported in Gentoo yet, and many packages simply fail to build.

When using LTO, clang compiles units into LLVM byte-code rather than machine code. In order to support linking such object files, the gold linker must be installed and set as the default linker. If that's done, you can create a new environment override profile for LTO-enabled clang:

Note that the link-time optimizations were indirectly enabled here via -O4. If you don't want to enable other optimizations enforced by -O3, please use -flto instead. You may also need to adjust the libdir path.

Using clang with distcc
In order to use clang on distcc client, additional symlinks have to be created in /usr/lib*/distcc/bin: