r278382 - [analyzer] Teach RetainCountChecker about CVFooRetain
Devin Coughlin via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 11 11:41:29 PDT 2016
Author: dcoughlin
Date: Thu Aug 11 13:41:29 2016
New Revision: 278382
URL: http://llvm.org/viewvc/llvm-project?rev=278382&view=rev
Log:
[analyzer] Teach RetainCountChecker about CVFooRetain
Change the retain count checker to treat CoreFoundation-style "CV"-prefixed
reference types from CoreVideo similarly to CoreGraphics types. With this
change, we treat CVFooRetain() on a CVFooRef type as a retain. CVFooRelease()
APIs are annotated as consuming their parameter, so this change prevents false
positives about incorrect decrements of reference counts.
<rdar://problem/27116090>
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
cfe/trunk/test/Analysis/retain-release.m
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp?rev=278382&r1=278381&r2=278382&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp Thu Aug 11 13:41:29 2016
@@ -1171,8 +1171,9 @@ RetainSummaryManager::getFunctionSummary
break;
}
- // For CoreGraphics ('CG') types.
- if (cocoa::isRefType(RetTy, "CG", FName)) {
+ // For CoreGraphics ('CG') and CoreVideo ('CV') types.
+ if (cocoa::isRefType(RetTy, "CG", FName) ||
+ cocoa::isRefType(RetTy, "CV", FName)) {
if (isRetain(FD, FName))
S = getUnarySummary(FT, cfretain);
else
@@ -3372,12 +3373,13 @@ bool RetainCountChecker::evalCall(const
// Handle: id NSMakeCollectable(CFTypeRef)
canEval = II->isStr("NSMakeCollectable");
} else if (ResultTy->isPointerType()) {
- // Handle: (CF|CG)Retain
+ // Handle: (CF|CG|CV)Retain
// CFAutorelease
// CFMakeCollectable
// It's okay to be a little sloppy here (CGMakeCollectable doesn't exist).
if (cocoa::isRefType(ResultTy, "CF", FName) ||
- cocoa::isRefType(ResultTy, "CG", FName)) {
+ cocoa::isRefType(ResultTy, "CG", FName) ||
+ cocoa::isRefType(ResultTy, "CV", FName)) {
canEval = isRetain(FD, FName) || isAutorelease(FD, FName) ||
isMakeCollectable(FD, FName);
}
Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=278382&r1=278381&r2=278382&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Thu Aug 11 13:41:29 2016
@@ -1247,6 +1247,26 @@ CVReturn rdar_7283567_2(CFAllocatorRef a
pixelBufferAttributes, pixelBufferOut) ;
}
+#pragma clang arc_cf_code_audited begin
+typedef struct SomeOpaqueStruct *CMSampleBufferRef;
+CVImageBufferRef _Nonnull CMSampleBufferGetImageBuffer(CMSampleBufferRef _Nonnull sbuf);
+#pragma clang arc_cf_code_audited end
+
+CVBufferRef _Nullable CVBufferRetain(CVBufferRef _Nullable buffer);
+void CVBufferRelease(CF_CONSUMED CVBufferRef _Nullable buffer);
+
+void testCVPrefixRetain(CMSampleBufferRef sbuf) {
+ // Make sure RetainCountChecker treats CVFooRetain() as a CF-style retain.
+ CVPixelBufferRef pixelBuf = CMSampleBufferGetImageBuffer(sbuf);
+ CVBufferRetain(pixelBuf);
+ CVBufferRelease(pixelBuf); // no-warning
+
+
+ // Make sure result of CVFooRetain() is the same as its argument.
+ CVPixelBufferRef pixelBufAlias = CVBufferRetain(pixelBuf);
+ CVBufferRelease(pixelBufAlias); // no-warning
+}
+
//===----------------------------------------------------------------------===//
// <rdar://problem/7358899> False leak associated with
// CGBitmapContextCreateWithData
More information about the cfe-commits
mailing list