This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Replay preamble #includes to clang-tidy checks.
ClosedPublic

Authored by sammccall on Nov 19 2018, 2:31 AM.

Details

Summary

This is needed to correctly handle checks that use IncludeInserter,
which is very common.

I couldn't find a totally safe example of a check to enable for testing,
I picked modernize-deprecated-headers which some will probably hate.
We should get configuration working...

This depends on D54691 which ensures our calls to getFile(open=false)
don't break subsequent accesses via the FileManager.

Diff Detail

Event Timeline

sammccall created this revision.Nov 19 2018, 2:31 AM
ilya-biryukov added inline comments.Nov 19 2018, 4:55 AM
clangd/ClangdUnit.cpp
129

Maybe move fields and the private function to the end of the class?
We definitely don't have a strict rule about this in clangd, but that's what most of the code does. The upside is that the public interface of the class is the first thing that readers of the code see.

That's a stylistic thing, so definitely feel free to disagree :-)

159

This should be Delegate-> instead of PP.getCallbacks().
Maybe add a test that catches it?

165

Another one: should this be Delegate->?

296

Maybe assert that the pointer returned from getPPCallbacks() actually changes after the call to addPPCallbacks call here?
A potential breakage might occur if the implementation of adding a callback changes and uses an inheritor of PPCallbacks that stores a list internally and adds new callbacks to a list instead of wrapping an existing one.

sammccall updated this revision to Diff 174621.Nov 19 2018, 8:29 AM
sammccall marked 4 inline comments as done.

Address comments.

clangd/ClangdUnit.cpp
159

So after permuting the code, the existing test catches this :-/
Not sure why it didn't before.

It's hard to construct a test that catches this explicitly, the most obvious way would be to add a PP callbacks inside/outside the replay and ensure it does/doesn't capture the events, but there's deliberately no public API for that.

The offline discussion about using the recorded IncludeStructure seems like the best we can do through the public API, but it's pretty indirect.

296

To do this without further cluttering this bloated function, I wrapped this in ReplayPreamble::attach. I'm not sure I like it, but I'm out of ideas, feel free to bikeshed.

This revision is now accepted and ready to land.Nov 20 2018, 2:07 AM
This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.