]> granicus.if.org Git - clang/commitdiff
Teach RetainCountChecker about 'pragma clang arc_cf_code_audited'.
authorTed Kremenek <kremenek@apple.com>
Thu, 30 Aug 2012 19:27:02 +0000 (19:27 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 30 Aug 2012 19:27:02 +0000 (19:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162934 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
test/Analysis/retain-release.m

index 93a77f440b51f3989e78454ebfd4c45dbdfd9df8..6710bfd3a5bf7084ece4185997ff5541ea8d8809 100644 (file)
@@ -1145,6 +1145,11 @@ RetainSummaryManager::getFunctionSummary(const FunctionDecl *FD) {
       break;
 
     if (RetTy->isPointerType()) {
+      if (FD->getAttr<CFAuditedTransferAttr>()) {
+        S = getCFCreateGetRuleSummary(FD);
+        break;
+      }
+      
       // For CoreFoundation ('CF') types.
       if (cocoa::isRefType(RetTy, "CF", FName)) {
         if (isRetain(FD, FName))
index da1477bb5888ba31a879a7dbdff77596d899916e..4280d69ba5cd0dfa62c24ba4ab6b1b81db45856e 100644 (file)
@@ -1885,3 +1885,16 @@ void testCFConsumeAndStopTracking() {
   id unretained = @[]; // +0
   CFConsumeAndStopTracking((CFTypeRef)unretained, ^{}); // expected-warning {{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}}
 }
+//===----------------------------------------------------------------------===//
+// Test 'pragma clang arc_cf_code_audited' support.
+//===----------------------------------------------------------------------===//
+
+typedef void *MyCFType;
+#pragma clang arc_cf_code_audited begin
+MyCFType CreateMyCFType();
+#pragma clang arc_cf_code_audited end 
+    
+void test_custom_cf() {
+  MyCFType x = CreateMyCFType(); // expected-warning {{leak of an object stored into 'x'}}
+}
+