2

I would like to use Clang's static analyzer for analyzing parallel code, i.e., code with needs MPI compiler wrappers. When configuring with CMake, however, I always get

$ scan-build cmake /path/to/source
-- Check for working CXX compiler: /usr/share/clang/scan-build/c++-analyzer
-- Check for working CXX compiler: /usr/share/clang/scan-build/c++-analyzer -- works

and the subsequent compilation (make) fails with

/usr/include/some/header.hpp:56:17: fatal error: mpi.h: No such file or directory

#include "mpi.h"

How to properly use scan-build here?

Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249

3 Answers3

3

I have not found a way to use the MPI compiler wrappers directly with scan-build. You can however circumvent the wrappers and give the flags to your compiler manually. e.g. this works for my environment:

$ export CXXFLAGS=`mpicxx --showme:compile`
$ export LDFLAGS=`mpicxx --showme:link`
$ export CXX=`mpicxx --showme:command`
$ scan-build ./configure && scan-build make #Or your cmake equivalent

The --showme: flags seem to differ slightly between versions, but mpicc --showme:help usually gives you a list of commands your specific wrapper supports.

Phobon
  • 61
  • 4
1

See MPI-Checker/examples :

To invoke the Clang Static Analyzer, it is recommended to use the scan-build package implemented in Python. You can either use the scripts being contained in LLVM trunk (llvm/tools/clang/tools/scan-build-py/bin) or install the scripts with pip install scan-build. Note that on make install LLVM copies old Perl versions of the scripts to /usr/local/bin which therefore might overwrite versions installed with pip.

As the MPI wrapper compiler interferes with the scan-build script, it is recommended to invoke the analysis based on a compilation database, generated by intercept-build (make|ninja|...). Note that databases generated by CMake can differ from those generated by intercept-build. If the compile_commands.json file denotes mpicc|mpic++ as the used compiler, no reports are emitted.

After the compilation database is created, analysis can be triggered with:
analyze-build --enable-checker your.check --use-analyzer /path/to/clang

0ax1
  • 475
  • 3
  • 11
0

You need to have a MPI wrapper for your c-compiler. Which means a MPI library compiled with CLang. After you got that, you need to set the c compiler in your build environment to mpicc. This should provide you with correct includes and linking options.

haraldkl
  • 3,809
  • 26
  • 44