This is an archive of the discontinued LLVM Phabricator instance.

[clangd] IncludeClenaer: Don't mark forward declarations of a class if it's declared in the main file
ClosedPublic

Authored by kbobyrev on Dec 1 2021, 4:28 AM.

Details

Summary

This will mark more headers that are unrelated to used symbol but contain its
forawrd declaration. E.g. the following are examples of headers forward
declaring llvm::StringRef:

  • clang/include/clang/Basic/Cuda.h
  • llvm/include/llvm/Support/SHA256.h
  • llvm/include/llvm/Support/TrigramIndex.h
  • llvm/include/llvm/Support/RandomNumberGenerator.
  • ... and more (~50 in total)

This patch is a reduced version of D112707 which was controversial.

Diff Detail

Event Timeline

kbobyrev created this revision.Dec 1 2021, 4:28 AM
kbobyrev requested review of this revision.Dec 1 2021, 4:28 AM

I can't fully remember the discussion but what about the case in which we don't have a declaration in the main file, but see a definition and multiple forward declarations. Is there a good reason to still include re-decls in this case?

clang-tools-extra/clangd/IncludeCleaner.cpp
57

why don't we do this inside add instead? which can take care of duplication, and remain as the only place we modify Result ?

kbobyrev updated this revision to Diff 390999.Dec 1 2021, 6:16 AM
kbobyrev marked an inline comment as done.

Resolve review comments, add justification in tests.

kadircet accepted this revision.Dec 2 2021, 1:03 AM

thanks, lgtm!

clang-tools-extra/clangd/IncludeCleaner.cpp
131

nit: I'd just inline RD->getMostRecentDecl() here.

clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
42

might be worth having a fixme comment here (around we should ignore all re-decls when we can see a def)

This revision is now accepted and ready to land.Dec 2 2021, 1:03 AM
kbobyrev updated this revision to Diff 391249.Dec 2 2021, 1:21 AM
kbobyrev marked 2 inline comments as done.

Address review comments

This revision was landed with ongoing or failed builds.Dec 2 2021, 1:26 AM
This revision was automatically updated to reflect the committed changes.