aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2011-10-01 00:48:56 +0000
committerJohn McCall <rjmccall@apple.com>2011-10-01 00:48:56 +0000
commit7df2ff45f101c87398329d0ea23c1377328dca40 (patch)
tree445d7ff7f200040414bfbd39e09c12c36e68a5c5 /lib
parentc4cc403d1e7b020d6d5deb968e4686301a8c83ac (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140911 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/CocoaConventions.cpp12
-rw-r--r--lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp14
2 files changed, 17 insertions, 9 deletions
diff --git a/lib/Analysis/CocoaConventions.cpp b/lib/Analysis/CocoaConventions.cpp
index 3926ce55aa..8acd1892f9 100644
--- a/lib/Analysis/CocoaConventions.cpp
+++ b/lib/Analysis/CocoaConventions.cpp
@@ -125,7 +125,13 @@ bool cocoa::isCocoaObjectRef(QualType Ty) {
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 @@ bool coreFoundation::followsCreateRule(StringRef functionName) {
// 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;
}
diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
index 695cc037e8..0a23d5b6bb 100644
--- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -623,8 +623,7 @@ public:
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 @@ RetainSummary* RetainSummaryManager::getSummary(const FunctionDecl *FD) {
else if (isMakeCollectable(FD, FName))
S = getUnarySummary(FT, cfmakecollectable);
else
- S = getCFCreateGetRuleSummary(FD, FName);
+ S = getCFCreateGetRuleSummary(FD);
break;
}
@@ -1010,7 +1009,7 @@ RetainSummary* RetainSummaryManager::getSummary(const FunctionDecl *FD) {
if (isRetain(FD, FName))
S = getUnarySummary(FT, cfretain);
else
- S = getCFCreateGetRuleSummary(FD, FName);
+ S = getCFCreateGetRuleSummary(FD);
break;
}
@@ -1019,7 +1018,7 @@ RetainSummary* RetainSummaryManager::getSummary(const FunctionDecl *FD) {
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::getSummary(const FunctionDecl *FD) {
}
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);