aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-10-20 00:13:00 +0000
committerTed Kremenek <kremenek@apple.com>2009-10-20 00:13:00 +0000
commite9731832ec3b995defba821ec24343d74d004f9f (patch)
tree8ce07f483d8b7ba82171b8cd5bf3ef1db69382a8
parent035c46fee8dd0a4e5a21fc29674297d41da9ec96 (diff)
retain/release checker: allow 'new', 'copy', 'alloc', 'init' prefix to start before '_' when determining Cocoa fundamental rule.
Fixes: <rdar://problem/7265711> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84569 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/CFRefCount.cpp10
-rw-r--r--test/Analysis/refcnt_naming.m4
-rw-r--r--test/Analysis/retain-release.m22
3 files changed, 30 insertions, 6 deletions
diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp
index 50ddbba5b2..c629ad1d96 100644
--- a/lib/Analysis/CFRefCount.cpp
+++ b/lib/Analysis/CFRefCount.cpp
@@ -93,12 +93,14 @@ static NamingConvention deriveNamingConvention(Selector S) {
// Skip '_'.
if (*s == '_') {
if (InPossiblePrefix) {
+ // If we already have a convention, return it. Otherwise, skip
+ // the prefix as if it wasn't there.
+ if (C != NoConvention)
+ break;
+
InPossiblePrefix = false;
AtBeginning = true;
- // Discard whatever 'convention' we
- // had already derived since it occurs
- // in the prefix.
- C = NoConvention;
+ assert(C == NoConvention);
}
++s;
continue;
diff --git a/test/Analysis/refcnt_naming.m b/test/Analysis/refcnt_naming.m
index bea404799b..2ce00b2a8c 100644
--- a/test/Analysis/refcnt_naming.m
+++ b/test/Analysis/refcnt_naming.m
@@ -15,7 +15,7 @@ typedef signed char BOOL;
-(NSObject*)photoCopy; // read as "photo Copy"
-(NSObject*)__blebPRCopy; // read as "bleb PRCopy"
-(NSObject*)__blebPRcopy; // read as "bleb P Rcopy"
--(NSObject*)new_theprefixdoesnotcount; // read as "theprefixdoesnotcount"
+-(NSObject*)new_theprefixdoescount; // read as "new theprefixdoescount"
-(NSObject*)newestAwesomeStuff; // read as "newest awesome stuff"
@end
@@ -49,7 +49,7 @@ void testNames(NamingTest* x) {
[x photoCopy]; // expected-warning{{leak}}
[x __blebPRCopy]; // expected-warning{{leak}}
[x __blebPRcopy]; // no-warning
- [x new_theprefixdoesnotcount]; // no-warning
+ [x new_theprefixdoescount]; // expected-warning{{leak}}
[x newestAwesomeStuff]; // no-warning
}
diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m
index a14a50b0fb..e620037b2c 100644
--- a/test/Analysis/retain-release.m
+++ b/test/Analysis/retain-release.m
@@ -1098,6 +1098,28 @@ CVReturn rdar_7283567_2(CFAllocatorRef allocator, size_t width, size_t height,
}
//===----------------------------------------------------------------------===//
+// <rdar://problem/7265711> allow 'new', 'copy', 'alloc', 'init' prefix to
+// start before '_' when determining Cocoa fundamental rule
+//
+// Previously the retain/release checker just skipped prefixes before the
+// first '_' entirely. Now the checker honors the prefix if it results in a
+// recognizable naming convention (e.g., 'new', 'init').
+//===----------------------------------------------------------------------===//
+
+@interface RDar7265711 {}
+- (id) new_stuff;
+@end
+
+void rdar7265711_a(RDar7265711 *x) {
+ id y = [x new_stuff]; // expected-warning{{leak}}
+}
+
+void rdar7265711_b(RDar7265711 *x) {
+ id y = [x new_stuff]; // no-warning
+ [y release];
+}
+
+//===----------------------------------------------------------------------===//
// <rdar://problem/7306898> clang thinks [NSCursor dragCopyCursor] returns a
// retained reference
//===----------------------------------------------------------------------===//