Fix crash identified by <rdar://problem/5986085>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51969 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index d833efe..e2e23ce 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -166,19 +166,31 @@
} else
ClassDecl = getObjCInterfaceDecl(receiverName);
- // FIXME: can ClassDecl ever be null?
- ObjCMethodDecl *Method = ClassDecl->lookupClassMethod(Sel);
+ // ClassDecl is null in the following case.
+ //
+ // typedef XCElementDisplayRect XCElementGraphicsRect;
+ //
+ // @implementation XCRASlice
+ // - whatever { // Note that XCElementGraphicsRect is a typedef name.
+ // _sGraphicsDelegate =[[XCElementGraphicsRect alloc] init];
+ // }
+ //
+ // FIXME: Investigate why GCC allows the above.
+ ObjCMethodDecl *Method = 0;
QualType returnType;
-
- // If we have an implementation in scope, check "private" methods.
- if (!Method) {
- if (ObjCImplementationDecl *ImpDecl =
- ObjCImplementations[ClassDecl->getIdentifier()])
- Method = ImpDecl->getClassMethod(Sel);
+ if (ClassDecl) {
+ Method = ClassDecl->lookupClassMethod(Sel);
+
+ // If we have an implementation in scope, check "private" methods.
+ if (!Method) {
+ if (ObjCImplementationDecl *ImpDecl =
+ ObjCImplementations[ClassDecl->getIdentifier()])
+ Method = ImpDecl->getClassMethod(Sel);
+ }
+ // Before we give up, check if the selector is an instance method.
+ if (!Method)
+ Method = ClassDecl->lookupInstanceMethod(Sel);
}
- // Before we give up, check if the selector is an instance method.
- if (!Method)
- Method = ClassDecl->lookupInstanceMethod(Sel);
if (!Method) {
Diag(lbrac, diag::warn_method_not_found, std::string("+"), Sel.getName(),
SourceRange(lbrac, rbrac));