This is an archive of the discontinued LLVM Phabricator instance.

[AST] Fix RecursiveASTVisitor visiting implicit constructor initializers.
ClosedPublic

Authored by jvikstrom on Aug 5 2019, 12:02 AM.

Details

Summary

RecursiveASTVisitor was visiting implcit constructor initializers. When the TypeLoc for the implicit construcor intializer was visited the SourceLocation would be invalid. This caused semantic highlighting in clangd to emit error logs.

Fixes this by checking if the constructor is written or if the visitor should visit implicit decls.

Diff Detail

Repository
rL LLVM

Event Timeline

jvikstrom created this revision.Aug 5 2019, 12:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2019, 12:02 AM
jvikstrom edited the summary of this revision. (Show Details)Aug 5 2019, 12:06 AM

I think this is a reasonable fix, just a few comments on the test.

clang/unittests/Tooling/RecursiveASTVisitorTests/InitListExprPreOrder.cpp
26 ↗(On Diff #213285)

there may be other reasons to cause an invalid source location. I think we can use the Init->isWritten() to verify the implicit initializer is being visited.

37 ↗(On Diff #213285)

maybe name it VisitedImplicitInitializer?

62 ↗(On Diff #213285)

nit: inline the Config.

The fix looks good.

clang/unittests/Tooling/RecursiveASTVisitorTests/InitListExprPreOrder.cpp
17 ↗(On Diff #213285)

Could you create a new test?
This test is clearly meant to test only InitListExpr, we should keep it focused on one thing.

jvikstrom updated this revision to Diff 213291.Aug 5 2019, 1:57 AM
jvikstrom marked 4 inline comments as done.

Moved test to its own test file (also addressed comments about the test).

jvikstrom updated this revision to Diff 213294.Aug 5 2019, 2:01 AM

Call the base Traverse.. function in the visitor.

hokein added inline comments.Aug 5 2019, 2:35 AM
clang/unittests/Tooling/RecursiveASTVisitorTests/ImplicitCtorInitializer.cpp
2 ↗(On Diff #213294)

we should make them one line even it exceeds 80 columns.

3 ↗(On Diff #213294)

I think you forgot to add the new file to the cmake file.

LGTM from my side, a few optional NITs.
Feel free to land as soon as @hokein stamps.

clang/unittests/Tooling/RecursiveASTVisitorTests/ImplicitCtorInitializer.cpp
16 ↗(On Diff #213294)

NIT: this comment is about the TEST rather than the helper class. Maybe move it there?

29 ↗(On Diff #213294)

NIT: alternatively use different match identifiers for written and unwritten initializers:

if (Init->isWritten())
  Match("written-inititiazlier", ...);
else
  Match("implicit-initializer", ...);

...
TEST() {
  Visitor.expectMatch("written-initializer");
  Visitor.disallowMatch("implicit-initializer"); // would that work with invalid source locs, though?
}

This allows to reuse the mechanism used by other tests without extra code. But up to you, definitely not a big deal.

jvikstrom updated this revision to Diff 213323.Aug 5 2019, 4:54 AM
jvikstrom marked 3 inline comments as done.

Address comments.

jvikstrom marked an inline comment as done.Aug 5 2019, 4:56 AM
jvikstrom added inline comments.
clang/unittests/Tooling/RecursiveASTVisitorTests/ImplicitCtorInitializer.cpp
29 ↗(On Diff #213294)

disallowMatch requires a valid SourceLocation otherwise that would definitely be the way to do it.

Maybe that is something that should be added (the ability to disallow matches no matter what location) to ExpectedLocationVisitor?

hokein accepted this revision.Aug 5 2019, 5:05 AM
hokein added inline comments.
clang/unittests/Tooling/RecursiveASTVisitorTests/ImplicitCtorInitializer.cpp
26 ↗(On Diff #213323)

is it intentional to run for case !Init->IsWritten() where the source location is invalid?

This revision is now accepted and ready to land.Aug 5 2019, 5:05 AM
This revision was automatically updated to reflect the committed changes.
jvikstrom marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2019, 5:20 AM