Skip to content

Commit 01acb62

Browse files
committed
followsFundamentalRule() returns true if "alloc" or "new" appear at the beginning of the string, not anywhere within it.
llvm-svn: 58112
1 parent 8d8a14a commit 01acb62

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

clang/lib/Analysis/CFRefCount.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,30 @@
3434
#include <stdarg.h>
3535

3636
using namespace clang;
37+
38+
//===----------------------------------------------------------------------===//
39+
// Utility functions.
40+
//===----------------------------------------------------------------------===//
41+
3742
using llvm::CStrInCStrNoCase;
3843

44+
// The "fundamental rule" for naming conventions of methods:
45+
// (url broken into two lines)
46+
// http://developer.apple.com/documentation/Cocoa/Conceptual/
47+
// MemoryMgmt/Tasks/MemoryManagementRules.html
48+
//
49+
// "You take ownership of an object if you create it using a method whose name
50+
// begins with “alloc” or “new” or contains “copy” (for example, alloc,
51+
// newObject, or mutableCopy), or if you send it a retain message. You are
52+
// responsible for relinquishing ownership of objects you own using release
53+
// or autorelease. Any other time you receive an object, you must
54+
// not release it."
55+
//
56+
static bool followsFundamentalRule(const char* s) {
57+
return CStrInCStrNoCase(s, "create") || CStrInCStrNoCase(s, "copy") ||
58+
CStrInCStrNoCase(s, "new") == s || CStrInCStrNoCase(s, "alloc") == s;
59+
}
60+
3961
//===----------------------------------------------------------------------===//
4062
// Selector creation functions.
4163
//===----------------------------------------------------------------------===//
@@ -1834,22 +1856,6 @@ void CFRefCount::EvalStore(ExplodedNodeSet<GRState>& Dst,
18341856

18351857
// End-of-path.
18361858

1837-
// The "fundamental rule" for naming conventions of methods:
1838-
// (url broken into two lines)
1839-
// http://developer.apple.com/documentation/Cocoa/Conceptual/
1840-
// MemoryMgmt/Tasks/MemoryManagementRules.html
1841-
//
1842-
// "You take ownership of an object if you create it using a method whose name
1843-
// begins with “alloc” or “new” or contains “copy” (for example, alloc,
1844-
// newObject, or mutableCopy), or if you send it a retain message. You are
1845-
// responsible for relinquishing ownership of objects you own using release
1846-
// or autorelease. Any other time you receive an object, you must
1847-
// not release it."
1848-
//
1849-
static bool followsFundamentalRule(const char* s) {
1850-
return CStrInCStrNoCase(s, "create") || CStrInCStrNoCase(s, "copy") ||
1851-
CStrInCStrNoCase(s, "new");
1852-
}
18531859

18541860
std::pair<GRStateRef,bool>
18551861
CFRefCount::HandleSymbolDeath(GRStateManager& VMgr,

0 commit comments

Comments
 (0)