Author: Haojian Wu Date: 2023-07-31T13:21:54+02:00 New Revision: dcb28244faa88cb566a852533790bcac75daaa0f
URL: https://github.com/llvm/llvm-project/commit/dcb28244faa88cb566a852533790bcac75daaa0f DIFF: https://github.com/llvm/llvm-project/commit/dcb28244faa88cb566a852533790bcac75daaa0f.diff LOG: [clangd] Respect IWYU keep pragma for standard headers. see the issue https://github.com/llvm/llvm-project/issues/64191 Differential Revision: https://reviews.llvm.org/D156650 Added: Modified: clang-tools-extra/clangd/IncludeCleaner.cpp clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp b/clang-tools-extra/clangd/IncludeCleaner.cpp index 8da42dba78f877..4a1ba484bfc492 100644 --- a/clang-tools-extra/clangd/IncludeCleaner.cpp +++ b/clang-tools-extra/clangd/IncludeCleaner.cpp @@ -71,6 +71,8 @@ bool isIgnored(llvm::StringRef HeaderPath, HeaderFilter IgnoreHeaders) { 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 @@ bool mayConsiderUnused( 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()) { diff --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp index c5d6ecfe4dcf61..afaba8aa68d1a7 100644 --- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp +++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp @@ -78,6 +78,8 @@ TEST(IncludeCleaner, StdlibUnused) { 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 @@ TEST(IncludeCleaner, StdlibUnused) { 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); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits