-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[alpha.webkit.NoUnretainedMemberChecker] Allow a retaining property synthesis #162576
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
Conversation
…ynthesis Don't emit a warning when an Objective-C property is defined using copy or strong semantics.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-static-analyzer-1 Author: Ryosuke Niwa (rniwa) ChangesDon't emit a warning when an Objective-C property is defined using copy or strong semantics. Full diff: https://github.com/llvm/llvm-project/pull/162576.diff 2 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
index 15a0c5a7fd9dc..ace639ce7ab18 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
@@ -232,7 +232,7 @@ class RawPtrRefMemberChecker
bool ignoreARC =
!PD->isReadOnly() && PD->getSetterKind() == ObjCPropertyDecl::Assign;
auto IsUnsafePtr = isUnsafePtr(QT, ignoreARC);
- return {IsUnsafePtr && *IsUnsafePtr, PropType};
+ return {IsUnsafePtr && *IsUnsafePtr && !PD->isRetaining(), PropType};
}
bool shouldSkipDecl(const RecordDecl *RD) const {
diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-members.mm b/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
index adf1d8aef9d7d..2b120b9b1385c 100644
--- a/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
+++ b/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
@@ -113,7 +113,6 @@ @interface AnotherObject : NSObject {
// expected-warning@-1{{Instance variable 'dispatch' in 'AnotherObject' is a retainable type 'dispatch_queue_t'}}
}
@property(nonatomic, readonly, strong) NSString *prop_string;
-// expected-warning@-1{{Property 'prop_string' in 'AnotherObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}}
@property(nonatomic, readonly) NSString *prop_safe;
@end
@@ -132,7 +131,6 @@ @interface DerivedObject : AnotherObject {
// expected-warning@-1{{Instance variable 'os_dispatch' in 'DerivedObject' is a retainable type 'dispatch_queue_t'}}
}
@property(nonatomic, strong) NSNumber *prop_number;
-// expected-warning@-1{{Property 'prop_number' in 'DerivedObject' is a raw pointer to retainable type 'NSNumber'; member variables must be a RetainPtr}}
@property(nonatomic, readonly) NSString *prop_string;
@end
@@ -178,12 +176,12 @@ @interface NoSynthObject : NSObject {
}
@property(nonatomic, readonly, strong) NSString *prop_string1;
@property(nonatomic, readonly, strong) NSString *prop_string2;
-// expected-warning@-1{{Property 'prop_string2' in 'NoSynthObject' is a raw pointer to retainable type 'NSString'}}
@property(nonatomic, assign) NSString *prop_string3;
// expected-warning@-1{{Property 'prop_string3' in 'NoSynthObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}}
@property(nonatomic, unsafe_unretained) NSString *prop_string4;
// expected-warning@-1{{Property 'prop_string4' in 'NoSynthObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}}
-@property(nonatomic, readonly, strong) NSString *dispatch;
+@property(nonatomic, copy) NSString *prop_string5;
+@property(nonatomic, readonly, strong) dispatch_queue_t dispatch;
@end
@implementation NoSynthObject
@@ -193,6 +191,7 @@ - (NSString *)prop_string1 {
@synthesize prop_string2;
@synthesize prop_string3;
@synthesize prop_string4;
+@synthesize prop_string5;
- (dispatch_queue_t)dispatch {
return nil;
}
|
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! |
…ynthesis (llvm#162576) Don't emit a warning when an Objective-C property is defined using copy or strong semantics.
…ynthesis (llvm#162576) Don't emit a warning when an Objective-C property is defined using copy or strong semantics.
…ynthesis (llvm#162576) Don't emit a warning when an Objective-C property is defined using copy or strong semantics.
…ynthesis (llvm#162576) Don't emit a warning when an Objective-C property is defined using copy or strong semantics. (cherry picked from commit b7e256d)
Don't emit a warning when an Objective-C property is defined using copy or strong semantics.