Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,21 @@ void RetainTypeChecker::visitTypedef(const TypedefDecl *TD) {
}
}

bool isNSApplicationCocoaObjectRef(const QualType QT) {
if (const ObjCObjectPointerType *PT = QT->getAs<ObjCObjectPointerType>()) {
const ObjCInterfaceDecl *ID = PT->getInterfaceDecl();
if (ID && ID->getIdentifier()->getName() == "NSApplication")
return true;
}
return false;
}

bool RetainTypeChecker::isUnretained(const QualType QT, bool ignoreARC) {
if (ento::cocoa::isCocoaObjectRef(QT) && (!IsARCEnabled || ignoreARC))
if (ento::cocoa::isCocoaObjectRef(QT) && (!IsARCEnabled || ignoreARC)) {
if (isNSApplicationCocoaObjectRef(QT))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the right place to add this check.

return false;
return true;
}
if (auto *RT = dyn_cast_or_null<RecordType>(
QT.getCanonicalType()->getPointeeType().getTypePtrOrNull()))
return CFPointees.contains(RT);
Expand All @@ -281,8 +293,11 @@ std::optional<bool> isUnretained(const QualType T, bool IsARCEnabled) {
}
}
if ((ento::cocoa::isCocoaObjectRef(T) && !IsARCEnabled) ||
ento::coreFoundation::isCFObjectRef(T))
ento::coreFoundation::isCFObjectRef(T)) {
if (isNSApplicationCocoaObjectRef(T))
return false;
return true;
}

// RetainPtr strips typedef for CF*Ref. Manually check for struct __CF* types.
auto CanonicalType = T.getCanonicalType();
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ __attribute__((objc_root_class))
+ (instancetype)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;
@end

@interface NSApplication : NSObject <NSCopying>
@end

NSApplication * NSApp;

@interface NSArray : NSObject <NSCopying, NSFastEnumeration>
- (NSUInteger)count;
- (NSEnumerator *)objectEnumerator;
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ @interface TestObject : NSObject
- (void)doWork:(NSString *)msg, ...;
- (void)doWorkOnSelf;
- (SomeObj *)getSomeObj;
- (void)callNSApp;
@end

@implementation TestObject
Expand Down Expand Up @@ -600,4 +601,8 @@ - (NSString *)convertImage {
RetainPtr<CGImageRef> image = [self createImage];
return stringForImage(image.get());
}

- (void)callNSApp {
[NSApp foo];
}
@end