[PATCH] D51729: [Tooling] JSONCompilationDatabasePlugin infers compile commands for missing files
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 5 23:45:27 PST 2018
sammccall added a comment.
In https://reviews.llvm.org/D51729#1287421, @Lekensteyn wrote:
> Before this patch, missing compilation database entries resulted in "Skipping .... Compile command not found." which is assumed by the tests in this clang-query patch: https://reviews.llvm.org/D54109
> After this patch, a command is inferred, but this is not always desired.
> Use case: find all function calls with a certain name using the compilation database produced by CMake.
> Example command:
> clang-query -p=/tmp/wsbuild -c 'set output print' -c 'm callExpr(callee(functionDecl(hasName("uat_new"))))' $(grep -rl uat_new epan/dissectors/)
> Expected result for some template files which do not exist in the compilation database:
> Skipping .../epan/dissectors/asn1/x509af/packet-x509af-template.c. Compile command not found.
> Actual result (clang-query tries to parse the contents which will fail since it is not an actual C source file):
> .../epan/dissectors/asn1/x509af/packet-x509af-template.c:18:10: fatal error: 'packet-ber.h' file not found
> I'm not entirely sure what to do here. The old behavior works great in cases where a complete database is available (produced by CMake). The new behavior might work better for clangd (?), but it breaks a use case (see above).
For clangd, but also clang-tidy and clang-query when the user *does* want to use it on files not represented in the CDB. (e.g. stale or headers)
There's indeed a tension here, because the CDB discovery needs to have a default configuration.
That said, in this case the behavior looks appropriate to me: you've explicitly specified files on the command line, ignoring them and returning with status 0 seems surprising.
For the case of "search over all TUs in CDB", the CDB does offer the ability to list TUs and iterate over compile commands, and ClangTool lets you run in this mode. We've discussed in the past adding a filename filter to `AllTUsExecutor`, which would be useful for this purpose and others. @ioeric
More information about the cfe-commits