[clang] 85507f1 - [analyzer] Ignore assignment to Ref / RefPtr in alpha.webkit.UncountedCallArgsChecker. (#80810)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 12 14:59:18 PST 2024
Author: Ryosuke Niwa
Date: 2024-02-12T14:59:14-08:00
New Revision: 85507f17cfc42e29f956de6b3e0924c3cf7b4469
URL: https://github.com/llvm/llvm-project/commit/85507f17cfc42e29f956de6b3e0924c3cf7b4469
DIFF: https://github.com/llvm/llvm-project/commit/85507f17cfc42e29f956de6b3e0924c3cf7b4469.diff
LOG: [analyzer] Ignore assignment to Ref / RefPtr in alpha.webkit.UncountedCallArgsChecker. (#80810)
Added:
clang/test/Analysis/Checkers/WebKit/assignment-to-refptr.cpp
Modified:
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
clang/test/Analysis/Checkers/WebKit/mock-types.h
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 31ccae8b097b89..737e887b89afdf 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -125,6 +125,16 @@ class UncountedCallArgsChecker
// of object on LHS.
if (auto *MemberOp = dyn_cast<CXXOperatorCallExpr>(CE)) {
// Note: assignemnt to built-in type isn't derived from CallExpr.
+ if (MemberOp->getOperator() ==
+ OO_Equal) { // Ignore assignment to Ref/RefPtr.
+ auto *callee = MemberOp->getDirectCallee();
+ if (auto *calleeDecl = dyn_cast<CXXMethodDecl>(callee)) {
+ if (const CXXRecordDecl *classDecl = calleeDecl->getParent()) {
+ if (isRefCounted(classDecl))
+ return true;
+ }
+ }
+ }
if (MemberOp->isAssignmentOp())
return false;
}
diff --git a/clang/test/Analysis/Checkers/WebKit/assignment-to-refptr.cpp b/clang/test/Analysis/Checkers/WebKit/assignment-to-refptr.cpp
new file mode 100644
index 00000000000000..8b2b4671ed96b1
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/assignment-to-refptr.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+#include "mock-types.h"
+
+class Node {
+public:
+ Node* nextSibling() const;
+
+ void ref() const;
+ void deref() const;
+};
+
+static void removeDetachedChildren(Node* firstChild)
+{
+ for (RefPtr child = firstChild; child; child = child->nextSibling());
+}
diff --git a/clang/test/Analysis/Checkers/WebKit/mock-types.h b/clang/test/Analysis/Checkers/WebKit/mock-types.h
index 5f570b8bee8cb8..814e0944145992 100644
--- a/clang/test/Analysis/Checkers/WebKit/mock-types.h
+++ b/clang/test/Analysis/Checkers/WebKit/mock-types.h
@@ -20,6 +20,7 @@ template <typename T> struct RefPtr {
T *operator->() { return t; }
T &operator*() { return *t; }
RefPtr &operator=(T *) { return *this; }
+ operator bool() { return t; }
};
template <typename T> bool operator==(const RefPtr<T> &, const RefPtr<T> &) {
More information about the cfe-commits
mailing list