Skip to content

Commit 872c431

Browse files
authored
[WebKit Checkers] Recognize NSApp as a safe global variable (#160990)
Treat accessing NSApp without retaining it as safe
1 parent e166816 commit 872c431

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ bool tryToFindPtrOrigin(
3131
if (auto *DRE = dyn_cast<DeclRefExpr>(E)) {
3232
if (auto *VD = dyn_cast_or_null<VarDecl>(DRE->getDecl())) {
3333
auto QT = VD->getType();
34-
if (VD->hasGlobalStorage() && QT.isConstQualified()) {
34+
auto IsImmortal = safeGetName(VD) == "NSApp";
35+
if (VD->hasGlobalStorage() && (IsImmortal || QT.isConstQualified()))
3536
return callback(E, true);
36-
}
3737
}
3838
}
3939
if (auto *tempExpr = dyn_cast<MaterializeTemporaryExpr>(E)) {

clang/test/Analysis/Checkers/WebKit/objc-mock-types.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@ __attribute__((objc_root_class))
178178
+ (NSNumber *)numberWithBool:(BOOL)value;
179179
@end
180180

181+
@interface NSResponder : NSObject
182+
@end
183+
184+
@interface NSApplication : NSResponder
185+
186+
extern NSApplication * NSApp;
187+
188+
@property (class, readonly, strong) NSApplication *sharedApplication;
189+
190+
- (void)finishLaunching;
191+
- (void)run;
192+
- (void)stop:(id)sender;
193+
- (void)terminate:(id)sender;
194+
195+
@end
196+
181197
@interface SomeObj : NSObject
182198
- (instancetype)_init;
183199
- (SomeObj *)mutableCopy;

clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ - (void)doWorkOnSelf {
588588
[self doWork:@"hello", RetainPtr<SomeObj> { provide() }.get(), RetainPtr<CFMutableArrayRef> { provide_cf() }.get(), OSObjectPtr { provide_dispatch() }.get()];
589589
[self doWork:__null];
590590
[self doWork:nil];
591+
[NSApp run];
591592
}
592593

593594
- (SomeObj *)getSomeObj {

0 commit comments

Comments
 (0)