summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-05-15 15:49:00 +0000
committerTed Kremenek <kremenek@apple.com>2009-05-15 15:49:00 +0000
commit3281977dbbc20c78f200e2810af75be2674132a0 (patch)
tree9eaca280947eb43255e38e34e51107adb7bd1462
parentdae2d9a852577b98f374742b14afeb8842066e25 (diff)
downloadbcm5719-llvm-3281977dbbc20c78f200e2810af75be2674132a0.tar.gz
bcm5719-llvm-3281977dbbc20c78f200e2810af75be2674132a0.zip
Fix crash when deriving the enclosing summary of a method whose first selector slot has a null IdentifierInfo*. This happens when analyzing Growl.
llvm-svn: 71857
-rw-r--r--clang/lib/Analysis/CFRefCount.cpp28
-rw-r--r--clang/test/Analysis/retain-release.m13
2 files changed, 29 insertions, 12 deletions
diff --git a/clang/lib/Analysis/CFRefCount.cpp b/clang/lib/Analysis/CFRefCount.cpp
index 67b364496ba..215be470867 100644
--- a/clang/lib/Analysis/CFRefCount.cpp
+++ b/clang/lib/Analysis/CFRefCount.cpp
@@ -76,7 +76,14 @@ static inline const char* parseWord(const char* s) {
return s;
}
-static NamingConvention deriveNamingConvention(const char* s) {
+static NamingConvention deriveNamingConvention(Selector S) {
+ IdentifierInfo *II = S.getIdentifierInfoForSlot(0);
+
+ if (!II)
+ return NoConvention;
+
+ const char *s = II->getName();
+
// A method/function name may contain a prefix. We don't know it is there,
// however, until we encounter the first '_'.
bool InPossiblePrefix = true;
@@ -145,8 +152,8 @@ static NamingConvention deriveNamingConvention(const char* s) {
return C;
}
-static bool followsFundamentalRule(const char* s) {
- return deriveNamingConvention(s) == CreateRule;
+static bool followsFundamentalRule(Selector S) {
+ return deriveNamingConvention(S) == CreateRule;
}
static const ObjCMethodDecl*
@@ -1218,19 +1225,17 @@ RetainSummaryManager::getCommonMethodSummary(const ObjCMethodDecl* MD,
if (isTrackedObjCObjectType(RetTy)) {
// EXPERIMENTAL: Assume the Cocoa conventions for all objects returned
// by instance methods.
- RetEffect E =
- followsFundamentalRule(S.getIdentifierInfoForSlot(0)->getName())
- ? ObjCAllocRetE : RetEffect::MakeNotOwned(RetEffect::ObjC);
+ RetEffect E = followsFundamentalRule(S)
+ ? ObjCAllocRetE : RetEffect::MakeNotOwned(RetEffect::ObjC);
return getPersistentSummary(E, ReceiverEff, MayEscape);
}
// Look for methods that return an owned core foundation object.
if (isTrackedCFObjectType(RetTy)) {
- RetEffect E =
- followsFundamentalRule(S.getIdentifierInfoForSlot(0)->getName())
- ? RetEffect::MakeOwned(RetEffect::CF, true)
- : RetEffect::MakeNotOwned(RetEffect::CF);
+ RetEffect E = followsFundamentalRule(S)
+ ? RetEffect::MakeOwned(RetEffect::CF, true)
+ : RetEffect::MakeNotOwned(RetEffect::CF);
return getPersistentSummary(E, ReceiverEff, MayEscape);
}
@@ -1258,8 +1263,7 @@ RetainSummaryManager::getInstanceMethodSummary(Selector S,
RetainSummary *Summ = 0;
// "initXXX": pass-through for receiver.
- if (deriveNamingConvention(S.getIdentifierInfoForSlot(0)->getName())
- == InitRule)
+ if (deriveNamingConvention(S) == InitRule)
Summ = getInitMethodSummary(RetTy);
else
Summ = getCommonMethodSummary(MD, S, RetTy);
diff --git a/clang/test/Analysis/retain-release.m b/clang/test/Analysis/retain-release.m
index 74f5b90b4b2..ed9f6617047 100644
--- a/clang/test/Analysis/retain-release.m
+++ b/clang/test/Analysis/retain-release.m
@@ -619,6 +619,19 @@ void test_RDar6859457(RDar6859457 *x, void *bytes, NSUInteger dataLength) {
}
//===----------------------------------------------------------------------===//
+// Method name that has a null IdentifierInfo* for its first selector slot.
+// This test just makes sure that we handle it.
+//===----------------------------------------------------------------------===//
+
+@interface TestNullIdentifier
+@end
+
+@implementation TestNullIdentifier
++ (id):(int)x, ... {
+ return [[NSString alloc] init]; // expected-warning{{leak}}
+}
+
+//===----------------------------------------------------------------------===//
// Tests of ownership attributes.
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud