From 47571176b5d5955cf8e828250d475b230e56c0ef Mon Sep 17 00:00:00 2001 From: George Karpenkov Date: Fri, 1 Feb 2019 23:06:44 +0000 Subject: [PATCH] [analyzer] Hotfix for RetainCountChecker: assert was too strong. Bridged casts can happen to non-CF objects as well. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352938 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../RetainCountChecker/RetainCountChecker.cpp | 7 +++---- test/Analysis/objc-arc.m | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp index 9d2d8cd82a..cdda327d62 100644 --- a/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp @@ -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); diff --git a/test/Analysis/objc-arc.m b/test/Analysis/objc-arc.m index c5549fae84..30e4ffcadd 100644 --- a/test/Analysis/objc-arc.m +++ b/test/Analysis/objc-arc.m @@ -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; +} -- 2.50.1