Compiling Gimp with LLVM/Clang and static analyse

Clang, which use LLVM infrastructure, is a compiler for the C language family. His goal is to offer a moder alternative to GCC. With Clang come a pretty cool static analyser. Here is how to use it for Gimp.

A small disclaimer before, I shamefully copied and adapted the procedure given by Campbell Barton, form the Blender team. (

Step 1: compile LLVM/Clang

I first tried the LLVM provided by ArchLinux, but the compilation ended with a fatal error. It goes flawlessly with the development version. To fetch it, Campbell Barton’s script works well.

Step 2: configure Gimp’s compilation

First, we need to add  LLVM’s binary to the PATH:

export PATH=$PATH:/opt/llvm/bin

The only difference with a classic GCC compilation, is that we explicitly ask to use Clang’s compiler:

CC=ccc-analyzer ./ --prefix=/opt/gimp/

Step 3: compile

If you just want to compile, the procedure doesn’t change.

make -j3

If you want to run a static analyse, you have to use scan-build:

scan-build -o clang make -j3

Just be aware that a static analyse will take a lot of time (3h40 with my Core 2 Duo E4500).

Etape 4: profit !

The static analyzer of Clang will probably find a lot of bug in the code. Yes, there is false positive, but it’s globally remarkably well done ! You can find here the result of the analyse of master i did today:

3 Responses to “Compiling Gimp with LLVM/Clang and static analyse”

  • Malix0:

    Hi Michael,

    I think that for a correct analysis some filter are needed. I have analyzed some “Dereference of null pointer” alert and in every case the instruction is preceded by a the functions g_return_if_fail(), g_return_val_if_fail(). So if I’m not wrong those are all false positive.