[analyzer] Hotfix for RetainCountChecker: assert was too strong.

Bridged casts can happen to non-CF objects as well.

llvm-svn: 352938
This commit is contained in:
George Karpenkov 2019-02-01 23:06:44 +00:00
parent 00056ed0e6
commit 77b3530865
2 changed files with 18 additions and 4 deletions

View File

@ -187,11 +187,10 @@ void RetainCountChecker::checkPostStmt(const CastExpr *CE,
QualType QT = CE->getType();
ObjKind K;
if (coreFoundation::isCFObjectRef(QT)) {
K = ObjKind::CF;
} else {
assert(cocoa::isCocoaObjectRef(QT));
if (QT->isObjCObjectPointerType()) {
K = ObjKind::ObjC;
} else {
K = ObjKind::CF;
}
ArgEffect AE = ArgEffect(IncRef, K);

View File

@ -239,8 +239,23 @@ extern const CFAllocatorRef kCFAllocatorDefault;
extern CFTypeRef CFRetain(CFTypeRef cf);
extern void CFRelease(CFTypeRef cf);
void check_bridge_retained_cast() {
NSString *nsStr = [[NSString alloc] init];
CFStringRef cfStr = (__bridge_retained CFStringRef)nsStr;
CFRelease(cfStr); // no-warning
}
@interface A;
@end
void check_bridge_to_non_cocoa(CFStringRef s) {
A *a = (__bridge_transfer A *) s; // no-crash
}
struct B;
struct B * check_bridge_to_non_cf() {
NSString *s = [[NSString alloc] init];
return (__bridge struct B*) s;
}