[llvm-branch-commits] [cfe-branch] r122482 - in /cfe/branches/Apple/whitney: lib/Checker/CocoaConventions.cpp test/Analysis/refcnt_naming.m test/Analysis/retain-release.m
Daniel Dunbar
daniel at zuster.org
Wed Dec 22 21:40:30 PST 2010
Author: ddunbar
Date: Wed Dec 22 23:40:30 2010
New Revision: 122482
URL: http://llvm.org/viewvc/llvm-project?rev=122482&view=rev
Log:
Merge r122036:
--
Author: Ted Kremenek <kremenek at apple.com>
Date: Fri Dec 17 04:44:43 2010 +0000
Revise Cocoa conventions detection: 'copy' and 'mutableCopy'
only indicates the create rule if it starts
at the beginning of the method name, not
within the method name.
Modified:
cfe/branches/Apple/whitney/lib/Checker/CocoaConventions.cpp
cfe/branches/Apple/whitney/test/Analysis/refcnt_naming.m
cfe/branches/Apple/whitney/test/Analysis/retain-release.m
Modified: cfe/branches/Apple/whitney/lib/Checker/CocoaConventions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Checker/CocoaConventions.cpp?rev=122482&r1=122481&r2=122482&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Checker/CocoaConventions.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Checker/CocoaConventions.cpp Wed Dec 22 23:40:30 2010
@@ -63,72 +63,48 @@
// A method/function name may contain a prefix. We don't know it is there,
// however, until we encounter the first '_'.
- bool InPossiblePrefix = true;
- bool AtBeginning = true;
- NamingConvention C = NoConvention;
-
while (*s != '\0') {
- // 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;
- assert(C == NoConvention);
- }
- ++s;
- continue;
- }
-
- // Skip numbers, ':', etc.
- if (!isalpha(*s)) {
+ // Skip '_', numbers, ':', etc.
+ if (*s == '_' || !isalpha(*s)) {
++s;
continue;
}
+ break;
+ }
- const char *wordEnd = parseWord(s);
- assert(wordEnd > s);
- unsigned len = wordEnd - s;
+ // Parse the first word, and look for specific keywords.
+ const char *wordEnd = parseWord(s);
+ assert(wordEnd > s);
+ unsigned len = wordEnd - s;
- switch (len) {
+ switch (len) {
default:
- break;
+ return NoConvention;
case 3:
// Methods starting with 'new' follow the create rule.
- if (AtBeginning && StringRef(s, len).equals_lower("new"))
- C = CreateRule;
- break;
+ return (memcmp(s, "new", 3) == 0) ? CreateRule : NoConvention;
case 4:
- // Methods starting with 'alloc' or contain 'copy' follow the
- // create rule
- if (C == NoConvention && StringRef(s, len).equals_lower("copy"))
- C = CreateRule;
- else // Methods starting with 'init' follow the init rule.
- if (AtBeginning && StringRef(s, len).equals_lower("init"))
- C = InitRule;
- break;
+ // Methods starting with 'copy' follow the create rule.
+ if (memcmp(s, "copy", 4) == 0)
+ return CreateRule;
+ // Methods starting with 'init' follow the init rule.
+ if (memcmp(s, "init", 4) == 0)
+ return InitRule;
+ return NoConvention;
case 5:
- if (AtBeginning && StringRef(s, len).equals_lower("alloc"))
- C = CreateRule;
- break;
- }
-
- // If we aren't in the prefix and have a derived convention then just
- // return it now.
- if (!InPossiblePrefix && C != NoConvention)
- return C;
-
- AtBeginning = false;
- s = wordEnd;
+ return (memcmp(s, "alloc", 5) == 0) ? CreateRule : NoConvention;
+ case 7:
+ // Methods starting with 'mutableCopy' follow the create rule.
+ if (memcmp(s, "mutable", 7) == 0) {
+ // Look at the next word to see if it is "Copy".
+ s = wordEnd;
+ wordEnd = parseWord(s);
+ len = wordEnd - s;
+ if (len == 4 && memcmp(s, "Copy", 4) == 0)
+ return CreateRule;
+ }
+ return NoConvention;
}
-
- // We will get here if there wasn't more than one word
- // after the prefix.
- return C;
}
bool cocoa::isRefType(QualType RetTy, llvm::StringRef Prefix,
Modified: cfe/branches/Apple/whitney/test/Analysis/refcnt_naming.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Analysis/refcnt_naming.m?rev=122482&r1=122481&r2=122482&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Analysis/refcnt_naming.m (original)
+++ cfe/branches/Apple/whitney/test/Analysis/refcnt_naming.m Wed Dec 22 23:40:30 2010
@@ -11,6 +11,8 @@
@class NSArray, NSString, NSURL;
@interface NamingTest : NSObject {}
+-(NSObject*)copyPhoto;
+-(NSObject*)mutableCopyPhoto;
-(NSObject*)photocopy; // read as "photocopy"
-(NSObject*)photoCopy; // read as "photo Copy"
-(NSObject*)__blebPRCopy; // read as "bleb PRCopy"
@@ -45,9 +47,11 @@
}
void testNames(NamingTest* x) {
+ [x copyPhoto]; // expected-warning{{leak}}
+ [x mutableCopyPhoto]; // expected-warning{{leak}}
[x photocopy]; // no-warning
- [x photoCopy]; // expected-warning{{leak}}
- [x __blebPRCopy]; // expected-warning{{leak}}
+ [x photoCopy]; // no-warning
+ [x __blebPRCopy]; // no-warning
[x __blebPRcopy]; // no-warning
[x new_theprefixdoescount]; // expected-warning{{leak}}
[x newestAwesomeStuff]; // no-warning
Modified: cfe/branches/Apple/whitney/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Analysis/retain-release.m?rev=122482&r1=122481&r2=122482&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Analysis/retain-release.m (original)
+++ cfe/branches/Apple/whitney/test/Analysis/retain-release.m Wed Dec 22 23:40:30 2010
@@ -762,13 +762,13 @@
@end
@implementation RDar6859457
-- (NSString*) NoCopyString { return [[NSString alloc] init]; } // no-warning
-- (NSString*) noCopyString { return [[NSString alloc] init]; } // no-warning
+- (NSString*) NoCopyString { return [[NSString alloc] init]; } // expected-warning{{leak}}
+- (NSString*) noCopyString { return [[NSString alloc] init]; } // expected-warning{{leak}}
@end
void test_RDar6859457(RDar6859457 *x, void *bytes, NSUInteger dataLength) {
- [x NoCopyString]; // expected-warning{{leak}}
- [x noCopyString]; // expected-warning{{leak}}
+ [x NoCopyString]; // no-warning
+ [x noCopyString]; // no-warning
[NSData dataWithBytesNoCopy:bytes length:dataLength]; // no-warning
[NSData dataWithBytesNoCopy:bytes length:dataLength freeWhenDone:1]; // no-warning
}
More information about the llvm-branch-commits
mailing list