]> granicus.if.org Git - clang/commitdiff
[analyzer] Place checking for Core Foundation "Create" rule into a proper API. No...
authorTed Kremenek <kremenek@apple.com>
Sat, 16 Jul 2011 19:50:32 +0000 (19:50 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 16 Jul 2011 19:50:32 +0000 (19:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135349 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/DomainSpecific/CocoaConventions.h
lib/Analysis/CocoaConventions.cpp
lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
lib/StaticAnalyzer/Core/CFRefCount.cpp

index 43e7bd236e1d14fabdedb936a1c255b54bc3a60d..5a4e06ff53e57f6a62ec0bacddf253aca86768f2 100644 (file)
@@ -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 @@ namespace cocoa {
   
   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
index 9068ca39493e12f1c1b91899b02afaead874ba51..428032bee547079c1e317651f98893ce357076f0 100644 (file)
@@ -86,12 +86,12 @@ bool cocoa::isRefType(QualType RetTy, llvm::StringRef Prefix,
   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 @@ bool cocoa::isCocoaObjectRef(QualType Ty) {
   
   return false;
 }
+
+bool coreFoundation::followsCreateRule(llvm::StringRef functionName) {
+  return functionName.find("Create") != StringRef::npos ||
+         functionName.find("Copy") != StringRef::npos;
+}
index 235b400eb9e3f3b1cbc1303c1bad6de855acc920..9fc8163ab8b9582fb1c580e9206fd03569993e4e 100644 (file)
@@ -606,7 +606,7 @@ void VariadicMethodTypeChecker::checkPreObjCMessage(ObjCMessage msg,
       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.
index 8306b7f524c1b9aa884ada44cc9618fb1ab339a4..bf5302920819b7226c1bc01cb5a85d3894ac5d76 100644 (file)
@@ -1135,8 +1135,7 @@ RetainSummary* RetainSummaryManager::getSummary(const FunctionDecl* FD) {
 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 @@ RetainSummaryManager::getInitMethodSummary(QualType RetTy) {
   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 @@ RetainSummaryManager::getCommonMethodSummary(const ObjCMethodDecl* MD,
   }
 
   // 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);