Trouble Using scan-build in Windows 7

No, cfe-dev is the appropriate list for questions. (Or cfe-users, but to be honest we analyzer folks don’t follow that list much and you probably wouldn’t have gotten an answer there!)

scan-build is not installed with Clang or LLVM; I believe when the analyzer project first began it wasn’t clear if everyone would want it as a part of their default install. You can find the executables in tools\scan-build under your Clang source directory (probably llvm\tools\clang.)

I’ve CC’d Anton Yartsev, who I know has been running scan-build on Windows for some time. (Not sure which version, though.)
Jordan

Hi Jonathan,

To use the scan-build you should get the contents of clang\tools\scan-build from Clang sources as Jordan pointed out.
Currently the scan-build script expects the clang executables (clang.exe and clang++.exe) to live in ./clang or ./bin/clang directory relative to directory with the scan-build stuff but you can use the --use-analyzer=[Xcode|path to clang] scan-build option to tell scan-build where your clang executables live.
The last thing you should do is to add the path to scan-build to your PATH and then you should be able to use scan-build as it described in http://clang-analyzer.llvm.org/scan-build.html.
Hope I've not missed something.
Feel free to ask and point to problems.

mistake, ./ or ./bin

Anton and Jordan,

Thank you so much for your prompt replies. I appreciate the assistance you have and will be providing.

Anton,

So based on what you have sent me, then the Clang Static Analyzer, called via scan-build, was not provided in the svn checkout that I performed when getting Clang, is that correct? Is there an svn repository for it that I can check out, or do I just need to go to the source files and get it specifically and add it to the clang/tools directory of my directory?

I also noticed in the commands for clang there is an option for running a static analyzer, albeit I am not sure if they are different from one another and if they are different from the one run by scan-build command, when you pull up the help menu for the clang command. The options are -Xanalyzer and --analyze, if I am remembering those correctly. Could you explain these options to me a little more, if possible?

Regards,
Jon

Anton and Jordon,

So I got scan-build to fire off, and when I do it does another command with perl -S in front of it. Now I did not have perl originally install on my machine but since have gone and grabbed a copy of perl and installed it. Now when I run the scan-build command I get this error:

C:\Users\lockhaja\llvm\tools\clang\tools\scan-build>perl -S scan-build
The getpwuid function is unimplemented at scan-build line 35.

Now Patrik on the LLVM list point out this article to me:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2010-April/008659.html

I read through it and believe I may be using the ActiveState perl which appears not to work with scan-build. This would mean I would have to go grab another version. I am curious to know if I would have to perform all this changes that were described further in the digest, as I am on 7 not XP, and I would feel that the Static Analyzer has progressed since 2010 and its building on Windows.

I would be very interested in knowing your set up Anton.

Regards,
Jon

Now I see that it was a good idea to try MinGW first :slight_smile: I got the same error “getpwuid function is unimplemented” when tried to launch scan-build with ActiveState perl. Then I switched to perl from my MinGW+MSYS installation, and after little changes in scripts scan-build worked for me. I never tried to launch scan-build with Cygwin. Clang repository () holds the changes, allowing to use scan-build with MinGW+MSYS, since the revision 180905. Theoretically all you should do to get scan-build work is: 1) install MinGW+MSYS, get scan-build from 2) add the path to scan-build to your PATH environment variable 3) provide --use-analyzer=[Xcode|path to clang] option to scan-build Here is a random example of how I use scan-build: for configuring: scan-build -v -v -v -o “./” --use-analyzer=F:/llvm_COMMON/-Eclipse_build-/Release+Asserts/bin/clang.exe …/configure DISABLE_ASSERTIONS=1 for making: scan-build -v -v -v -o “./” --use-analyzer=F:/llvm_COMMON/-Eclipse_build-/Release+Asserts/bin/clang.exe make DISABLE_ASSERTIONS=1 -o “./” forces scan-build to put reports to the current folder DISABLE_ASSERTIONS=1 is a command passed to the configure/make, not scan-build Hope that helps.

