This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Initial clang-tidy diagnostics support.
ClosedPublic

Authored by sammccall on Nov 7 2018, 6:02 AM.

Details

Summary

This runs checks over a restricted subset of the TU:

  • preprocessor callbacks just receive the truncated PP events that occur when a preamble is used.
  • ASTMatchers run only over the top-level decls in the main-file

This patch just turns on one simple check (bugprone-sizeof-expression)
with no configuration.

  • configuration is complex enough to warrant a separate patch
  • arbitrary checks don't work well yet - there are various ways that checks can access the whole AST (and thus be incredibly slow). Most notably: the hasAncestor matcher, and using the ASTContext from check().

This depends on a small patch to ASTMatchers to run a MatchFinder on a
certain set of top-level declarations.

Diff Detail

Repository
rL LLVM

Event Timeline

sammccall created this revision.Nov 7 2018, 6:02 AM
hokein added a comment.Nov 7 2018, 7:55 AM

I think this is in a good shape as initial patch!

clangd/ClangdUnit.cpp
168 ↗(On Diff #172937)

It seems we also support clang-tidy checks that analyze preprocessor-dependent properties. I think we can add a clang-tidy check to make sure PPCallback actually work, google-readability-todo is a good candidate.

Ah just realized limitations (truncated PPCallback events) you wrote in the patch description, maybe mention them in the source comment, so that we won't forget in the future when reading the code.

175 ↗(On Diff #172937)

Maybe add the check names to the Trace?

468 ↗(On Diff #172937)

I'm curious how much does clangd binary size get increased.

sammccall updated this revision to Diff 173357.Nov 9 2018, 8:53 AM
sammccall marked an inline comment as done.

Address comments and rebase on D54309, addressing performance issues.

sammccall added inline comments.Nov 9 2018, 8:55 AM
clangd/ClangdUnit.cpp
175 ↗(On Diff #172937)

that would be nice, but there's no API to get that info :-(

468 ↗(On Diff #172937)

It's now 21M stripped vs 18M before this patch.
The different with debug info is *much* larger for some reason... sadly this will hurt link times.

Looks mostly good, just a few nits.

This patch contains two parts (clang-tidy and clangd), I think we could split into two, but I'm not insisting, up to you.

clang-tidy/modernize/LoopConvertUtils.h
59 ↗(On Diff #173357)

The comment is out-of-date.

clang-tidy/readability/SimplifyBooleanExprCheck.cpp
518 ↗(On Diff #173357)

maybe add a comment describing we are trying to find the top level decl?

566 ↗(On Diff #173357)

add an assert (MatchOnce)?

clang-tidy/readability/SimplifyBooleanExprCheck.h
82 ↗(On Diff #173357)

The name seems a bit unclear for readers without any context, maybe FoundTopDecl?

clangd/ClangdUnit.cpp
158 ↗(On Diff #173357)

just want to make sure -- do we receive all preprocessor events in the main file when we use preamble? We have a few checks that generate #include insertion as part of FixIt.

TestTU doesn't use preamble, it would be nice to have a test running on a main file with a real preamble, but this can be a follow-up I think.

Moved the clang-tidy changes to D54579.
Sorry for mixing everything up!

clang-tidy/readability/SimplifyBooleanExprCheck.cpp
518 ↗(On Diff #173357)

We're not, we're trying to match any node (but only one). Extended the comment on the matcher.

566 ↗(On Diff #173357)

That doesn't compile, I'm not sure what you want here.

clangd/ClangdUnit.cpp
158 ↗(On Diff #173357)

Nope, you're right: #include from the preamble are not replayed. Can't fix this now, added a FIXME. (Neither of the hardcoded checks care).

TestTU does use a preamble now :-)

sammccall updated this revision to Diff 174204.Nov 15 2018, 6:31 AM

Remove clang-tidy changes, add FIXME comment.

hokein accepted this revision.Nov 15 2018, 7:08 AM

looks good!

This revision is now accepted and ready to land.Nov 15 2018, 7:08 AM
This revision was automatically updated to reflect the committed changes.