Skip to content

Ignore assignment to Ref / RefPtr in alpha.webkit.UncountedCallArgsChecker. #80810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,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;
}
Expand Down
17 changes: 17 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/assignment-to-refptr.cpp
Original file line number Diff line number Diff line change
@@ -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());
}
1 change: 1 addition & 0 deletions clang/test/Analysis/Checkers/WebKit/mock-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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> &) {
Expand Down