diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index d2b6634105800..eadd4686e5dfc 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -154,6 +154,7 @@ std::optional isGetterOfRefCounted(const CXXMethodDecl* M) if (((className == "Ref" || className == "RefPtr") && methodName == "get") || + (className == "Ref" && methodName == "ptr") || ((className == "String" || className == "AtomString" || className == "AtomStringImpl" || className == "UniqueString" || className == "UniqueStringImpl" || className == "Identifier") && diff --git a/clang/test/Analysis/Checkers/WebKit/mock-types.h b/clang/test/Analysis/Checkers/WebKit/mock-types.h index 814e094414599..cc40487614a83 100644 --- a/clang/test/Analysis/Checkers/WebKit/mock-types.h +++ b/clang/test/Analysis/Checkers/WebKit/mock-types.h @@ -2,13 +2,14 @@ #define mock_types_1103988513531 template struct Ref { - T t; + T *t; Ref() : t{} {}; Ref(T *) {} - T *get() { return nullptr; } - operator const T &() const { return t; } - operator T &() { return t; } + T *get() { return t; } + T *ptr() { return t; } + operator const T &() const { return *t; } + operator T &() { return *t; } }; template struct RefPtr { @@ -40,6 +41,7 @@ template bool operator!=(const RefPtr &, T *) { return false; } template bool operator!=(const RefPtr &, T &) { return false; } struct RefCountable { + static Ref create(); void ref() {} void deref() {} }; diff --git a/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp b/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp new file mode 100644 index 0000000000000..560dcfd4bdb09 --- /dev/null +++ b/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s +// expected-no-diagnostics + +#include "mock-types.h" + +void someFunction(RefCountable*); + +void testFunction() +{ + Ref item = RefCountable::create(); + someFunction(item.ptr()); +}