[PATCH] D124170: [clangd] Include Cleaner: suppress unused warnings for IWYU pragma: export
Kirill Bobyrev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 21 06:54:01 PDT 2022
kbobyrev created this revision.
kbobyrev added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
kbobyrev requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
Add limited support for "IWYU pragma: export" - for now it just supresses the
warning similar to "IWYU pragma: keep".
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D124170
Files:
clang-tools-extra/clangd/Headers.cpp
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -511,11 +511,13 @@
TestTU TU;
TU.Code = R"cpp(
#include "behind_keep.h" // IWYU pragma: keep
+ #include "exported.h" // IWYU pragma: export
#include "public.h"
void bar() { foo(); }
)cpp";
TU.AdditionalFiles["behind_keep.h"] = guard("");
+ TU.AdditionalFiles["exported.h"] = guard("");
TU.AdditionalFiles["public.h"] = guard("#include \"private.h\"");
TU.AdditionalFiles["private.h"] = guard(R"cpp(
// IWYU pragma: private, include "public.h"
Index: clang-tools-extra/clangd/Headers.cpp
===================================================================
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -22,6 +22,7 @@
namespace clangd {
const char IWYUPragmaKeep[] = "// IWYU pragma: keep";
+const char IWYUPragmaExport[] = "// IWYU pragma: export";
class IncludeStructure::RecordHeaders : public PPCallbacks,
public CommentHandler {
@@ -129,15 +130,21 @@
// 2. HandleComment("// IWYU pragma: keep")
// 3. InclusionDirective("bar.h")
//
- // HandleComment will store the last location of "IWYU pragma: keep" comment
- // in the main file, so that when InclusionDirective is called, it will know
- // that the next inclusion is behind the IWYU pragma.
+ // HandleComment will store the last location of "IWYU pragma: keep" (or
+ // export) comment in the main file, so that when InclusionDirective is
+ // called, it will know that the next inclusion is behind the IWYU pragma.
bool HandleComment(Preprocessor &PP, SourceRange Range) override {
if (!inMainFile() || Range.getBegin().isMacroID())
return false;
bool Err = false;
llvm::StringRef Text = SM.getCharacterData(Range.getBegin(), &Err);
- if (Err || !Text.consume_front(IWYUPragmaKeep))
+ if (Err)
+ return false;
+ if (Text.startswith(IWYUPragmaKeep))
+ Text.consume_front(IWYUPragmaKeep);
+ else if (Text.startswith(IWYUPragmaExport))
+ Text.consume_front(IWYUPragmaExport);
+ else
return false;
unsigned Offset = SM.getFileOffset(Range.getBegin());
LastPragmaKeepInMainFileLine =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124170.424188.patch
Type: text/x-patch
Size: 2422 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220421/c6cdc86c/attachment.bin>
More information about the cfe-commits
mailing list