Skip to content

Commit e369e9c

Browse files
committed
[alpha.webkit.NoUnretainedMemberChecker] Only check @Property when @implementation is seen
A @interface declaration with a raw pointer @Property does not necessarily mean it synthesizes ivar of that type. To determine whether such a synthesis happens or not, we must wait for @implementation to appear. So this PR makes the checker only validate @Property then.
1 parent 38f2a1c commit e369e9c

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,16 @@ class RawPtrRefMemberChecker
129129
if (BR->getSourceManager().isInSystemHeader(CD->getLocation()))
130130
return;
131131

132-
ObjCContainerDecl::PropertyMap map;
133-
CD->collectPropertiesToImplement(map);
134-
for (auto it : map)
135-
visitObjCPropertyDecl(CD, it.second);
136-
137-
if (auto *ID = dyn_cast<ObjCInterfaceDecl>(CD)) {
138-
for (auto *Ivar : ID->ivars())
139-
visitIvarDecl(CD, Ivar);
140-
return;
141-
}
142132
if (auto *ID = dyn_cast<ObjCImplementationDecl>(CD)) {
133+
ObjCContainerDecl::PropertyMap map;
134+
CD->collectPropertiesToImplement(map);
135+
for (auto it : map)
136+
visitObjCPropertyDecl(CD, it.second);
137+
138+
if (auto *Interface = ID->getClassInterface()) {
139+
for (auto *Ivar : Interface->ivars())
140+
visitIvarDecl(CD, Ivar);
141+
}
143142
for (auto *PropImpl : ID->property_impls())
144143
visitPropImpl(CD, PropImpl);
145144
for (auto *Ivar : ID->ivars())

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ @interface AnotherObject : NSObject {
7676
@property(nonatomic, unsafe_unretained) NSString *prop_string3;
7777
// expected-warning@-1{{Property 'prop_string3' in 'AnotherObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}}
7878
@property(nonatomic, readonly) NSString *prop_string4;
79+
@property(nonatomic, readonly) NSString *prop_safe;
80+
@end
81+
82+
@implementation AnotherObject
83+
- (NSString *)prop_safe {
84+
return nil;
85+
}
86+
@end
87+
88+
// No warnings for @interface declaration itself.
89+
@interface InterfaceOnlyObject : NSObject
90+
@property(nonatomic, strong) NSString *prop_string1;
91+
@property(nonatomic, assign) NSString *prop_string2;
92+
@property(nonatomic, unsafe_unretained) NSString *prop_string3;
93+
@property(nonatomic, readonly) NSString *prop_string4;
7994
@end
8095

8196
NS_REQUIRES_PROPERTY_DEFINITIONS

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ @interface AnotherObject : NSObject {
9898
}
9999
@property(nonatomic, strong) NSString *prop_string;
100100
// expected-warning@-1{{Property 'prop_string' in 'AnotherObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}}
101+
@property(nonatomic, readonly) NSString *prop_safe;
102+
@end
103+
104+
@implementation AnotherObject
105+
- (NSString *)prop_safe {
106+
return nil;
107+
}
108+
@end
109+
110+
// No warnings for @interface declaration itself.
111+
@interface InterfaceOnlyObject : NSObject
112+
@property(nonatomic, strong) NSString *prop_string1;
113+
@property(nonatomic, assign) NSString *prop_string2;
114+
@property(nonatomic, unsafe_unretained) NSString *prop_string3;
115+
@property(nonatomic, readonly) NSString *prop_string4;
101116
@end
102117

103118
NS_REQUIRES_PROPERTY_DEFINITIONS

0 commit comments

Comments
 (0)