[clang] 872c431 - [WebKit Checkers] Recognize NSApp as a safe global variable (#160990)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 7 12:09:33 PDT 2025
Author: Ryosuke Niwa
Date: 2025-10-07T12:09:29-07:00
New Revision: 872c4319dfc52886bbac03955ba1b7fe3ce83efc
URL: https://github.com/llvm/llvm-project/commit/872c4319dfc52886bbac03955ba1b7fe3ce83efc
DIFF: https://github.com/llvm/llvm-project/commit/872c4319dfc52886bbac03955ba1b7fe3ce83efc.diff
LOG: [WebKit Checkers] Recognize NSApp as a safe global variable (#160990)
Treat accessing NSApp without retaining it as safe
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 9060ec0f07771..66cfccbecf31f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -31,9 +31,9 @@ bool tryToFindPtrOrigin(
if (auto *DRE = dyn_cast<DeclRefExpr>(E)) {
if (auto *VD = dyn_cast_or_null<VarDecl>(DRE->getDecl())) {
auto QT = VD->getType();
- if (VD->hasGlobalStorage() && QT.isConstQualified()) {
+ auto IsImmortal = safeGetName(VD) == "NSApp";
+ if (VD->hasGlobalStorage() && (IsImmortal || QT.isConstQualified()))
return callback(E, true);
- }
}
}
if (auto *tempExpr = dyn_cast<MaterializeTemporaryExpr>(E)) {
diff --git a/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h b/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
index dacb713130818..a5fc3d7f9a932 100644
--- a/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
+++ b/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
@@ -178,6 +178,22 @@ __attribute__((objc_root_class))
+ (NSNumber *)numberWithBool:(BOOL)value;
@end
+ at interface NSResponder : NSObject
+ at end
+
+ at interface NSApplication : NSResponder
+
+extern NSApplication * NSApp;
+
+ at property (class, readonly, strong) NSApplication *sharedApplication;
+
+- (void)finishLaunching;
+- (void)run;
+- (void)stop:(id)sender;
+- (void)terminate:(id)sender;
+
+ at end
+
@interface SomeObj : NSObject
- (instancetype)_init;
- (SomeObj *)mutableCopy;
diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm b/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
index 7046386e3e49b..a517dbc394dbb 100644
--- a/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
+++ b/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
@@ -588,6 +588,7 @@ - (void)doWorkOnSelf {
[self doWork:@"hello", RetainPtr<SomeObj> { provide() }.get(), RetainPtr<CFMutableArrayRef> { provide_cf() }.get(), OSObjectPtr { provide_dispatch() }.get()];
[self doWork:__null];
[self doWork:nil];
+ [NSApp run];
}
- (SomeObj *)getSomeObj {
More information about the cfe-commits
mailing list