// Utility functions.
//===----------------------------------------------------------------------===//
-static const ObjCInterfaceType* GetReceiverType(const ObjCMessage &msg) {
+static const char* GetReceiverNameType(const ObjCMessage &msg) {
if (const ObjCInterfaceDecl *ID = msg.getReceiverInterface())
- return ID->getTypeForDecl()->getAs<ObjCInterfaceType>();
- return NULL;
+ return ID->getIdentifier()->getNameStart();
+ return 0;
}
-static const char* GetReceiverNameType(const ObjCMessage &msg) {
- if (const ObjCInterfaceType *ReceiverType = GetReceiverType(msg))
- return ReceiverType->getDecl()->getIdentifier()->getNameStart();
- return NULL;
-}
+static bool isReceiverClassOrSuperclass(const ObjCInterfaceDecl *ID,
+ llvm::StringRef ClassName) {
+ if (ID->getIdentifier()->getName() == ClassName)
+ return true;
+
+ if (const ObjCInterfaceDecl *Super = ID->getSuperClass())
+ return isReceiverClassOrSuperclass(Super, ClassName);
-static bool isNSString(llvm::StringRef ClassName) {
- return ClassName == "NSString" || ClassName == "NSMutableString";
+ return false;
}
static inline bool isNil(SVal X) {
void NilArgChecker::checkPreObjCMessage(ObjCMessage msg,
CheckerContext &C) const {
- const ObjCInterfaceType *ReceiverType = GetReceiverType(msg);
- if (!ReceiverType)
+ const ObjCInterfaceDecl *ID = msg.getReceiverInterface();
+ if (!ID)
return;
- if (isNSString(ReceiverType->getDecl()->getIdentifier()->getName())) {
+ if (isReceiverClassOrSuperclass(ID, "NSString")) {
Selector S = msg.getSelector();
if (S.isUnarySelector())
CFRelease(ref); // expected-warning{{Reference-counted object is used after it is released}}
}
+@interface MyString : NSString
+@end
+
+void f14(MyString *s) {
+ [s compare:0]; // expected-warning {{Argument to 'MyString' method 'compare:' cannot be nil.}}
+}
+
// Test regular use of -autorelease
@interface TestAutorelease
-(NSString*) getString;