[cfe-users] Using clang for static analysis only from Visual Studio

Michael Mortensen mgmortensen at gmail.com
Mon Apr 20 10:05:03 PDT 2015


I would like to create a StaticAnalysis configuration within a Visual
Studio (2012) Solution/set of projects that will just run clang-cl.exe
--analyze for each of the source files in each project in the solution. We
have both Mac and Windows versions of our product and want a common tool
and output format to add static analysis to our process.

I have created batch files based on the MSBuild command that is actually
issued by Visual Studio to generate all the plist output files. The batch
files and supporting files capture all the settings that need to be added
and removed to invoke a successful analysis run for each source file.
[Already, I have been able to clean up quite a number of potential error
areas.] I have attached samples; the .bat file's extension was changed to
.txt get around the email/attachment filter.

Is there a preferred way to integrate the clang analysis? My batch files
always execute the clang command for every file. This is far too time
consuming. Some of my projects have 100s of files. MSBuild already knows
what has changed and needs to be re-compiled (taking into account all the
dependencies), so I want to benefit from that, except checking for the
plist time stamp instead of the .obj file's timestamp. I also need to avoid
additional maintenance to keep the clang analysis configuration in synch as
source files are added or removed from each project.

The suggested method of changing the platform toolset does not work for me.
I still need to do a normal build (using Microsoft's compiler), not a
complete switch to clang. And when calling clang-cl --analyze, object files
are not created so the link step fails.

I hope this is the right forum and that I have given enough information but
not included too much.

Thank you, Michael Mortensen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20150420/6eb05fd9/attachment.html>
-------------- next part --------------
 C:\projects\Software\Common\ControlPanel\C3FingerGestureBehaviorData.cpp
 C:\projects\Software\Common\ControlPanel\CABOrientationItemView.cpp
 C:\projects\Software\Common\ControlPanel\CAboutSuperView.cpp
 C:\projects\Software\Common\ControlPanel\AddFingerTextItemView.cpp
 C:\projects\Software\Common\ControlPanel\CCompositeFunctionsObject.cpp
 C:\projects\Software\Common\ControlPanel\CConsumerOrientationData.cpp
 C:\projects\Software\Common\ControlPanel\CFingerWheelView.cpp
 C:\projects\Software\Common\ControlPanel\CMetaComposite.cpp
 C:\projects\Software\Common\ControlPanel\COnScreenCollectionDG.cpp
 C:\projects\Software\Common\ControlPanel\Consumer\CCT_IWBatteryGroupView.cpp
 C:\projects\Software\Common\ControlPanel\Consumer\CCT_IWOrientationModeView.cpp
 C:\projects\Software\Common\ControlPanel\Consumer\CCT_IWTabletButtonsGroupView.cpp
 C:\projects\Software\Common\ControlPanel\Consumer\CCT_IWTabletView.cpp
 C:\projects\Software\Common\ControlPanel\Consumer\CCT_IWTobagoBatteryGroupView.cpp
 C:\projects\Software\Common\ControlPanel\Consumer\CCT_IWTobagoTabletView.cpp
 C:\projects\Software\Common\ControlPanel\Consumer\CCT_OrientationTobagoModeView.cpp
 C:\projects\Software\Common\ControlPanel\CStringifyEnums_ControlPanel.cpp
 C:\projects\Software\Common\ControlPanel\CTabletTiltAnglesItemView.cpp
 C:\projects\Software\Common\ControlPanel\CWirelessIDItemView.cpp
 C:\projects\Software\Common\ControlPanel\DataTranslators\CDataTranslator.cpp
 C:\projects\Software\Common\ControlPanel\DataTranslators\CDoubleRangeToIndexDataTranslator.cpp
 C:\projects\Software\Common\ControlPanel\DataTranslators\CDoubleValuesToIndexDataTranslator.cpp
 C:\projects\Software\Common\ControlPanel\DataTranslators\CNegateBoolDataTranslator.cpp
 C:\projects\Software\Common\ControlPanel\DataTranslators\CRangeToDoubleTranslator.cpp
 C:\projects\Software\Common\ControlPanel\FingerWheelMenuView.cpp
 C:\projects\Software\Common\CStringifyEnums_Common.cpp
 C:\projects\Software\Common\CSystemState.cpp
 C:\projects\Software\Common\CTimer.cpp
 C:\projects\Software\Common\CVotes.cpp
 C:\projects\Software\Common\ProductIDUtils.cpp
 C:\projects\Software\Common\Settings\CSettingsBytes.cpp
 C:\projects\Software\Common\TabletDriverInterface.cpp
 C:\projects\Software\Common\UHMappingUtils.cpp
 C:\projects\Software\Win\Common\importWin32API.cpp
 C:\projects\Software\Win\Common\nttimer.cpp
 C:\projects\Software\Win\Common\WinPathUtils.cpp
 C:\projects\Software\Win\Common\WinSystemState.cpp
 C:\projects\Software\Win\Common\WinTabletDriverInterface.cpp
 C:\projects\Software\Win\ControlPanel\aboutdlg.cpp
 C:\projects\Software\Win\ControlPanel\advdlg.cpp
 C:\projects\Software\Common\ControlPanel\CAdvancedSuperView.cpp
-------------- next part --------------

@rem sample usage
@rem for /f "delims=" %F in (ControlPanel_Con_list.txt) do @call ControlPanel_Con_analyze.bat %F

@if [%1] == [] goto end
@if [%1] == [""] goto end
@if [%1] == [x] goto end
@if [%1] == [d] goto end

@set PATH=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin
@set PATH=%PATH%;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\bin
@set PATH=%PATH%;C:\Program Files (x86)\Windows Kits\8.0\bin\x86
@set PATH=%PATH%;C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools
@set PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\bin
@set PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\tools
@set PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\ide
@set PATH=%PATH%;C:\Program Files (x86)\HTML Help Workshop
@set PATH=%PATH%;C:\Windows\Microsoft.NET\Framework\v4.0.30319
@set PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 11.0
@set PATH=%PATH%;C:\Windows\SysWow64
@set PATH=%PATH%;C:\Windows\Microsoft.NET\Framework\v3.5
@set PATH=%PATH%;C:\Program Files\WinRAR
@set PATH=%PATH%;C:\Perl64\site\bin
@set PATH=%PATH%;C:\Perl64\site\lib
@set PATH=%PATH%;C:\Perl64\bin
@set PATH=%PATH%;C:\Users\mmortensen\Documents\etc
@set PATH=%PATH%;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
@set PATH=%PATH%;C:\ProgramData\Oracle\Java\javapath
@set PATH=%PATH%;C:\Windows\system32
@set PATH=%PATH%;C:\Windows
@set PATH=%PATH%;C:\Windows\System32\Wbem
@set PATH=%PATH%;C:\Windows\System32\WindowsPowerShell\v1.0
@set PATH=%PATH%;C:\Program Files\Microsoft\Web Platform Installer
@set PATH=%PATH%;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0
@set PATH=%PATH%;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit
@set PATH=%PATH%;C:\Program Files\Microsoft SQL Server\110\Tools\Binn
@set PATH=%PATH%;C:\Program Files (x86)\Seapine\Surround SCM
@set PATH=%PATH%;C:\Program Files (x86)\Seapine\TestTrack

@set LIB=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib
@set LIB=%LIB%;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\lib
@set LIB=%LIB%;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\lib

@set LIBPATH=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\lib
@set LIBPATH=%LIBPATH%;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib

@set INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include
@set INCLUDE=%INCLUDE%;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include
@set INCLUDE=%INCLUDE%;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\include
@set INCLUDE=%INCLUDE%;C:\WinDDK\7600.16385.1\inc\api
@set INCLUDE=%INCLUDE%;C:\WinDDK\7600.16385.1\inc\ddk
@set INCLUDE=%INCLUDE%;C:\WinDDK\7600.16385.1\inc

@set VS_UNICODE_OUTPUT=1468

@rem "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\CL.exe" ^
@rem   /MP ^
@rem   /Gm- ^
@rem   /GS ^
@rem   /fp:precise ^
@rem   /Yu"PrecompiledHeader.h" ^
@rem   /Fp"Win32\DebugCon\PrefUtil.pch" ^
@rem   /Fd"Win32\DebugCon\vc110.pdb" ^

@"C:\LLVM-3.7.0svn-win32\bin\clang-cl.exe" ^
-v ^
--analyze ^
/c ^
/I.\Consumer ^
/I..\..\Common\ControlPanel\Consumer ^
/I..\..\Common\ControlPanel ^
/I..\..\Common\ControlPanel\DataTranslators ^
/I"..\..\..\3rd Party\ZAF\Include" ^
/I. ^
/I..\Common ^
/I..\..\Common ^
/I..\..\Common\Settings ^
/I"..\..\..\3rd Party\boost_dist\include" ^
/I"..\..\..\3rd Party\openssl_dist\include" ^
/I"..\..\..\3rd Party\libxml2\include" ^
/I"..\..\..\3rd Party\wtl\include" ^
/I"..\..\..\3rd Party\zlib_dist\include" ^
/Zi ^
/nologo ^
/W4 ^
/WX ^
/Od ^
/Oy- ^
/D NO_DRIVER ^
/D SETTING_OBJ_IN_ENVENTS ^
/D SETTINGS_OBJECTS_COMPRESSED_BINARY ^
/D DEBUG ^
/D _DEBUG ^
/D _HAS_ITERATOR_DEBUGGING ^
/D WIN32 ^
/D _WINDOWS ^
/D PLATFORM_WIN ^
/D WINVER=0x0700 ^
/D _WIN32_WINNT=0x0700 ^
/D BOOST_ALL_NO_LIB ^
/D _CRT_SECURE_NO_WARNINGS ^
/D _SCL_SECURE_NO_WARNINGS ^
/D _CRT_SECURE_NO_DEPRECATE ^
/D _SCL_SECURE_NO_DEPRECATE ^
/D CLANG_ANALYSIS_BUILD ^
/D _USING_V110_SDK71_ ^
/D _MBCS ^
/D BOOST_TYPEOF_EMULATION ^
/D BOOST_USE_WINDOWS_H ^
/D BOOST_NO_CXX11_CHAR16_T ^
/D BOOST_NO_CXX11_CHAR32_T ^
/EHsc ^
/RTC1 ^
/MDd ^
/Zc:wchar_t ^
/Zc:forScope ^
/Fo"Win32\DebugCon\\" ^
/Gd ^
/TP ^
/wd4995 ^
/FIPrecompiledHeader.h ^
/analyze- ^
/errorReport:prompt ^
/Zm200 ^
-Wno-invalid-token-paste ^
/D _HAS_EXCEPTIONS=0 ^
/D __clang_analyzer__ ^
-Xclang -analyzer-output=plist-multi-file ^
-Xclang -analyzer-config -Xclang path-diagnostics-alternate=true ^
-Xclang -analyzer-config -Xclang report-in-main-source-file=true ^
-Xclang -analyzer-checker -Xclang security.FloatLoopCounter ^
-Xclang -analyzer-checker -Xclang security.insecureAPI.UncheckedReturn ^
-Xclang -analyzer-checker -Xclang security.insecureAPI.getpw ^
-Xclang -analyzer-checker -Xclang security.insecureAPI.gets ^
-Xclang -analyzer-checker -Xclang security.insecureAPI.mkstemp ^
-Xclang -analyzer-checker -Xclang security.insecureAPI.mktemp ^
-Xclang -analyzer-checker -Xclang security.insecureAPI.rand ^
-Xclang -analyzer-checker -Xclang security.insecureAPI.strcpy ^
-Xclang -analyzer-checker -Xclang security.insecureAPI.vfork ^
%~s1 2>fail.txt

@if not exist %~sn1.plist goto fail_report
@if exist StaticAnalysis\Consumer\%~n1_fail.txt del StaticAnalysis\Consumer\%~n1_fail.txt
@echo Pass : %~1
@if not [%~sn1] == [%~n1] ren %~sn1.plist %~n1.plist
@call move_to.bat %~n1.plist StaticAnalysis\Consumer
@if exist fail.txt del fail.txt
@goto end

:fail_report
@echo Fail : %~1
@rem if exist fail.txt type fail.txt
@if exist fail.txt copy fail.txt %~n1_fail.txt
@if exist %~n1_fail.txt call move_to.bat %~n1_fail.txt StaticAnalysis\Consumer

:end


More information about the cfe-users mailing list