r176463 - [analyzer] Don't let cf_audited_transfer override CFRetain semantics.

Jordan Rose jordan_rose at apple.com
Mon Mar 4 15:21:32 PST 2013


Author: jrose
Date: Mon Mar  4 17:21:32 2013
New Revision: 176463

URL: http://llvm.org/viewvc/llvm-project?rev=176463&view=rev
Log:
[analyzer] Don't let cf_audited_transfer override CFRetain semantics.

We weren't treating a cf_audited_transfer CFRetain as returning +1 because
its name doesn't contain "Create" or "Copy". Oops! Fortunately, the
standard definitions of these functions are not marked audited.

<rdar://problem/13339601>

Added:
    cfe/trunk/test/Analysis/retain-release-cf-audited.m
Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp?rev=176463&r1=176462&r2=176463&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp Mon Mar  4 17:21:32 2013
@@ -1133,12 +1133,7 @@ RetainSummaryManager::getFunctionSummary
     if (S)
       break;
 
-    if (RetTy->isPointerType()) {
-      if (FD->getAttr<CFAuditedTransferAttr>()) {
-        S = getCFCreateGetRuleSummary(FD);
-        break;
-      }
-      
+    if (RetTy->isPointerType()) {      
       // For CoreFoundation ('CF') types.
       if (cocoa::isRefType(RetTy, "CF", FName)) {
         if (isRetain(FD, FName))
@@ -1168,6 +1163,11 @@ RetainSummaryManager::getFunctionSummary
         S = getCFCreateGetRuleSummary(FD);
         break;
       }
+
+      if (FD->getAttr<CFAuditedTransferAttr>()) {
+        S = getCFCreateGetRuleSummary(FD);
+        break;
+      }
 
       break;
     }

Added: cfe/trunk/test/Analysis/retain-release-cf-audited.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release-cf-audited.m?rev=176463&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/retain-release-cf-audited.m (added)
+++ cfe/trunk/test/Analysis/retain-release-cf-audited.m Mon Mar  4 17:21:32 2013
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.cocoa.RetainCount -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.cocoa.RetainCount -verify %s -x objective-c++
+
+// The special thing about this file is that CFRetain and CFRelease are marked
+// as cf_audited_transfer.
+
+#pragma clang arc_cf_code_audited begin
+typedef const void * CFTypeRef;
+extern CFTypeRef CFRetain(CFTypeRef cf);
+extern void CFRelease(CFTypeRef cf);
+
+extern CFTypeRef CFCreateSomethingAudited();
+#pragma clang arc_cf_code_audited end
+
+extern CFTypeRef CFCreateSomethingUnaudited();
+
+void testAudited() {
+  CFTypeRef obj = CFCreateSomethingAudited(); // no-warning
+  CFRelease(obj); // no-warning
+
+  CFTypeRef obj2 = CFCreateSomethingAudited(); // expected-warning{{leak}}
+  CFRetain(obj2); // no-warning
+  CFRelease(obj2); // no-warning
+}
+
+void testUnaudited() {
+  CFTypeRef obj = CFCreateSomethingUnaudited(); // no-warning
+  CFRelease(obj); // no-warning
+
+  CFTypeRef obj2 = CFCreateSomethingUnaudited(); // expected-warning{{leak}}
+  CFRetain(obj2); // no-warning
+  CFRelease(obj2); // no-warning
+}





More information about the cfe-commits mailing list