[cfe-commits] r140911 - in /cfe/trunk: include/clang/Analysis/DomainSpecific/CocoaConventions.h lib/Analysis/CocoaConventions.cpp lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp test/Analysis/retain-release.mm

John McCall rjmccall at apple.com
Fri Sep 30 19:48:57 CDT 2011


Author: rjmccall
Date: Fri Sep 30 19:48:56 2011
New Revision: 140911

URL: http://llvm.org/viewvc/llvm-project?rev=140911&view=rev
Log:
Tweak the interface for analyzing the CF conventions for a name
to take a FunctionDecl* instead of an llvm::StringRef.  Eventually
we might push more logic in there, like using slightly different
conventions for C++ methods.

Also, fix a bug where 'copy' and 'create' were being caught in 
non-camel-cased strings.  We want copyFoo and CopyFoo and XCopy
but not Xcopy or xcopy.


Modified:
    cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h
    cfe/trunk/lib/Analysis/CocoaConventions.cpp
    cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
    cfe/trunk/test/Analysis/retain-release.mm

Modified: cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h?rev=140911&r1=140910&r2=140911&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h (original)
+++ cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h Fri Sep 30 19:48:56 2011
@@ -14,12 +14,13 @@
 #ifndef LLVM_CLANG_ANALYSIS_DS_COCOA
 #define LLVM_CLANG_ANALYSIS_DS_COCOA
 
+#include "clang/Basic/IdentifierTable.h"
 #include "llvm/ADT/StringRef.h"
-#include "clang/AST/Type.h"
 
 namespace clang {
-  
+class FunctionDecl;
 class ObjCMethodDecl;
+class QualType;
   
 namespace ento {
 namespace cocoa {
@@ -43,7 +44,7 @@
 namespace coreFoundation {
   bool isCFObjectRef(QualType T);
   
-  bool followsCreateRule(StringRef functionName);
+  bool followsCreateRule(const FunctionDecl *FD);
 }
 
 }} // end: "clang:ento"

Modified: cfe/trunk/lib/Analysis/CocoaConventions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CocoaConventions.cpp?rev=140911&r1=140910&r2=140911&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CocoaConventions.cpp (original)
+++ cfe/trunk/lib/Analysis/CocoaConventions.cpp Fri Sep 30 19:48:56 2011
@@ -125,7 +125,13 @@
   return false;
 }
 
-bool coreFoundation::followsCreateRule(StringRef functionName) {
+bool coreFoundation::followsCreateRule(const FunctionDecl *fn) {
+  // For now, *just* base this on the function name, not on anything else.
+
+  const IdentifierInfo *ident = fn->getIdentifier();
+  if (!ident) return false;
+  StringRef functionName = ident->getName();
+  
   StringRef::iterator it = functionName.begin();
   StringRef::iterator start = it;
   StringRef::iterator endI = functionName.end();
@@ -136,6 +142,10 @@
       // Search for the first character.  It can either be 'C' or 'c'.
       char ch = *it;
       if (ch == 'C' || ch == 'c') {
+        // Make sure this isn't something like 'recreate' or 'Scopy'.
+        if (ch == 'c' && it != start && isalpha(*(it - 1)))
+          continue;
+
         ++it;
         break;
       }

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp?rev=140911&r1=140910&r2=140911&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp Fri Sep 30 19:48:56 2011
@@ -623,8 +623,7 @@
 
   RetainSummary* getCFSummaryCreateRule(const FunctionDecl *FD);
   RetainSummary* getCFSummaryGetRule(const FunctionDecl *FD);
-  RetainSummary* getCFCreateGetRuleSummary(const FunctionDecl *FD, 
-                                           StringRef FName);
+  RetainSummary* getCFCreateGetRuleSummary(const FunctionDecl *FD);
 
   RetainSummary* getPersistentSummary(ArgEffects AE, RetEffect RetEff,
                                       ArgEffect ReceiverEff = DoNothing,
@@ -1000,7 +999,7 @@
         else if (isMakeCollectable(FD, FName))
           S = getUnarySummary(FT, cfmakecollectable);
         else
-          S = getCFCreateGetRuleSummary(FD, FName);
+          S = getCFCreateGetRuleSummary(FD);
 
         break;
       }
@@ -1010,7 +1009,7 @@
         if (isRetain(FD, FName))
           S = getUnarySummary(FT, cfretain);
         else
-          S = getCFCreateGetRuleSummary(FD, FName);
+          S = getCFCreateGetRuleSummary(FD);
 
         break;
       }
@@ -1019,7 +1018,7 @@
       if (cocoa::isRefType(RetTy, "DADisk") ||
           cocoa::isRefType(RetTy, "DADissenter") ||
           cocoa::isRefType(RetTy, "DASessionRef")) {
-        S = getCFCreateGetRuleSummary(FD, FName);
+        S = getCFCreateGetRuleSummary(FD);
         break;
       }
 
@@ -1072,9 +1071,8 @@
 }
 
 RetainSummary*
-RetainSummaryManager::getCFCreateGetRuleSummary(const FunctionDecl *FD,
-                                                StringRef FName) {
-  if (coreFoundation::followsCreateRule(FName))
+RetainSummaryManager::getCFCreateGetRuleSummary(const FunctionDecl *FD) {
+  if (coreFoundation::followsCreateRule(FD))
     return getCFSummaryCreateRule(FD);
 
   return getCFSummaryGetRule(FD);

Modified: cfe/trunk/test/Analysis/retain-release.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.mm?rev=140911&r1=140910&r2=140911&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release.mm (original)
+++ cfe/trunk/test/Analysis/retain-release.mm Fri Sep 30 19:48:56 2011
@@ -304,4 +304,14 @@
   foo.noAdopt(x);
 }
 
+extern CFStringRef ElectronMicroscopyEngage(void);
+void test_microscopy() {
+  NSString *token = (NSString*) ElectronMicroscopyEngage();
+  [token release]; // expected-warning {{object that is not owned}}
+}
 
+extern CFStringRef Scopy(void);
+void test_Scopy() {
+  NSString *token = (NSString*) Scopy();
+  [token release]; // expected-warning {{object that is not owned}}
+}




More information about the cfe-commits mailing list