From: Devin Coughlin Date: Thu, 11 Aug 2016 18:41:29 +0000 (+0000) Subject: [analyzer] Teach RetainCountChecker about CVFooRetain X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=271e3dbddedabb82291728cb87e700bdb72e2369;p=clang [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@278382 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp index b646127cfa..6bb072710f 100644 --- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp @@ -1171,8 +1171,9 @@ RetainSummaryManager::getFunctionSummary(const FunctionDecl *FD) { 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 CallExpr *CE, CheckerContext &C) 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); } diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index f0d91e34c1..3acf86c7d9 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -1247,6 +1247,26 @@ CVReturn rdar_7283567_2(CFAllocatorRef allocator, size_t width, size_t height, 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 +} + //===----------------------------------------------------------------------===// // False leak associated with // CGBitmapContextCreateWithData