[PATCH] D147144: [include-cleaner] Report references to operator calls as implicit
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 29 05:09:57 PDT 2023
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
Missing these references can result in false negatives in the used-ness
analysis and break builds.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147144
Files:
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===================================================================
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -292,12 +292,13 @@
TEST(WalkAST, Operator) {
// References to operators are not counted as uses.
- testWalk("struct string {}; int operator+(string, string);",
+ testWalk("struct string {}; int $implicit^operator+(string, string);",
"int k = string() ^+ string();");
- testWalk("struct string {int operator+(string); }; ",
- "int k = string() ^+ string();");
- testWalk("struct string { friend int operator+(string, string); }; ",
+ testWalk("struct string {int $implicit^operator+(string); }; ",
"int k = string() ^+ string();");
+ testWalk(
+ "struct string { friend int $implicit^operator+(string, string); }; ",
+ "int k = string() ^+ string();");
}
TEST(WalkAST, Functions) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===================================================================
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -87,14 +87,16 @@
public:
ASTWalker(DeclCallback Callback) : Callback(Callback) {}
+ // Operators are always ADL extension points, by design references to them
+ // doesn't count as uses (generally the type should provide them). Hence
+ // treat these as implicit references.
+ // We do this in traverse to make sure rest of the visitor doesn't see
+ // operator calls.
bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
if (!WalkUpFromCXXOperatorCallExpr(S))
return false;
-
- // Operators are always ADL extension points, by design references to them
- // doesn't count as uses (generally the type should provide them).
- // Don't traverse the callee.
-
+ report(S->getOperatorLoc(), llvm::cast<NamedDecl>(S->getCalleeDecl()),
+ RefType::Implicit);
for (auto *Arg : S->arguments())
if (!TraverseStmt(Arg))
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147144.509319.patch
Type: text/x-patch
Size: 2141 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230329/2baaad87/attachment.bin>
More information about the cfe-commits
mailing list