Warning, /Utilities/StaticAnalyzers/README.txt is written in an unsupported language. File is not indexed.
0001
0002 === CLANG CMS ===
0003
0004 This are the CMS clang static analyzer checkers to crawl C/C++ code for constructs which my become problematic when running multi-threaded code or do violate CMS Framework Rules.
0005
0006 by Thomas Hauth - Thomas.Hauth@cern.ch
0007
0008 This is still in early development/evaluation phase. You are welcome to contribute your commens and source code changes.
0009
0010 == Available Checks ==
0011
0012 * Non-const local statics
0013
0014 int foo()
0015 {
0016 static int myEvilLocalState;
0017 }
0018
0019 * Non-const global statics
0020
0021 static g_myGlobalStatic;
0022
0023 * use of the mutable keyword ( breaks const-corrcetness )
0024
0025 struct Foo{
0026 mutable int myEvilValue;
0027 };
0028
0029 * use of const_cast to remove const-ness
0030
0031 std::string s = "23";
0032 std::string const& r_const = s;
0033 std::string & r = const_cast< std::string & >( r_const );
0034
0035 * every explicit cast statement that removes const-ness
0036
0037 std::string s = "23";
0038 std::string const& r_const = s;
0039 std::string & r = (std::string &) ( r_const );
0040
0041 Dedicated Checkers exist for each of this code constructs.
0042
0043 == Compile LLVM / clang with this extensions ==
0044
0045 Follow the directions to obtain and compile LLVM/clang here:
0046
0047 http://clang.llvm.org/get_started.html#build
0048
0049 Stick to the directory structure suggested by this website, but run configure with the option --enable-optimized which will speed-up llvm/clang by some factors. Compile LLVM/clang and see if this is working. The root path of the LLVM subversion folder will in the following be aliased by . The folder where you built llvm is aliased
0050
0051 Now, checkout the repository which contains the CMS extensions into the same folder as <llvm_src> resides (CERN account needed):
0052
0053 svn co https://svn.cern.ch/reps/cmscoperformance/projects/clang_cms
0054
0055 and run
0056
0057 cmake .
0058 make
0059
0060 inside the clang_cms folder. If you encounter problems with missing files or directories, you may need to edit the file CMakeLists.txt to adapt it to your specific build configuration.
0061
0062 The CMS specific checkers have now been compiled into an external library in clang_cms/lib.
0063
0064 == Test on a small example (non-CMSSW) ==
0065
0066 Export the path to the new clang binary ( Bash example ):
0067
0068 export PATH=<llvm_bin>/Release+Asserts/bin/:$PATH
0069
0070
0071 To see a listing of all available checkers, also the CMS-specific ones, you can run the scan-build command:
0072
0073 <llvm_src>/tools/clang/tools/scan-build/scan-build -load-plugin lib/ClangCms.so
0074
0075
0076 Test out the newly compiled and modified clang, cd into the clang_cms/test folder and run:
0077
0078 <llvm_src>/tools/clang/tools/scan-build/scan-build -load-plugin ../lib/ClangCms.so -enable-checker threadsafety.ConstCast -enable-checker threadsafety.ConstCastAway -enable-checker threadsafety.GlobalStatic -enable-checker threadsafety.MutableMember -enable-checker threadsafety.StaticLocal make -B
0079
0080 This wil produce a clang static analyzer html your can open in your favorite browser. You can find the location in the output line, something along the lines:
0081
0082 scan-build: 6 bugs found.
0083 scan-build: Run 'scan-view /tmp/scan-build-2012-04-26-13' to examine bug reports.
0084
0085
0086 You then call:
0087 firefox /tmp/scan-build-2012-04-26-13/index.html
0088
0089 == Run within a SCRAM-based build ==
0090
0091 Create a project area with arch slc5_amd64_gcc470
0092
0093 export SCRAM_ARCH=slc5_amd64_gcc470
0094 source cmsset_default.sh
0095 scram pro CMSSW CMSSW_6_0_0_pre3
0096
0097 In the project area edit
0098
0099 config/toolbox/slc5_amd64_gcc470/tools/selected/cxxcompiler
0100
0101 and change these lines
0102
0103 # <environment name="CXX" value="$GCCBINDIR/c++"/>
0104 <environment name="CXX" value="(llvm src path)/tools/clang/tools/scan-build/c++-analyzer"/>
0105
0106 Then setup the project area with the new cxxcompiler settings
0107
0108 scram setup cxxcompiler
0109
0110 Now you can run a build as usual expect that you will run scan-build to collect the results and then run scan-view to view them. The output by default goes to /tmp/scan-view-date-1
0111
0112 cd src/(your package dir)
0113 scan-build scram b -v -k -j 4
0114 scan-view /tmp/scan-view-(date)-(##)
0115
0116 You will need to include the paths to clang, scan-build and scan-view in your path
0117
0118 export PATH=$PATH\:(llvm install path)/bin/\:(llvm src path)/tools/clang/tools/scan-build/\:(llvm src path)/tools/clang/tools/scan-view/
0119
0120 If you also want to generate the reports for thread-safety, you also need to add the additional parameters to scan-build.
0121
0122