Skip to content

Commit 6476d4c

Browse files
committed
[alpha.webkit.UncountedCallArgsChecker] Add the support for calling Ref::ptr accessor.
This accessor returns a pointer from Ref type and is therefore safe.
1 parent a3c6875 commit 6476d4c

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ std::optional<bool> isGetterOfRefCounted(const CXXMethodDecl* M)
148148

149149
if (((className == "Ref" || className == "RefPtr") &&
150150
methodName == "get") ||
151+
(className == "Ref" && methodName == "ptr") ||
151152
((className == "String" || className == "AtomString" ||
152153
className == "AtomStringImpl" || className == "UniqueString" ||
153154
className == "UniqueStringImpl" || className == "Identifier") &&

clang/test/Analysis/Checkers/WebKit/mock-types.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
#define mock_types_1103988513531
33

44
template <typename T> struct Ref {
5-
T t;
5+
T *t;
66

77
Ref() : t{} {};
88
Ref(T *) {}
9-
T *get() { return nullptr; }
10-
operator const T &() const { return t; }
11-
operator T &() { return t; }
9+
T *get() { return t; }
10+
T *ptr() { return t; }
11+
operator const T &() const { return *t; }
12+
operator T &() { return *t; }
1213
};
1314

1415
template <typename T> struct RefPtr {
@@ -39,6 +40,7 @@ template <typename T> bool operator!=(const RefPtr<T> &, T *) { return false; }
3940
template <typename T> bool operator!=(const RefPtr<T> &, T &) { return false; }
4041

4142
struct RefCountable {
43+
static Ref<RefCountable> create();
4244
void ref() {}
4345
void deref() {}
4446
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
2+
// expected-no-diagnostics
3+
4+
#include "mock-types.h"
5+
6+
void someFunction(RefCountable*);
7+
8+
void testFunction()
9+
{
10+
Ref item = RefCountable::create();
11+
someFunction(item.ptr());
12+
}

0 commit comments

Comments
 (0)