[clang-tools-extra] ae0813f - Revert "[clang-tidy] fix false positives for the functions with the same name as standard library functions in misc-include-cleaner (#94923)"
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 18 00:15:45 PDT 2024
Author: Kadir Cetinkaya
Date: 2024-06-18T09:15:30+02:00
New Revision: ae0813f2d7222c4eab7cd3e6099d49f50318d1d5
URL: https://github.com/llvm/llvm-project/commit/ae0813f2d7222c4eab7cd3e6099d49f50318d1d5
DIFF: https://github.com/llvm/llvm-project/commit/ae0813f2d7222c4eab7cd3e6099d49f50318d1d5.diff
LOG: Revert "[clang-tidy] fix false positives for the functions with the same name as standard library functions in misc-include-cleaner (#94923)"
This reverts commit 1bae10879d9183c5edfb709c36b55086ebc772f0. Also add
some test cases to prevent further regressions.
Added:
Modified:
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 3bdd735f7dcf7..16fdc20eafd62 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -341,10 +341,6 @@ Changes in existing checks
<clang-tidy/checks/misc/header-include-cycle>` check by avoiding crash for self
include cycles.
-- Improved :doc:`misc-include-cleaner
- <clang-tidy/checks/misc/include-cleaner>` check by avoiding false positives for
- the functions with the same name as standard library functions.
-
- Improved :doc:`misc-unused-using-decls
<clang-tidy/checks/misc/unused-using-decls>` check by replacing the local
option `HeaderFileExtensions` by the global option of the same name.
diff --git a/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp b/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
index 9148d36a5038f..78e783a62eb27 100644
--- a/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
+++ b/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
@@ -14,7 +14,6 @@
#include "clang/AST/DeclTemplate.h"
#include "clang/Tooling/Inclusions/StandardLibrary.h"
#include "llvm/Support/Casting.h"
-#include "llvm/Support/raw_ostream.h"
#include <utility>
#include <vector>
@@ -41,11 +40,8 @@ Hints declHints(const Decl *D) {
std::vector<Hinted<SymbolLocation>> locateDecl(const Decl &D) {
std::vector<Hinted<SymbolLocation>> Result;
// FIXME: Should we also provide physical locations?
- if (auto SS = tooling::stdlib::Recognizer()(&D)) {
- Result.push_back({*SS, Hints::CompleteSymbol});
- if (!D.hasBody())
- return Result;
- }
+ if (auto SS = tooling::stdlib::Recognizer()(&D))
+ return {{*SS, Hints::CompleteSymbol}};
// FIXME: Signal foreign decls, e.g. a forward declaration not owned by a
// library. Some useful signals could be derived by checking the DeclContext.
// Most incidental forward decls look like:
diff --git a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
index fdcbf25fd628c..c5fc465ced7a7 100644
--- a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -619,26 +619,23 @@ TEST_F(HeadersForSymbolTest, AmbiguousStdSymbolsUsingShadow) {
TEST_F(HeadersForSymbolTest, StandardHeaders) {
- Inputs.Code = "void assert();";
+ Inputs.Code = R"cpp(
+ #include "stdlib_internal.h"
+ void assert();
+ void foo() { assert(); }
+ )cpp";
+ Inputs.ExtraFiles["stdlib_internal.h"] = "void assert();";
buildAST();
EXPECT_THAT(
headersFor("assert"),
// Respect the ordering from the stdlib mapping.
+ // FIXME: Report physical locations too, stdlib_internal.h and main-file
+ // should also be candidates. But they should be down-ranked compared to
+ // stdlib providers.
UnorderedElementsAre(tooling::stdlib::Header::named("<cassert>"),
tooling::stdlib::Header::named("<assert.h>")));
}
-TEST_F(HeadersForSymbolTest, NonStandardHeaders) {
- Inputs.Code = "void assert() {}";
- buildAST();
- EXPECT_THAT(
- headersFor("assert"),
- // Respect the ordering from the stdlib mapping.
- UnorderedElementsAre(physicalHeader("input.mm"),
- tooling::stdlib::Header::named("<cassert>"),
- tooling::stdlib::Header::named("<assert.h>")));
-}
-
TEST_F(HeadersForSymbolTest, ExporterNoNameMatch) {
Inputs.Code = R"cpp(
#include "exporter/foo.h"
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
index d5ea96b00254c..e10ac3f46e2e9 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
@@ -15,11 +15,3 @@ std::string HelloString;
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: no header providing "std::string" is directly included [misc-include-cleaner]
int FooBarResult = foobar();
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: no header providing "foobar" is directly included [misc-include-cleaner]
-
-namespace valid {
-
-namespace gh93335 {
-void log2() {}
-} // namespace gh93335
-
-} // namespace valid
More information about the cfe-commits
mailing list