blob: 4f4a852bb1523028d670a1ed5cd829b2aa579644 [file] [log] [blame] [view]
andybonsad92aa32015-08-31 02:27:441# Retrieving Code Analysis Warnings
andybons3322f762015-08-24 21:37:092
andybonsad92aa32015-08-31 02:27:443Several times a day the Chromium code base is built with Microsoft VC++'s
4`/analyze` compile option. This does static code analysis which has found
5numerous bugs (see https://crbug.com/427616). While it is possible to visit the
6`/analyze` builder page and look at the raw results
xiaoyin.l1003c0b2016-12-06 02:51:177(https://build.chromium.org/p/chromium.fyi/builders/Chromium%20Windows%20Analyze)
andybonsad92aa32015-08-31 02:27:448this works very poorly.
andybons3322f762015-08-24 21:37:099
andybonsad92aa32015-08-31 02:27:4410As of this writing there are 2,702 unique warnings. Some of these are in header
11files and fire multiple times so there are a total of 11,202 warning lines. Most
12of these have been examined and found to be false positives. Therefore, in order
13to sanely examine the /analyze warnings it is necessary to summarize the
14warnings, and find what is new.
andybons3322f762015-08-24 21:37:0915
16There are scripts to do this.
17
andybonsad92aa32015-08-31 02:27:4418## Details
andybons3322f762015-08-24 21:37:0919
andybonsad92aa32015-08-31 02:27:4420The necessary scripts, which currently run on Windows only, are checked in to
21`tools\win\new_analyze_warnings`. Typical usage is like this:
andybons3322f762015-08-24 21:37:0922
andybonsad92aa32015-08-31 02:27:4423 > set ANALYZE_REPO=d:\src\analyze_chromium
24 > retrieve_latest_warnings.bat
andybons3322f762015-08-24 21:37:0925
andybonsad92aa32015-08-31 02:27:4426The batch file using the associated Python scripts to retrieve the latest
27results from the web page, create a summary file, and if previous results were
28found create a new warnings file. Typical results look like this:
andybons3322f762015-08-24 21:37:0929
andybonsad92aa32015-08-31 02:27:4430 analyze0067_full.txt
31 analyze0067_summary.txt
32 analyze0067_new.txt
andybons3322f762015-08-24 21:37:0933
andybonsad92aa32015-08-31 02:27:4434If `ANALYZE_REPO` is set then the batch file goes to `%ANALYZE_REPO%\src`, does
35a git pull, then does a checkout of the revision that corresponds to the latest
36warnings, and then does a gclient sync. The warnings can then be easily
37correlated to the specific source that triggered them.
andybons3322f762015-08-24 21:37:0938
andybonsad92aa32015-08-31 02:27:4439## Understanding the results
andybons3322f762015-08-24 21:37:0940
andybonsad92aa32015-08-31 02:27:4441The `new.txt` file lists new warnings, and fixed warnings. Usually it can
42accurately identify them but sometimes all it can say is that the number of
43instances of a particularly warning has changed, which is usually not of
44interest. If you look at new warnings every day or two then the number of new
45warnings is usually low enough to be quite manageable.
andybons3322f762015-08-24 21:37:0946
andybonsad92aa32015-08-31 02:27:4447The `summary.txt` file groups warnings by type, and then sorts the groups by
48frequency. Low frequency warnings are more likely to be real bugs, so focus on
49those. However, all of the low-frequency have been investigated so at this time
50they are unlikely to be real bugs.
andybons3322f762015-08-24 21:37:0951
andybonsad92aa32015-08-31 02:27:4452The majority of new warnings are variable shadowing warnings. Until `-Wshadow`
53is enabled for gcc/clang builds these warnings will continue to appear, and
54unless they are actually buggy or are particularly confusing it is usually not
55worth fixing them. One exception would be if you are planning to enable
56`-Wshadow` in which case using the list or relevant shadowing warnings would be
57ideal.
andybons3322f762015-08-24 21:37:0958
andybonsad92aa32015-08-31 02:27:4459Some of the warnings say that out-of-range memory accesses will occur, which is
60pretty scary. For instance "warning C6201: Index '-1' is out of valid index
61range '0' to '4'". In most cases these are false positives so use your own
62judgment when deciding whether to fix them.
andybons3322f762015-08-24 21:37:0963
andybonsad92aa32015-08-31 02:27:4464The `full.txt` file contains the raw output and should usually be ignored.
andybons3322f762015-08-24 21:37:0965
andybonsad92aa32015-08-31 02:27:4466If you have any questions then post to the chromium dev mailing list.