Clang patching

Dovecot is developed with some extra warning features developed for clang. Here’s how to build such a patched clang.


To build llvm/clang, you’ll need cmake version 3.4.3.

Source Repos

There are github mirrors, but you can clone directly from

git clone
cd tools
git clone

Here are some hints on how to build/hack clang:

  • If you want to debug clang with gdb, you need to have a debug build. This used to be the default, but apparently not nowadays. Note that Debug build takes ~15 GB of space vs non-debug build 5 GB. cmake -DCMAKE_BUILD_TYPE=Debug

  • With debug build you still want it to be optimized or the resulting compiler will be horribly slow. cmake -DLLVM_OPTIMIZED_TABLEGEN=ON

  • Even then it seems to be very slow. It’s possibly enough to use -DCMAKE_BUILD_TYPE=RelWithDebInfo

mkdir build
cd build
Makefiles" ../

If you want to debug clang, you need to debug “clang -cc1” because otherwise it forks a new process and you can’t do much with it. See

Dovecot Patches

Dovecot has some clang patches in

These patches aid with sanity checking the dovecot build, e.g. static code analysis:

  • clang-strict-bool.diff - This is the most important one that implements -Wstrict-bool

  • clang-default-nonnull.diff - Add support for automatically marking pointer parameters as non-null. This was never fully implemented to work nicely.