matus-chochlik / ctcache

Cache for clang-tidy static analysis results
Boost Software License 1.0
84 stars 30 forks source link

Computation of the hash value does not always detect code changes #26

Closed nicocvn closed 1 year ago

nicocvn commented 1 year ago

Description of the problem

The current implementation of hash_inputs() does not always detect if the code to be analyzed has changed. It seems that the issue can be traced to how #24 modified the hash_inputs() modification.

For example, consider the following clang-tidy invocation (using a compilation database):

clang-tidy -p build_dir foo-lib/foo.cpp

Upon parsing the compilation database to extract the compiler arguments, the compiler command line would look like:

clang++ -D__clang_analyzer__=1 __whatever_compiler_flags__ -o - -E foo-lib/foo.cpp

hash_inputs will then calculate the hash based on the modification time of the file foo-lib/foo.cpp. If the headers included by that file have changed since last run this will not impact the computation of the hash and clang-tidy-cache will use the cached information if available.

Discussion

Prior #24 the compiler command line was actually executed to collect the output of the preprocessor (which was then filtered using adjust_chunks()). The advantage of this approach is that any changes in the translation unit lead to a different hash, and I assume this is the desired behavior.

Note that, #24 was motivated by issues observed in VSCode+Ninja but it is not clear (to me at least) what was the real bottleneck.

Would it be possible to actually revert these changes to avoid the issue?

Thoughts:

I can open a PR but I first wanted to discuss the issue as this is essentially asking for reverting a big part of #24.

nicocvn commented 1 year ago

27 shows the code changes