Building clang's static analyzer on Windows

Hi everybody,

I’d like to evaluate the usage of Clang’s static analyzer on our C++ code. However, there do not seem to be pre-compiled binaries (why? Too early in the project’s lifecycle?), so I tried to build it myself, following the advice from here:

http://pete.akeo.ie/2011/10/building-and-running-clang-static.html

This works fine until issuing make in step 5 of the process, where I’m running into compile problems. Below’s the output of my compilation attempt – does anybody have an idea on what’s going on here?

Thanks in advance,

Christian

Output of make:

make[1]: Entering directory `/src/build/lib/Support’

llvm[1]: Compiling APFloat.cpp for Release+Asserts build

llvm[1]: Compiling APInt.cpp for Release+Asserts build

llvm[1]: Compiling APSInt.cpp for Release+Asserts build

llvm[1]: Compiling ARMBuildAttrs.cpp for Release+Asserts build

llvm[1]: Compiling ARMWinEH.cpp for Release+Asserts build

llvm[1]: Compiling Allocator.cpp for Release+Asserts build

llvm[1]: Compiling Atomic.cpp for Release+Asserts build

llvm[1]: Compiling BlockFrequency.cpp for Release+Asserts build

llvm[1]: Compiling BranchProbability.cpp for Release+Asserts build

llvm[1]: Compiling COM.cpp for Release+Asserts build

llvm[1]: Compiling CommandLine.cpp for Release+Asserts build

llvm[1]: Compiling Compression.cpp for Release+Asserts build

llvm[1]: Compiling ConvertUTF.c for Release+Asserts build

llvm[1]: Compiling ConvertUTFWrapper.cpp for Release+Asserts build

llvm[1]: Compiling CrashRecoveryContext.cpp for Release+Asserts build

llvm[1]: Compiling DAGDeltaAlgorithm.cpp for Release+Asserts build

llvm[1]: Compiling DataExtractor.cpp for Release+Asserts build

llvm[1]: Compiling DataStream.cpp for Release+Asserts build

llvm[1]: Compiling Debug.cpp for Release+Asserts build

llvm[1]: Compiling DeltaAlgorithm.cpp for Release+Asserts build

llvm[1]: Compiling Dwarf.cpp for Release+Asserts build

llvm[1]: Compiling DynamicLibrary.cpp for Release+Asserts build

In file included from D:/Clang/msys/1.0/src/llvm/lib/Support/DynamicLibrary.cpp:40:0:

D:/Clang/msys/1.0/src/llvm/lib/Support/Windows/DynamicLibrary.inc:34:56: error: ‘PENUMLOADED_MODULES_CALLBACK64’ has not been declared

typedef BOOL (WINAPI *fpEnumerateLoadedModules)(HANDLE,PENUMLOADED_MODULES_CALLBACK64,PVOID);

^

D:/Clang/msys/1.0/src/llvm/lib/Support/Windows/DynamicLibrary.inc: In static member function ‘static llvm::sys::DynamicLibrary llvm::sys::DynamicLibrary::getPermanentLibrary(const char*, std::string*)’:

D:/Clang/msys/1.0/src/llvm/lib/Support/Windows/DynamicLibrary.inc:70:65: error: invalid conversion from ‘BOOL (attribute((stdcall)) )(PSTR, DWORD64, ULONG, PVOID) {aka int (attribute((stdcall)) )(char, long long unsigned int, long unsigned int, void)}’ to ‘int’ [-fpermissive]

fEnumerateLoadedModules(GetCurrentProcess(), ELM_Callback, 0);

^

/bin/rm: cannot lstat `/usr/src/build/lib/Support/Release+Asserts/DynamicLibrary.d.tmp’: No such file or directory

make[1]: *** [/usr/src/build/lib/Support/Release+Asserts/DynamicLibrary.o] Error 1

