Bug 1799640 - unused include files checker in clang-tidy. r=glandium,sergesanspaille

Ported from clangd, this still can be improved over time, but it can be landed.
This was based on the work from https://bit.ly/3TkV2N1

  * The utility makes the assumption that all header are self contained!
  * It only checkes `Decls` from the main translation file, where SourceLocarion is the
    passed `cpp` file.
  * It builds a list with all of the includes from the translation unit.
  * It matches all of the `Decls` from the main translation units with definitions from the
    included header files and builds a list with used header files.
  * All of the includes that are not part of the matched used header files are considered
    to be unused. Of course this is correct if the first assumption if followed by the coding guide,
    where all of the header are self contained. Since the mozilla code base doesn't follow this approach
    false positives might appear where the is the following situation:
FOO.cpp
  #include <A>
  #Include <B>

If header `A` defines a symbol that is used by header `B` and `B` doesn't include `A` nor
it has symbols defined that are used by `FOO.cpp` then `B` it will be marked as potentially to be removed
by the tool.
This is the limitation determined by header that are not self contained.

The limitation presented above can be fixed in the future with extra work, but it's very time expensive
during the runtime of the checker.

Differential Revision: https://phabricator.services.mozilla.com/D161583
This commit is contained in:
Andi-Bogdan Postelnicu 2022-11-23 14:21:03 +00:00
parent 9cc8fd31b7
commit 3c68509ca3
5 changed files with 2240 additions and 0 deletions

View file

@ -5,6 +5,7 @@
"cxx": "{MOZ_FETCHES_DIR}/clang/bin/clang++",
"as": "{MOZ_FETCHES_DIR}/clang/bin/clang",
"patches": [
"clang_include_cleaner.patch",
"clang-tidy-ci.patch"
]
}

View file

@ -10,6 +10,7 @@
"libtool": "{MOZ_FETCHES_DIR}/cctools/bin/x86_64-apple-darwin-libtool",
"ld": "{MOZ_FETCHES_DIR}/clang/bin/clang",
"patches": [
"clang_include_cleaner.patch",
"clang-tidy-ci.patch"
]
}

View file

@ -5,6 +5,7 @@
"cxx": "cl.exe",
"ml": "ml64.exe",
"patches": [
"clang_include_cleaner.patch",
"clang-tidy-ci.patch"
]
}

File diff suppressed because it is too large Load diff

View file

@ -23,6 +23,8 @@ package_version: "15.0.5"
clang_checkers:
- name: -*
publish: !!bool no
- name: alpha-unused-includes
reliability: medium
- name: bugprone-argument-comment
reliability: high
- name: bugprone-assert-side-effect