Clang + ccache == different warnings?

After compiling my apps with clang 3.1, and fixing all the new warnings it found that gcc did not care about, I wanted to get clang + ccache working together. I set up a bash script "~/bin/clang" that looks like this:

  #!/bin/bash
  ccache /opt/local/bin/clang $@

Obviously this just calls ccache with the clang path and arguments. The surprising thing is that when I invoke clang this way, several classes of warnings are flagged that were not noticed when I ran /opt/local/bin/clang.

The above example is on OS X, where I've installed clang 3.1 via Macports. But I've reproduced the same effect on Linux using clang/llvm that I compiled from the svn (3.1 branch) as well.

Is this expected behavior? Does anybody have an explanation for what's going on here?

After compiling my apps with clang 3.1, and fixing all the new warnings it found that gcc did not care about, I wanted to get clang + ccache working together. I set up a bash script "~/bin/clang" that looks like this:

   \#\!/bin/bash
   ccache /opt/local/bin/clang $@

Obviously this just calls ccache with the clang path and arguments. The surprising thing is that when I invoke clang this way, several classes of warnings are flagged that were not noticed when I ran /opt/local/bin/clang.

The above example is on OS X, where I've installed clang 3.1 via Macports. But I've reproduced the same effect on Linux using clang/llvm that I compiled from the svn (3.1 branch) as well.

Is this expected behavior? Does anybody have an explanation for what's going on here?

The problem is that ccache give clang a preprocessed file to compile
and clang uses macro expansion context in its warnings. You might be
able to use CCACHE_CPP2 to avoid the problem.

--
Larry Gritz
lg@larrygritz.com

Cheers,
Rafael

You are hitting the same behavior as building with -save-temps.
Basically, a number of warnings check if they are the result of a macro
expansion. If yes, they get suppressed.

Joerg

clang has a few warnings which are suppressed for specific patterns in
macros; if you pass clang a preprocessed file, it can't see the
macros, so the warning output can change a bit.

-Eli

Presumably something like ccache could be changed to use a “preprocess headers only (& leave in line directives)” option like we’re adding to clang (under review at the moment) & that would mitigate this problem. (& make for possibly/marginally smaller files to send to distributed builders, etc)

  • David

I'll pick up that review again any day now :wink:

(Seriously, I'll try to take a look this weekend.)

-Matt