It is unclear how scan-build overrides the CC

The scan-build site states:

scan-build has little or no knowledge about how you build your code. It works by overriding the CC and CXX environment variables to (hopefully) change your build to use a “fake” compiler instead of the one that would normally build your project.

However, through experimentation, I have found that running scan-build make with a Makefile that contains an explicit assignment CC := <something>, scan-build still works, even though environment variables don’t override explicit assignments in Makefiles. Does scan-build have a special case for make that calls make with a CC=…/ccc-analyzer command-line argument?

Here is a terminal session demonstrating this:

~/Documents$ bat 
       │ File:
   1   │ CC := echo
   2   │ all:
   3   │     $(CC) $@
~/Documents$ make -f 
echo all
~/Documents$ CC=clang make -f 
echo all
~/Documents$ scan-build make -f 
scan-build: Using '/nix/store/p2i411dpdfh3nv41fgn77y9cqvbd8bqs-clang-wrapper-14.0.6/bin/clang' for static analysis
/nix/store/76qrr5dksjzljr0vwqwdfycbxx6q39fs-clang-analyzer-14.0.6/bin/../libexec/ccc-analyzer all
clang-14: error: no such file or directory: 'all'
make: *** [ all] Error 1
scan-build: Analysis run complete.
scan-build: Removing directory '/tmp/scan-build-2023-05-14-023619-329036-1' because it contains no reports.
scan-build: No bugs found.
~/Documents [2]$ 

It’s as you suspect, there’s a special case for make: llvm-project/scan-build at c04bcadf30ee07d437a238f78c2fb2c90be5c40c · llvm/llvm-project · GitHub

1 Like

Thank you!

I believe this should be made clear in the documentation. Is it possible to make changes to the documentation?

Yup it lives in llvm-project/scan-build.html at main · llvm/llvm-project · GitHub so you can send patches through Phabricator as usual.

I can try to fix this myself but it’s probably also valuable if you phrase it in a way that’s ideal for you as a reader who actually encountered the problem :sweat_smile: