[clang] 8256804 - [analyzer] Add the support for calling Ref::ptr accessor. (#80919)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 12 15:00:15 PST 2024
Author: Ryosuke Niwa
Date: 2024-02-12T15:00:12-08:00
New Revision: 82568046e6761f961002ea6c48b5160ba6c7576f
URL: https://github.com/llvm/llvm-project/commit/82568046e6761f961002ea6c48b5160ba6c7576f
DIFF: https://github.com/llvm/llvm-project/commit/82568046e6761f961002ea6c48b5160ba6c7576f.diff
LOG: [analyzer] Add the support for calling Ref::ptr accessor. (#80919)
This accessor returns a pointer from Ref type and is therefore safe.
Added:
clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp
Modified:
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/test/Analysis/Checkers/WebKit/mock-types.h
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index d2b66341058000..eadd4686e5dfc3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -154,6 +154,7 @@ std::optional<bool> 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 814e0944145992..cc40487614a83d 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 <typename T> 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 <typename T> struct RefPtr {
@@ -40,6 +41,7 @@ template <typename T> bool operator!=(const RefPtr<T> &, T *) { return false; }
template <typename T> bool operator!=(const RefPtr<T> &, T &) { return false; }
struct RefCountable {
+ static Ref<RefCountable> 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 00000000000000..560dcfd4bdb094
--- /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());
+}
More information about the cfe-commits
mailing list