clangify2010: Using the Analyzer with Visual Studio 2010
The Clang Static Analyzer has only limited support right now for Visual Studio users. Some users might find the Clangify2010.py script useful (described below) for analyzing their projects. It does not provide the same functionality as scan-build (for example, it does not actually build Visual Studio projects to analyze source files nor does it have a UI for viewing results) but some users may still find it useful.
We encourage anyone who is interested in developing support/integration of the Clang Static Analyzer with Visual Studio to get involved in clang development.
Important Caveats
- Clang doesn't support all Microsoft extensions implemented in Visual C/C++.
- The Clang Static Analyzer currently has very remedial and experimental support for analyzing C++ code. It will frequently crash.
- clangify2010.py strives to be as easy to read and modify as possible. If it does not quite suit your needs, you can always tweak it to make it work the way you want it to work.
- This script is provided as-is. Currently no technical support is available until we have someone to champion the development of the static analyzer on Windows.
Requirements
- You have a C or C++ Visual Studio 2010 project.
- You have Python 3.x (get the latest version here) in your PATH.
- You have clang + llvm (get the latest version here) in your PATH.
- Your project does not have automatically generated intermediate files as part of the build step. You can possibly work around this limitation by adding a custom pre_analysis function to Clangify2010.py.
- The source files in your project all take the same compiler flags.
Usage
Step 1: Download the script
Assuming you have met all of the above requirements, you should first download and copy clangify2010.py to wherever your project resides. Alternatively you can put the script in a global location and add it to your PATH.
Step 2: Running the script
Once you have obtained clangify2010.py say you have a project file called Foo.vcxproj, holding 300 .cpp files. To run the analyzer on all these files, just type the following at the Windows command prompt:
clangify2010.py Foo.vcxproj
clangify2010.py will automatically scan your project file for all your C++ files and hand them off to the Clang Static Analyzer for analysis.. Additionally, you could run the script as a post-build step to your project.