make[1]: Leaving directory `/src/build/lib/Support’

make: *** [all] Error 1

Hi again,

no answer so far, so let me rephrase my question: Has anybody managed to build a recent version of the static analyzer for Windows platforms? If this is the case, would she or he be willing to share the executable with me?

Thanks in advance,

Christian

Hi once more,

ok, this is my final attempt to get some feedback. In the meantime, I have performed another try to build clang plus tooling, this time following the official documentation at http://clang.llvm.org/get_started.html - however, CMake fails due to several missing include files (due to the lack of any response on this mailing list, I save you and me the time of adding the error log to my mail). I have also discovered http://llvm.org/releases/ , where Windows distributions are available, but they do not seem to contain the static analyzer at all. I’m tempted to think that building the static analyzer on Windows is not possible or at least very difficult – otherwise, why should it be missing in the official distributions?

Therefore, my last question (which is probably mostly directed to the moderators of this list) is: Am I asking at the right place? I chose this mailing list since I do not want to develop the static analyzer, I just want to use it…

All the best

Christian

Hi Christian,

here are clang binaries generated with MinGW and VS:

clang_MinGW.exe
clang_VS.exe download instruction:

download.jpg

D:/Clang/msys/1.0/src/llvm/lib/Support/Windows/DynamicLibrary.inc:34:56:
error: 'PENUMLOADED_MODULES_CALLBACK64' has not been declared

typedef BOOL (WINAPI
*fpEnumerateLoadedModules)(HANDLE,PENUMLOADED_MODULES_CALLBACK64,PVOID);
                                                        ^

D:/Clang/msys/1.0/src/llvm/lib/Support/Windows/DynamicLibrary.inc: In static
member function 'static llvm::sys::DynamicLibrary
llvm::sys::DynamicLibrary::getPermanentLibrary(const char*, std::string*)':

D:/Clang/msys/1.0/src/llvm/lib/Support/Windows/DynamicLibrary.inc:70:65:
error: invalid conversion from 'BOOL (__attribute__((__stdcall__)) *)(PSTR,
DWORD64, ULONG, PVOID) {aka int (__attribute__((__stdcall__)) *)(char*, long
long unsigned int, long unsigned int, void*)}' to 'int' [-fpermissive]

     fEnumerateLoadedModules(GetCurrentProcess(), ELM_Callback, 0);

PENUMLOADED_MODULES_CALLBACK64 and PENUMLOADED_MODULES_CALLBACKW64 are
declared in DbgHelp.h. See

Open the file giving you trouble, and manually add the include.

Or, open the file in question and manually add the typedef. The
typedef is provided on the MSDN page.

(If you are building LLVM/Cfe/Tools/etc from scratch, be prepared for
some of this sort of thing).

Jeff

ok, this is my final attempt to get some feedback. In the meantime, I have
performed another try to build clang plus tooling, this time following the
official documentation at http://clang.llvm.org/get_started.html - however,
CMake fails due to several missing include files (due to the lack of any
response on this mailing list, I save you and me the time of adding the
error log to my mail). I have also discovered http://llvm.org/releases/ ,
where Windows distributions are available, but they do not seem to contain
the static analyzer at all. I’m tempted to think that building the static
analyzer on Windows is not possible or at least very difficult – otherwise,
why should it be missing in the official distributions?

You received quite a number of replies:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2015-July/thread.html.
(More than some people get for interesting issues).

Maybe your mail server is blocking the messages? (In which case, this
won't get through either).

Jeff

Hi Christian,

Unfortunately I'm limited to only e-mails now but I'll try to assist you.
First of all, you don't need to build the static analyser separately.
Static analyser is a part of clang executable. To evaluate the
analyser over a single file or a set of files you just need to run the
clang.exe with the --analyze option (explore output from "clang -help"
for additional analyser options). Typical example:
clang.exe -cc1 -analyzer-checker=core,unix.Malloc -analyze test.cpp
I've sent you two versions of clang executables for windows one
compiled with MinGW, other with VS, did you received them?

If you want to evaluate the static analyser over a make project you
also need the scan-build, ccc-analyser and c++-analyzer perl scripts.
You can get them from the repository if they are missing in Windows
distributions. ccc-analyser.bat and c++-analyzer.bat scripts may also
be helpful in running the analyser under Windows. You obviously need
Perl to be installed to run analyser scripts. scan-build script has
several command-line options, you may check them simply running ''perl
scan-build". --use-analyzer=[path to clang executable] is the one you
exactly need.
There is a site devoted to the analyser:
http://clang-analyzer.llvm.org, check it for additional information.