[clang-tools-extra] 9f05b11 - [clangd] Include Cleaner: suppress unused warnings for IWYU pragma: export
Kirill Bobyrev via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 21 08:00:44 PDT 2022
Author: Kirill Bobyrev
Date: 2022-04-21T17:00:06+02:00
New Revision: 9f05b111ee1fc48974ed515c865bdaddb5998d01
URL: https://github.com/llvm/llvm-project/commit/9f05b111ee1fc48974ed515c865bdaddb5998d01
DIFF: https://github.com/llvm/llvm-project/commit/9f05b111ee1fc48974ed515c865bdaddb5998d01.diff
LOG: [clangd] Include Cleaner: suppress unused warnings for IWYU pragma: export
Add limited support for "IWYU pragma: export" - for now it just supresses the
warning similar to "IWYU pragma: keep".
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D124170
Added:
Modified:
clang-tools-extra/clangd/Headers.cpp
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp
index 4ee58f3b3ab52..9484bb7afa15b 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -17,11 +17,13 @@
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Path.h"
+#include <cstring>
namespace clang {
namespace clangd {
const char IWYUPragmaKeep[] = "// IWYU pragma: keep";
+const char IWYUPragmaExport[] = "// IWYU pragma: export";
class IncludeStructure::RecordHeaders : public PPCallbacks,
public CommentHandler {
@@ -136,15 +138,16 @@ class IncludeStructure::RecordHeaders : public PPCallbacks,
// 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 && !Text.consume_front(IWYUPragmaKeep) &&
+ !Text.consume_front(IWYUPragmaExport))
return false;
unsigned Offset = SM.getFileOffset(Range.getBegin());
LastPragmaKeepInMainFileLine =
diff --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
index f28ffc5139f80..8df292cd28a94 100644
--- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -511,11 +511,13 @@ TEST(IncludeCleaner, IWYUPragmas) {
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"
More information about the cfe-commits
mailing list