andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 1 | # Retrieving Code Analysis Warnings |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 2 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 3 | Several 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 |
| 5 | numerous bugs (see https://crbug.com/427616). While it is possible to visit the |
| 6 | `/analyze` builder page and look at the raw results |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 7 | (https://build.chromium.org/p/chromium.fyi/builders/Chromium%20Windows%20Analyze) |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 8 | this works very poorly. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 9 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 10 | As of this writing there are 2,702 unique warnings. Some of these are in header |
| 11 | files and fire multiple times so there are a total of 11,202 warning lines. Most |
| 12 | of these have been examined and found to be false positives. Therefore, in order |
| 13 | to sanely examine the /analyze warnings it is necessary to summarize the |
| 14 | warnings, and find what is new. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 15 | |
| 16 | There are scripts to do this. |
| 17 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 18 | ## Details |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 19 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 20 | The necessary scripts, which currently run on Windows only, are checked in to |
| 21 | `tools\win\new_analyze_warnings`. Typical usage is like this: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 22 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 23 | > set ANALYZE_REPO=d:\src\analyze_chromium |
| 24 | > retrieve_latest_warnings.bat |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 25 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 26 | The batch file using the associated Python scripts to retrieve the latest |
| 27 | results from the web page, create a summary file, and if previous results were |
| 28 | found create a new warnings file. Typical results look like this: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 29 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 30 | analyze0067_full.txt |
| 31 | analyze0067_summary.txt |
| 32 | analyze0067_new.txt |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 33 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 34 | If `ANALYZE_REPO` is set then the batch file goes to `%ANALYZE_REPO%\src`, does |
| 35 | a git pull, then does a checkout of the revision that corresponds to the latest |
| 36 | warnings, and then does a gclient sync. The warnings can then be easily |
| 37 | correlated to the specific source that triggered them. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 38 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 39 | ## Understanding the results |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 40 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 41 | The `new.txt` file lists new warnings, and fixed warnings. Usually it can |
| 42 | accurately identify them but sometimes all it can say is that the number of |
| 43 | instances of a particularly warning has changed, which is usually not of |
| 44 | interest. If you look at new warnings every day or two then the number of new |
| 45 | warnings is usually low enough to be quite manageable. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 46 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 47 | The `summary.txt` file groups warnings by type, and then sorts the groups by |
| 48 | frequency. Low frequency warnings are more likely to be real bugs, so focus on |
| 49 | those. However, all of the low-frequency have been investigated so at this time |
| 50 | they are unlikely to be real bugs. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 51 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 52 | The majority of new warnings are variable shadowing warnings. Until `-Wshadow` |
| 53 | is enabled for gcc/clang builds these warnings will continue to appear, and |
| 54 | unless they are actually buggy or are particularly confusing it is usually not |
| 55 | worth 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 |
| 57 | ideal. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 58 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 59 | Some of the warnings say that out-of-range memory accesses will occur, which is |
| 60 | pretty scary. For instance "warning C6201: Index '-1' is out of valid index |
| 61 | range '0' to '4'". In most cases these are false positives so use your own |
| 62 | judgment when deciding whether to fix them. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 63 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 64 | The `full.txt` file contains the raw output and should usually be ignored. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 65 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 66 | If you have any questions then post to the chromium dev mailing list. |