Skip to content
Merged
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
6 changes: 5 additions & 1 deletion clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ bool tryToFindPtrOrigin(

auto Name = safeGetName(callee);
if (Name == "__builtin___CFStringMakeConstantString" ||
Name == "NSClassFromString")
Name == "NSStringFromSelector" || Name == "NSSelectorFromString" ||
Name == "NSStringFromClass" || Name == "NSClassFromString" ||
Name == "NSStringFromProtocol" || Name == "NSProtocolFromString")
return callback(E, true);
} else if (auto *CalleeE = call->getCallee()) {
if (auto *E = dyn_cast<DeclRefExpr>(CalleeE->IgnoreParenCasts())) {
Expand Down Expand Up @@ -202,6 +204,8 @@ bool tryToFindPtrOrigin(
!Selector.getNumArgs())
return callback(E, true);
}
if (auto *ObjCProtocol = dyn_cast<ObjCProtocolExpr>(E))
return callback(ObjCProtocol, true);
if (auto *ObjCDict = dyn_cast<ObjCDictionaryLiteral>(E))
return callback(ObjCDict, true);
if (auto *ObjCArray = dyn_cast<ObjCArrayLiteral>(E))
Expand Down
10 changes: 9 additions & 1 deletion clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,20 @@ typedef CVImageBufferRef CVPixelBufferRef;
typedef signed int CVReturn;
CVReturn CVPixelBufferCreateWithIOSurface(CFAllocatorRef allocator, IOSurfaceRef surface, CFDictionaryRef pixelBufferAttributes, CF_RETURNS_RETAINED CVPixelBufferRef * pixelBufferOut);

extern "C" NSString *NSStringFromSelector(SEL aSelector);
extern "C" SEL NSSelectorFromString(NSString *aSelectorName);

extern "C" NSString *NSStringFromClass(Class aClass);
extern "C" Class NSClassFromString(NSString *aClassName);

extern "C" NSString *NSStringFromProtocol(Protocol *proto);
extern "C" Protocol * NSProtocolFromString(NSString *namestr);

CFRunLoopRef CFRunLoopGetCurrent(void);
CFRunLoopRef CFRunLoopGetMain(void);
extern CFTypeRef CFRetain(CFTypeRef cf);
extern void CFRelease(CFTypeRef cf);
#define CFSTR(cStr) ((CFStringRef) __builtin___CFStringMakeConstantString ("" cStr ""))
extern Class NSClassFromString(NSString *aClassName);

#if __has_feature(objc_arc)
id CFBridgingRelease(CFTypeRef X) {
Expand Down
18 changes: 18 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,24 @@ void foo() {

} // autoreleased

namespace sel_string {

void consumeStr(NSString *);
void consumeSel(SEL);
void consumeClass(Class);
void consumeProtocol(Protocol *);

void foo() {
consumeStr(NSStringFromSelector(@selector(mutableCopy)));
consumeSel(NSSelectorFromString(@"mutableCopy"));
consumeStr(NSStringFromClass(NSNumber.class));
consumeClass(NSClassFromString(@"NSNumber"));
consumeStr(NSStringFromProtocol(@protocol(NSCopying)));
consumeProtocol(NSProtocolFromString(@"NSCopying"));
}

} // namespace sel_string

@interface TestObject : NSObject
- (void)doWork:(NSString *)msg, ...;
- (void)doWorkOnSelf;
Expand Down