This is an archive of the discontinued LLVM Phabricator instance.

[clangd] IncludeCleaner: Don't warn on system headers
ClosedPublic

Authored by kbobyrev on Oct 26 2021, 1:00 PM.

Details

Summary

This is a temporary hack to disable diagnostics for system headers. As of right
now, IncludeCleaner does not handle the Standard Library correctly and will
report most system headers as unused because very few symbols are defined in
top-level system headers. This will eventually be fixed, but for now we are
aiming for the most conservative approach with as little false-positive
warnings as possible. After the initial prototype and core functionality is
polished, I will turn back to handling the Standard Library as it requires
custom logic.

Diff Detail

Event Timeline

kbobyrev created this revision.Oct 26 2021, 1:00 PM
kbobyrev requested review of this revision.Oct 26 2021, 1:00 PM
sammccall accepted this revision.Oct 27 2021, 1:57 AM
sammccall added inline comments.
clang-tools-extra/clangd/IncludeCleaner.cpp
294

As discussed offline, I'm not sure this difference in behavior is as temporary or as narrow as we originally planned.

I think the reason we want this hack is:

  • umbrella headers need special handling
  • standard library headers are umbrella headers
  • system headers are likely to be standard library headers

But this is complicated by the fact that non-stdlib headers can be umbrella headers, system headers are likely to be umbrella headers even if not stdlib, stdlib needs different special handling from other umbrella headers, there are other headers (non-self-contained) that need special handling, etc.

Among other things, it's going to be hard to just turn this back on.

For now, I'd suggest extracting a function mayConsiderUnused(const Inclusion&) with the simple logic you have here for now, but we should come up with a more concrete plan soon.

This revision is now accepted and ready to land.Oct 27 2021, 1:57 AM
kbobyrev updated this revision to Diff 382576.Oct 27 2021, 2:50 AM
kbobyrev marked an inline comment as done.

Resolve review comment.

This revision was landed with ongoing or failed builds.Oct 27 2021, 2:51 AM
This revision was automatically updated to reflect the committed changes.