blob: ed9feab99e5b6460b79ff78c7954a945abe23f38 [file] [log] [blame] [view]
andybons222c4ee2015-08-25 16:51:031# The Clang Static Analyzer
andybons3322f762015-08-24 21:37:092
andybons222c4ee2015-08-25 16:51:033See the [official clang static analyzer page](http://clang-analyzer.llvm.org/)
4for background.
andybons3322f762015-08-24 21:37:095
andybons222c4ee2015-08-25 16:51:036We don't run this regularly (because the analyzer's
7[support for C++ isn't great yet](http://clang-analyzer.llvm.org/dev_cxx.html)),
8so everything on this page is likely broken. The last time I checked, the
9analyzer reported mostly uninteresting things. This assumes you're
10[building chromium with clang](clang.md).
11
12You need an llvm checkout to get `scan-build` and `scan-view`; the easiest way
13to get that is to run
14
15```shell
Nico Webere250e6a2015-12-02 19:31:5616tools/clang/scripts/update.py --force-local-build --without-android
andybons3322f762015-08-24 21:37:0917```
18
19## With make
20
21To build base, if you use the make build:
22
23```
24builddir_name=out_analyze \
25PATH=$PWD/third_party/llvm-build/Release+Asserts/bin:$PATH \
26third_party/llvm/tools/clang/tools/scan-build/scan-build \
27 --keep-going --use-cc clang --use-c++ clang++ \
28 make -j8 base
29```
30
31(`builddir_name` is set to force a clobber build.)
32
andybons222c4ee2015-08-25 16:51:0333Once that's done, run `third_party/llvm/tools/clang/tools/scan-view/scan-view`
34to see the results; pass in the pass that `scan-build` outputs.
andybons3322f762015-08-24 21:37:0935
36## With ninja
37
andybons222c4ee2015-08-25 16:51:0338scan-build does its stuff by mucking with $CC/$CXX, which ninja ignores. gyp
39does look at $CC/$CXX however, so you need to first run gyp\_chromium under
40scan-build:
41
42```shell
andybons3322f762015-08-24 21:37:0943time GYP_GENERATORS=ninja \
andybons222c4ee2015-08-25 16:51:0344GYP_DEFINES='component=shared_library clang_use_chrome_plugins=0 \
45 mac_strip_release=0 dcheck_always_on=1' \
andybons3322f762015-08-24 21:37:0946third_party/llvm/tools/clang/tools/scan-build/scan-build \
47 --use-analyzer $PWD/third_party/llvm-build/Release+Asserts/bin/clang \
48 build/gyp_chromium -Goutput_dir=out_analyze
49```
andybons222c4ee2015-08-25 16:51:0350
andybons3322f762015-08-24 21:37:0951You then need to run the build under scan-build too, to get a HTML report:
andybons222c4ee2015-08-25 16:51:0352
53```shell
54time third_party/llvm/tools/clang/tools/scan-build/scan-build \
andybons3322f762015-08-24 21:37:0955 --use-analyzer $PWD/third_party/llvm-build/Release+Asserts/bin/clang \
56 ninja -C out_analyze/Release/ base
57```
andybons222c4ee2015-08-25 16:51:0358
andybons3322f762015-08-24 21:37:0959Then run `scan-view` as described above.
60
61## Known False Positives
62
andybons222c4ee2015-08-25 16:51:0363* http://llvm.org/bugs/show_bug.cgi?id=11425
andybons3322f762015-08-24 21:37:0964
65## Stuff found by the static analyzer
66
andybons222c4ee2015-08-25 16:51:0367* https://code.google.com/p/skia/issues/detail?id=399
68* https://code.google.com/p/skia/issues/detail?id=400
69* https://codereview.chromium.org/8308008/
70* https://codereview.chromium.org/8313008/
71* https://codereview.chromium.org/8308009/
72* https://codereview.chromium.org/10031018/
73* https://codereview.chromium.org/12390058/