This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Include Cleaner: ignore headers with IWYU export pragmas
ClosedPublic

Authored by kbobyrev on May 12 2022, 7:55 AM.

Details

Summary

Disable the warnings with IWYU pragma: export or begin_exports +
end_exports until we have support for these pragmas. There are too many
false-positive warnings for the headers that have the correct pragmas for now
and it makes the user experience very unpleasant.

Diff Detail

Event Timeline

kbobyrev created this revision.May 12 2022, 7:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2022, 7:55 AM
kbobyrev requested review of this revision.May 12 2022, 7:55 AM
kbobyrev updated this revision to Diff 428947.May 12 2022, 8:03 AM

Remove unwanted formatting changes.

kbobyrev updated this revision to Diff 428949.May 12 2022, 8:11 AM

Remove redundant comment.

kadircet added inline comments.May 13 2022, 4:46 AM
clang-tools-extra/clangd/Headers.cpp
134

the split seems to be increasing code duplication (we've already copied a bug with it 😓), what about:

bool Err = false;
    llvm::StringRef Text = SM.getCharacterData(Range.getBegin(), &Err);
    if (!Err || (!Text.consume_front(IWYUPragmaKeep) &&
        !Text.consume_front(IWYUPragmaExport)))
      return false;
    if(inMainFile()) {
      unsigned Offset = SM.getFileOffset(Range.getBegin());
      LastPragmaKeepInMainFileLine =
          SM.getLineNumber(SM.getMainFileID(), Offset) - 1;
    } else {
      Out->HasIWYUPragmas.insert(
        *Out->getID(SM.getFileEntryForID(SM.getFileID(Range.getBegin()))));
    }
    return false;
135

i don't think the asserts carry their weight (here and also in the headerfile comment handler). we're not really performing anything dubious if the asserts don't hold. getCharacterData will return non-sense (but valid) buffers in case of a macroid, and we're already reading data whether we're in the main file or not. moreover these are private and controlled at the entry by the public interface (HandleComment).

178

shouldn't this be if (Err || (!Text.consume ... && !Text.consume...)) return false; ? same above for the main file comment handling

clang-tools-extra/clangd/IncludeCleaner.cpp
270–271

can you also move this comment below, next to the isFileMultipleHeaderGuarded check?

clang-tools-extra/clangd/unittests/HeadersTests.cpp
427

no need for testPaths here and below.

438

this is passing not because you don't have a IWYU pragma comment here, but because you don't have any comments at all. can you try inserting an arbitrary comment into the file?

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

do you mean just foo.h is unused why are we talking about bar.h also being unused here?

kbobyrev updated this revision to Diff 429618.May 15 2022, 11:50 PM
kbobyrev marked 7 inline comments as done.

Address review comments: the structure is a bit different but the bug is now
actually removed.

kbobyrev updated this revision to Diff 429619.May 15 2022, 11:53 PM

Also rebase on top of main.

sammccall accepted this revision.May 16 2022, 12:49 AM

Great! A few more nits

clang-tools-extra/clangd/Headers.cpp
151

you never use Text again, so consume_front is unneccesary and confusing here, we can just use starts_with

151

add a FIXME that begin_export is not handled here (now that the other branch supports it)

clang-tools-extra/clangd/Headers.h
148

hasIWYUExport?
(if the file contains non-export pragmas we need to return false)

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

actual support for export pragmas => more precise tracking of exported headers?

(current wording doesn't really say what's missing)

This revision is now accepted and ready to land.May 16 2022, 12:49 AM
kbobyrev updated this revision to Diff 429637.May 16 2022, 1:12 AM
kbobyrev marked 4 inline comments as done.

Address review comments.

This revision was landed with ongoing or failed builds.May 16 2022, 1:14 AM
This revision was automatically updated to reflect the committed changes.