[clang-tools-extra] 149f309 - [include-cleaner] Ignore the ParmVarDecl itself in WalkAST.cpp
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 20 05:33:36 PDT 2023
Author: Haojian Wu
Date: 2023-06-20T14:26:55+02:00
New Revision: 149f309f50cd981ed320c948f772aa571eaa9afa
URL: https://github.com/llvm/llvm-project/commit/149f309f50cd981ed320c948f772aa571eaa9afa
DIFF: https://github.com/llvm/llvm-project/commit/149f309f50cd981ed320c948f772aa571eaa9afa.diff
LOG: [include-cleaner] Ignore the ParmVarDecl itself in WalkAST.cpp
This fixes a false positive where a ParamVarDecl happend to be the
same name of some C standard symbol and has a global namespace.
```
using A = int(int time); // we suggest <ctime> for the `int time`.
```
Differential Revision: https://reviews.llvm.org/D153330
Added:
Modified:
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index fc392fec36865..8cfda506fc254 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -214,6 +214,10 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
return true;
}
bool VisitVarDecl(VarDecl *VD) {
+ // Ignore the parameter decl itself (its children were handled elsewhere),
+ // as they don't contribute to the main-file #include.
+ if (llvm::isa<ParmVarDecl>(VD))
+ return true;
// Mark declaration from definition as it needs type-checking.
if (VD->isThisDeclarationADefinition())
report(VD->getLocation(), VD);
diff --git a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
index bad55e1433549..5b5f77b5fdea8 100644
--- a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -91,7 +91,8 @@ TEST_F(WalkUsedTest, Basic) {
#include "header.h"
#include "private.h"
- void $bar^bar($private^Private $p^p) {
+ // No reference reported for the Parameter "p".
+ void $bar^bar($private^Private p) {
$foo^foo();
std::$vector^vector $vconstructor^$v^v;
$builtin^__builtin_popcount(1);
@@ -120,7 +121,6 @@ TEST_F(WalkUsedTest, Basic) {
offsetToProviders(AST, SM),
UnorderedElementsAre(
Pair(Code.point("bar"), UnorderedElementsAre(MainFile)),
- Pair(Code.point("p"), UnorderedElementsAre(MainFile)),
Pair(Code.point("private"),
UnorderedElementsAre(PublicFile, PrivateFile)),
Pair(Code.point("foo"), UnorderedElementsAre(HeaderFile)),
More information about the cfe-commits
mailing list