Skip to content

Commit b7e256d

Browse files
authored
[alpha.webkit.NoUnretainedMemberChecker] Allow a retaining property synthesis (#162576)
Don't emit a warning when an Objective-C property is defined using copy or strong semantics.
1 parent e02c645 commit b7e256d

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class RawPtrRefMemberChecker
232232
bool ignoreARC =
233233
!PD->isReadOnly() && PD->getSetterKind() == ObjCPropertyDecl::Assign;
234234
auto IsUnsafePtr = isUnsafePtr(QT, ignoreARC);
235-
return {IsUnsafePtr && *IsUnsafePtr, PropType};
235+
return {IsUnsafePtr && *IsUnsafePtr && !PD->isRetaining(), PropType};
236236
}
237237

238238
bool shouldSkipDecl(const RecordDecl *RD) const {

clang/test/Analysis/Checkers/WebKit/unretained-members.mm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ @interface AnotherObject : NSObject {
113113
// expected-warning@-1{{Instance variable 'dispatch' in 'AnotherObject' is a retainable type 'dispatch_queue_t'}}
114114
}
115115
@property(nonatomic, readonly, strong) NSString *prop_string;
116-
// expected-warning@-1{{Property 'prop_string' in 'AnotherObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}}
117116
@property(nonatomic, readonly) NSString *prop_safe;
118117
@end
119118

@@ -132,7 +131,6 @@ @interface DerivedObject : AnotherObject {
132131
// expected-warning@-1{{Instance variable 'os_dispatch' in 'DerivedObject' is a retainable type 'dispatch_queue_t'}}
133132
}
134133
@property(nonatomic, strong) NSNumber *prop_number;
135-
// expected-warning@-1{{Property 'prop_number' in 'DerivedObject' is a raw pointer to retainable type 'NSNumber'; member variables must be a RetainPtr}}
136134
@property(nonatomic, readonly) NSString *prop_string;
137135
@end
138136

@@ -178,12 +176,12 @@ @interface NoSynthObject : NSObject {
178176
}
179177
@property(nonatomic, readonly, strong) NSString *prop_string1;
180178
@property(nonatomic, readonly, strong) NSString *prop_string2;
181-
// expected-warning@-1{{Property 'prop_string2' in 'NoSynthObject' is a raw pointer to retainable type 'NSString'}}
182179
@property(nonatomic, assign) NSString *prop_string3;
183180
// expected-warning@-1{{Property 'prop_string3' in 'NoSynthObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}}
184181
@property(nonatomic, unsafe_unretained) NSString *prop_string4;
185182
// expected-warning@-1{{Property 'prop_string4' in 'NoSynthObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}}
186-
@property(nonatomic, readonly, strong) NSString *dispatch;
183+
@property(nonatomic, copy) NSString *prop_string5;
184+
@property(nonatomic, readonly, strong) dispatch_queue_t dispatch;
187185
@end
188186

189187
@implementation NoSynthObject
@@ -193,6 +191,7 @@ - (NSString *)prop_string1 {
193191
@synthesize prop_string2;
194192
@synthesize prop_string3;
195193
@synthesize prop_string4;
194+
@synthesize prop_string5;
196195
- (dispatch_queue_t)dispatch {
197196
return nil;
198197
}

0 commit comments

Comments
 (0)