[PATCH] D156650: [clangd] Respect IWYU keep pragma for standard headers.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 31 04:23:57 PDT 2023
hokein updated this revision to Diff 545589.
hokein marked an inline comment as done.
hokein added a comment.
address review comment
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156650/new/
https://reviews.llvm.org/D156650
Files:
clang-tools-extra/clangd/IncludeCleaner.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
@@ -78,6 +78,8 @@
auto TU = TestTU::withCode(R"cpp(
#include <list>
#include <queue>
+ #include <vector> // IWYU pragma: keep
+ #include <string> // IWYU pragma: export
std::list<int> x;
)cpp");
// Layout of std library impl is not relevant.
@@ -86,10 +88,13 @@
namespace std {
template <typename> class list {};
template <typename> class queue {};
+ template <typename> class vector {};
}
)cpp";
TU.AdditionalFiles["list"] = "#include <bits>";
TU.AdditionalFiles["queue"] = "#include <bits>";
+ TU.AdditionalFiles["vector"] = "#include <bits>";
+ TU.AdditionalFiles["string"] = "#include <bits>";
TU.ExtraArgs = {"-isystem", testRoot()};
auto AST = TU.build();
IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===================================================================
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -71,6 +71,8 @@
bool mayConsiderUnused(
const Inclusion &Inc, ParsedAST &AST,
const include_cleaner::PragmaIncludes *PI) {
+ if (PI && PI->shouldKeep(Inc.HashLine + 1))
+ return false;
// FIXME(kirillbobyrev): We currently do not support the umbrella headers.
// System headers are likely to be standard library headers.
// Until we have good support for umbrella headers, don't warn about them.
@@ -82,8 +84,6 @@
AST.getIncludeStructure().getRealPath(HID));
assert(FE);
if (PI) {
- if (PI->shouldKeep(Inc.HashLine + 1))
- return false;
// Check if main file is the public interface for a private header. If so we
// shouldn't diagnose it as unused.
if (auto PHeader = PI->getPublic(*FE); !PHeader.empty()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156650.545589.patch
Type: text/x-patch
Size: 2059 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230731/33c79350/attachment-0001.bin>
More information about the cfe-commits
mailing list