Skip to content

Commit 77b3530

Browse files
author
George Karpenkov
committed
[analyzer] Hotfix for RetainCountChecker: assert was too strong.
Bridged casts can happen to non-CF objects as well. llvm-svn: 352938
1 parent 00056ed commit 77b3530

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,10 @@ void RetainCountChecker::checkPostStmt(const CastExpr *CE,
187187

188188
QualType QT = CE->getType();
189189
ObjKind K;
190-
if (coreFoundation::isCFObjectRef(QT)) {
191-
K = ObjKind::CF;
192-
} else {
193-
assert(cocoa::isCocoaObjectRef(QT));
190+
if (QT->isObjCObjectPointerType()) {
194191
K = ObjKind::ObjC;
192+
} else {
193+
K = ObjKind::CF;
195194
}
196195

197196
ArgEffect AE = ArgEffect(IncRef, K);

clang/test/Analysis/objc-arc.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,23 @@ id rdar14061675() {
239239
extern CFTypeRef CFRetain(CFTypeRef cf);
240240
extern void CFRelease(CFTypeRef cf);
241241

242+
242243
void check_bridge_retained_cast() {
243244
NSString *nsStr = [[NSString alloc] init];
244245
CFStringRef cfStr = (__bridge_retained CFStringRef)nsStr;
245246
CFRelease(cfStr); // no-warning
246247
}
248+
249+
@interface A;
250+
@end
251+
252+
void check_bridge_to_non_cocoa(CFStringRef s) {
253+
A *a = (__bridge_transfer A *) s; // no-crash
254+
}
255+
256+
struct B;
257+
258+
struct B * check_bridge_to_non_cf() {
259+
NSString *s = [[NSString alloc] init];
260+
return (__bridge struct B*) s;
261+
}

0 commit comments

Comments
 (0)