Anton,

Well earlier today I uninstalled ActiveState perl for Strawberry perl and oddly enough I ran into the same error, “getpwuid function is unimplemented”, which means that apparently it isn’t just ActiveState perl that causes the problem.

Now I am surprised to hear you are using MinGW and that all I need is the MinGW installation with MSYS. I have that already installed, as I needed it for Eclipse with the C project I am working on, and it is already in my path. I also have the latest version of both llvm and clang from the trunk. I also added scan-build to my path. With all that I am still hitting the error I emailed back today.

Now I have not tried the example you provided so I will give that a shot and be sure to provide it the build folder for clang.exe and see if that takes care of the problem. Only other thing I can figure is that scan-build can’t find MinGW on my path though it is there.

I have also checked the MinGW\msys folder, and there is no perl in the bin folder.

Looks like I still got a bunch of problems left to figure out.

Regards,
Jon

Tried to install MinGW from the latest installer mingw-get-inst-20120426.exe () Found out that “MinGW Developer Toolkit” component should be selected during installation to have perl installed at \MinGW\msys\1.0\bin\

Anton,

Ah, that makes much more sense and would explain why when I installed mine I did not have perl in the msys folder, because I did not install the MinGW Developer Toolkit. A subtle yet foolish oversight on my part.

I will be sure to get the toolkit installed immediately and then see what shakes out.

Regards,
Jon

Anton,

Maybe we should add a page describing what it takes to run scan-build on Windows to the static analyzer website?

Cheers,
Anna.

Sure, I’ll see to it.

Anton,

Removing Active perl from my path, and installing the development toolkit for MinGW did the trick, scan-build is now a recognized command when it kicks off perl.

I am not having some difficulty with scan-build itself. Below is the following error I receive.

C:\Users\lockhaja\llvm\tools\clang\tools\scan-build>perl -S scan-build --use-analyzer=C:\Users\lockhaja\build\bin\Debug\clang.exe
scan-build: No build command specified.

scan-build: Cannot find an executable clang at ‘C:\Users\lockhaja\build\bin\Debug\clang.exe’

Now I know I do not have a build in place but I find it odd it can’t find an executable clang when I am telling ti exactly where to find it as per your instructions, as well I have that directory in my path and can just run “clang --help” and get the help menu to appear with all the flags it takes for input, etc.

I was also wondering is there a help menu with scan-build? I have tried running “scan-build -help” and “scan-build --help” and both come back that neither is a proper input to scan-build.

Regards,
Jon Lockhart

Anton,

Maybe we should add a page describing what it takes to run scan-build on Windows to the static analyzer website?

Added “For Windows Users” section to scan-build.html, will become actual after ‘[PATCH][analyzer][review request] scan-build port for windows’ patch gets in.
Could you please give a feedback on it? Mainly worry about syntax.

scan-build-win-users-html_v1.patch (1.63 KB)

+

By default scan-build searches for clang executables in ./ or ./bin paths relative to itself.
+Use --use-analyzer=[path to clang] option to explicitly provide path to your clang executables for scan-build:

Thanks for review! Updated the patch with your remarks considered. This documentation is for ordinary users, included the path to manual build by force of habit. Now when --use-analyzer is added to the list of generic options the example is removed. Also removed references to all perl ports except msys perl for now so the documentation is actual. Ok to commit?

scan-build-win-users-html_v2.patch (2.99 KB)

Thanks for review!Updated the patch with your remarks considered.This documentation is for ordinary users, included the path to manual build by force of habit. Now when --use-analyzer is added to the list of generic options the example is removed.Also removed references to all perl ports except msys perl for now so the documentation is actual.Ok to commit?

Let’s commit but only after the scan-build.bat is in.

Thanks!
Anna.

Committed at r185199, scan-build.bat is already in.