From 0556048ae8ff743d0abb9fa88a0d0ee8e9123742 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sat, 16 Jul 2011 19:50:32 +0000 Subject: [PATCH] [analyzer] Place checking for Core Foundation "Create" rule into a proper API. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135349 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Analysis/DomainSpecific/CocoaConventions.h | 13 ++++++++++--- lib/Analysis/CocoaConventions.cpp | 17 +++++++++++------ .../Checkers/BasicObjCFoundationChecks.cpp | 2 +- lib/StaticAnalyzer/Core/CFRefCount.cpp | 8 ++++---- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/include/clang/Analysis/DomainSpecific/CocoaConventions.h b/include/clang/Analysis/DomainSpecific/CocoaConventions.h index 43e7bd236e..5a4e06ff53 100644 --- a/include/clang/Analysis/DomainSpecific/CocoaConventions.h +++ b/include/clang/Analysis/DomainSpecific/CocoaConventions.h @@ -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 diff --git a/lib/Analysis/CocoaConventions.cpp b/lib/Analysis/CocoaConventions.cpp index 9068ca3949..428032bee5 100644 --- a/lib/Analysis/CocoaConventions.cpp +++ b/lib/Analysis/CocoaConventions.cpp @@ -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; +} diff --git a/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp b/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp index 235b400eb9..9fc8163ab8 100644 --- a/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp +++ b/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp @@ -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. diff --git a/lib/StaticAnalyzer/Core/CFRefCount.cpp b/lib/StaticAnalyzer/Core/CFRefCount.cpp index 8306b7f524..bf53029208 100644 --- a/lib/StaticAnalyzer/Core/CFRefCount.cpp +++ b/lib/StaticAnalyzer/Core/CFRefCount.cpp @@ -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); -- 2.40.0