[cfe-commits] r135349 - in /cfe/trunk: include/clang/Analysis/DomainSpecific/CocoaConventions.h lib/Analysis/CocoaConventions.cpp lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp lib/StaticAnalyzer/Core/CFRefCount.cpp

Ted Kremenek kremenek at apple.com
Sat Jul 16 12:50:33 PDT 2011


Author: kremenek
Date: Sat Jul 16 14:50:32 2011
New Revision: 135349

URL: http://llvm.org/viewvc/llvm-project?rev=135349&view=rev
Log:
[analyzer] Place checking for Core Foundation "Create" rule into a proper API.  No functionality change.

Modified:
    cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h
    cfe/trunk/lib/Analysis/CocoaConventions.cpp
    cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp

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=135349&r1=135348&r2=135349&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h (original)
+++ cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h Sat Jul 16 14:50:32 2011
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_ANALYSIS_DS_COCOA
 #define LLVM_CLANG_ANALYSIS_DS_COCOA
 
+#include "llvm/ADT/StringRef.h"
 #include "clang/AST/Type.h"
 
 namespace clang {
@@ -34,11 +35,17 @@
   
   bool isRefType(QualType RetTy, llvm::StringRef Prefix,
                  llvm::StringRef Name = llvm::StringRef());
-  
+    
+  bool isCocoaObjectRef(QualType T);
+
+}
+
+namespace coreFoundation {
   bool isCFObjectRef(QualType T);
   
-  bool isCocoaObjectRef(QualType T);
+  bool followsCreateRule(llvm::StringRef functionName);
+}
 
-}}}
+}} // end: "clang:ento"
 
 #endif

Modified: cfe/trunk/lib/Analysis/CocoaConventions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CocoaConventions.cpp?rev=135349&r1=135348&r2=135349&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CocoaConventions.cpp (original)
+++ cfe/trunk/lib/Analysis/CocoaConventions.cpp Sat Jul 16 14:50:32 2011
@@ -86,12 +86,12 @@
   return Name.startswith(Prefix);
 }
 
-bool cocoa::isCFObjectRef(QualType T) {
-  return isRefType(T, "CF") || // Core Foundation.
-         isRefType(T, "CG") || // Core Graphics.
-         isRefType(T, "DADisk") || // Disk Arbitration API.
-         isRefType(T, "DADissenter") ||
-         isRefType(T, "DASessionRef");
+bool coreFoundation::isCFObjectRef(QualType T) {
+  return cocoa::isRefType(T, "CF") || // Core Foundation.
+         cocoa::isRefType(T, "CG") || // Core Graphics.
+         cocoa::isRefType(T, "DADisk") || // Disk Arbitration API.
+         cocoa::isRefType(T, "DADissenter") ||
+         cocoa::isRefType(T, "DASessionRef");
 }
 
 
@@ -126,3 +126,8 @@
   
   return false;
 }
+
+bool coreFoundation::followsCreateRule(llvm::StringRef functionName) {
+  return functionName.find("Create") != StringRef::npos ||
+         functionName.find("Copy") != StringRef::npos;
+}

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp?rev=135349&r1=135348&r2=135349&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp Sat Jul 16 14:50:32 2011
@@ -606,7 +606,7 @@
       continue;
     
     // Ignore CF references, which can be toll-free bridged.
-    if (cocoa::isCFObjectRef(ArgTy))
+    if (coreFoundation::isCFObjectRef(ArgTy))
       continue;
 
     // Generate only one error node to use for all bug reports.

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp?rev=135349&r1=135348&r2=135349&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp Sat Jul 16 14:50:32 2011
@@ -1135,8 +1135,7 @@
 RetainSummary*
 RetainSummaryManager::getCFCreateGetRuleSummary(const FunctionDecl* FD,
                                                 StringRef FName) {
-  if (FName.find("Create") != StringRef::npos ||
-      FName.find("Copy") != StringRef::npos)
+  if (coreFoundation::followsCreateRule(FName))
     return getCFSummaryCreateRule(FD);
 
   return getCFSummaryGetRule(FD);
@@ -1206,7 +1205,8 @@
   assert(ScratchArgs.isEmpty());
   // 'init' methods conceptually return a newly allocated object and claim
   // the receiver.
-  if (cocoa::isCocoaObjectRef(RetTy) || cocoa::isCFObjectRef(RetTy))
+  if (cocoa::isCocoaObjectRef(RetTy) ||
+      coreFoundation::isCFObjectRef(RetTy))
     return getPersistentSummary(ObjCInitRetE, DecRefMsg);
 
   return getDefaultSummary();
@@ -1356,7 +1356,7 @@
   }
 
   // Look for methods that return an owned core foundation object.
-  if (cocoa::isCFObjectRef(RetTy)) {
+  if (coreFoundation::isCFObjectRef(RetTy)) {
     RetEffect E = cocoa::followsFundamentalRule(S, MD)
       ? RetEffect::MakeOwned(RetEffect::CF, true)
       : RetEffect::MakeNotOwned(RetEffect::CF);





More information about the cfe-commits mailing list