[PATCH] D152801: [include-cleaner] Don't apply PreferredHeader hings for standard headers.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 13 04:43:48 PDT 2023
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang-tools-extra.
Fixes https://github.com/llvm/llvm-project/issues/62635
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D152801
Files:
clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
Index: clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
===================================================================
--- clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -486,5 +486,16 @@
}
}
+TEST_F(HeadersForSymbolTest, StandardHeaders) {
+ Inputs.Code = "void assert();";
+ buildAST();
+ EXPECT_THAT(
+ headersFor("assert"),
+ // Respect the ordering from the stdlib mapping.
+ UnorderedElementsAre(tooling::stdlib::Header::named("<cassert>"),
+ tooling::stdlib::Header::named("<assert.h>")));
+}
+
+
} // namespace
} // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
===================================================================
--- clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
+++ clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
@@ -248,6 +248,10 @@
// Add name match hints to deduplicated providers.
llvm::StringRef SymbolName = symbolName(S);
for (auto &H : Headers) {
+ // Don't apply name match hints to standard headers as the standard headers
+ // are already ranked in the stdlib mapping.
+ if (H.kind() == Header::Standard)
+ continue;
if (nameMatch(SymbolName, H))
H.Hint |= Hints::PreferredHeader;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152801.530864.patch
Type: text/x-patch
Size: 1381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230613/75082ba2/attachment-0001.bin>
More information about the cfe-commits
mailing list