-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[alpha.webkit.UnretainedCallArgsChecker] Treat getter on a dependent smart pointer type as safe #161025
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
[alpha.webkit.UnretainedCallArgsChecker] Treat getter on a dependent smart pointer type as safe #161025
Conversation
|
@llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) ChangesAdd the support for recognizing smart pointer type appearing as the type of the object pointer in CXXDependentScopeMemberExpr. Full diff: https://github.com/llvm/llvm-project/pull/161025.diff 2 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 00a1b8b6e7e89..0bc7cb9db8272 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -165,6 +165,14 @@ bool tryToFindPtrOrigin(
if (isSingleton(E->getFoundDecl()))
return callback(E, true);
}
+
+ if (auto *MemberExpr = dyn_cast<CXXDependentScopeMemberExpr>(CalleeE)) {
+ auto *Base = MemberExpr->getBase();
+ auto MemberName = MemberExpr->getMember().getAsString();
+ bool IsGetter = MemberName == "get" || MemberName == "ptr";
+ if (Base && isSafePtrType(Base->getType()) && IsGetter)
+ return callback(E, true);
+ }
}
// Sometimes, canonical type erroneously turns Ref<T> into T.
diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm b/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
index c9d2fe861bb49..111a22d6c8b73 100644
--- a/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
+++ b/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
@@ -561,6 +561,35 @@ void foo() {
} // namespace ns_retained_return_value
+namespace template_function {
+
+class Base {
+public:
+ virtual ~Base() = default;
+ void send(dispatch_queue_t) const;
+ void ref() const;
+ void deref() const;
+};
+
+template<typename Traits>
+class Derived : public Base {
+public:
+ virtual ~Derived() = default;
+
+ void send(typename Traits::MessageType) const;
+
+ virtual OSObjectPtr<dispatch_queue_t> msg(typename Traits::MessageType) const = 0;
+};
+
+template<typename Traits>
+void Derived<Traits>::send(typename Traits::MessageType messageType) const
+{
+ OSObjectPtr dictionary = msg(messageType);
+ Base::send(dictionary.get());
+}
+
+} // namespace template_function
+
@interface TestObject : NSObject
- (void)doWork:(NSString *)msg, ...;
- (void)doWorkOnSelf;
|
b2f3e37 to
9bdb0cf
Compare
…smart pointer type as safe Add the support for recognizing smart pointer type appearing as the type of the object pointer in CXXDependentScopeMemberExpr.
9bdb0cf to
2d45c82
Compare
t-rasmud
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
Thanks for the review! |
…smart pointer type as safe (llvm#161025) Add the support for recognizing smart pointer type appearing as the type of the object pointer in CXXDependentScopeMemberExpr. (cherry picked from commit 65c895d)
…smart pointer type as safe (llvm#161025) Add the support for recognizing smart pointer type appearing as the type of the object pointer in CXXDependentScopeMemberExpr. (cherry picked from commit 65c895d)
Add the support for recognizing smart pointer type appearing as the type of the object pointer in CXXDependentScopeMemberExpr.