File tree Expand file tree Collapse file tree 2 files changed +81
-0
lines changed
lib/StaticAnalyzer/Checkers/WebKit
test/Analysis/Checkers/WebKit Expand file tree Collapse file tree 2 files changed +81
-0
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,16 @@ class UncountedCallArgsChecker
126
126
// of object on LHS.
127
127
if (auto *MemberOp = dyn_cast<CXXOperatorCallExpr>(CE)) {
128
128
// Note: assignemnt to built-in type isn't derived from CallExpr.
129
+ if (MemberOp->getOperator () ==
130
+ OO_Equal) { // Ignore assignment to Ref/RefPtr.
131
+ auto *callee = MemberOp->getDirectCallee ();
132
+ if (auto *calleeDecl = dyn_cast<CXXMethodDecl>(callee)) {
133
+ if (const CXXRecordDecl *classDecl = calleeDecl->getParent ()) {
134
+ if (isRefCounted (classDecl))
135
+ return true ;
136
+ }
137
+ }
138
+ }
129
139
if (MemberOp->isAssignmentOp ())
130
140
return false ;
131
141
}
Original file line number Diff line number Diff line change
1
+ // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
2
+ // expected-no-diagnostics
3
+
4
+ template <typename T>
5
+ class RefPtr {
6
+ public:
7
+ inline constexpr RefPtr () : m_ptr(nullptr ) { }
8
+ inline RefPtr (T* ptr)
9
+ : m_ptr(ptr)
10
+ {
11
+ if (m_ptr)
12
+ m_ptr->ref ();
13
+ }
14
+
15
+ inline RefPtr (const RefPtr& o)
16
+ : m_ptr(o.m_ptr)
17
+ {
18
+ if (m_ptr)
19
+ m_ptr->ref ();
20
+ }
21
+
22
+ inline ~RefPtr ()
23
+ {
24
+ if (m_ptr)
25
+ m_ptr->deref ();
26
+ }
27
+
28
+ inline T* operator ->() const { return m_ptr; }
29
+ explicit operator bool () const { return m_ptr; }
30
+
31
+ RefPtr& operator =(const RefPtr&);
32
+ RefPtr& operator =(T*);
33
+
34
+ private:
35
+ T* m_ptr;
36
+ };
37
+
38
+ template <typename T>
39
+ inline RefPtr<T>& RefPtr<T>::operator =(const RefPtr& o)
40
+ {
41
+ if (m_ptr)
42
+ m_ptr->deref ();
43
+ m_ptr = o.m_ptr ;
44
+ if (m_ptr)
45
+ m_ptr->ref ();
46
+ return *this ;
47
+ }
48
+
49
+ template <typename T>
50
+ inline RefPtr<T>& RefPtr<T>::operator =(T* optr)
51
+ {
52
+ if (m_ptr)
53
+ m_ptr->deref ();
54
+ m_ptr = optr;
55
+ if (m_ptr)
56
+ m_ptr->ref ();
57
+ return *this ;
58
+ }
59
+
60
+ class Node {
61
+ public:
62
+ Node* nextSibling () const ;
63
+
64
+ void ref () const ;
65
+ void deref () const ;
66
+ };
67
+
68
+ static void removeDetachedChildren (Node* firstChild)
69
+ {
70
+ for (RefPtr child = firstChild; child; child = child->nextSibling ());
71
+ }
You can’t perform that action at this time.
0 commit comments