Skip to content

Commit 149f309

Browse files
committed
[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
1 parent 6bea833 commit 149f309

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

clang-tools-extra/include-cleaner/lib/WalkAST.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
214214
return true;
215215
}
216216
bool VisitVarDecl(VarDecl *VD) {
217+
// Ignore the parameter decl itself (its children were handled elsewhere),
218+
// as they don't contribute to the main-file #include.
219+
if (llvm::isa<ParmVarDecl>(VD))
220+
return true;
217221
// Mark declaration from definition as it needs type-checking.
218222
if (VD->isThisDeclarationADefinition())
219223
report(VD->getLocation(), VD);

clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ TEST_F(WalkUsedTest, Basic) {
9191
#include "header.h"
9292
#include "private.h"
9393
94-
void $bar^bar($private^Private $p^p) {
94+
// No reference reported for the Parameter "p".
95+
void $bar^bar($private^Private p) {
9596
$foo^foo();
9697
std::$vector^vector $vconstructor^$v^v;
9798
$builtin^__builtin_popcount(1);
@@ -120,7 +121,6 @@ TEST_F(WalkUsedTest, Basic) {
120121
offsetToProviders(AST, SM),
121122
UnorderedElementsAre(
122123
Pair(Code.point("bar"), UnorderedElementsAre(MainFile)),
123-
Pair(Code.point("p"), UnorderedElementsAre(MainFile)),
124124
Pair(Code.point("private"),
125125
UnorderedElementsAre(PublicFile, PrivateFile)),
126126
Pair(Code.point("foo"), UnorderedElementsAre(HeaderFile)),

0 commit comments

Comments
 (0)