This is an archive of the discontinued LLVM Phabricator instance.

[clang-query] Continue if compilation command not found for some files
ClosedPublic

Authored by george.karpenkov on Aug 23 2018, 2:12 PM.

Details

Summary

This is a somewhat controversial change, but I have found it very convenient when running clang-query on entire projects.


When searching for a code pattern in an entire project with a compilation database it's tempting to run

clang-query *.cpp

And yet, that often breaks because some files are just not in the compilation database: tests, sample code, etc.
I don't think clang-query should stop when encountering such cases.

Diff Detail

Repository
rL LLVM

Event Timeline

The change LG, but maybe also exit with an error code whenever some of the ASTs couldn't be built?

clang-tools-extra/clang-query/tool/ClangQuery.cpp
80 ↗(On Diff #162262)

Maybe make the error message scarier, e.g. "Failed to build AST for some of the files. Results may be incomplete."

82 ↗(On Diff #162262)

Maybe remove && Status? I don't think it will show up in assertion failure messages anyway.

george.karpenkov marked 2 inline comments as done.

@ilya-biryukov Thanks for the review and sorry for the delay :P

clang-tools-extra/clang-query/tool/ClangQuery.cpp
82 ↗(On Diff #162262)

Oops, you are right.

LGTM with a few NITs.
Also consider adding a test for this.

clang-tools-extra/clang-query/tool/ClangQuery.cpp
76 ↗(On Diff #176440)

These error codes are undocumented, so I would probably stick with a single != 0 check.
But up to you.

77 ↗(On Diff #176440)

NIT: remove this empty line

127 ↗(On Diff #176440)

NIT: Maybe make only a single int with a more descriptive name, e.g. ASTStatus.
The return at the end would be return ASTStatus != 0. But up to you.

ilya-biryukov accepted this revision.Dec 4 2018, 12:13 PM
This revision is now accepted and ready to land.Dec 4 2018, 12:13 PM
george.karpenkov marked an inline comment as done.Dec 4 2018, 3:50 PM
george.karpenkov added inline comments.
clang-tools-extra/clang-query/tool/ClangQuery.cpp
127 ↗(On Diff #176440)

Then why return ASTStatus != 0 and not just return ASTStatus ? :P

This revision was automatically updated to reflect the committed changes.
dblaikie added inline comments.
clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
108
ilya-biryukov added inline comments.Dec 5 2018, 10:24 AM
clang-tools-extra/clang-query/tool/ClangQuery.cpp
127 ↗(On Diff #176440)

return ASTStatus is clearly better!