Make Sema::ActOnClassMessage robust when name lookup for the receiver
name finds something other than a TypedefDecl or an
ObjCInterfaceDecl. This is a small part of <rdar://problem/7660386>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96676 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 0c5d8ef..3a05241 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -426,14 +426,14 @@
if (!ClassDecl) {
NamedDecl *IDecl
= LookupSingleName(TUScope, receiverName, LookupOrdinaryName);
- if (TypedefDecl *OCTD = dyn_cast_or_null<TypedefDecl>(IDecl)) {
- const ObjCInterfaceType *OCIT;
- OCIT = OCTD->getUnderlyingType()->getAs<ObjCInterfaceType>();
- if (!OCIT) {
- Diag(receiverLoc, diag::err_invalid_receiver_to_message);
- return true;
- }
- ClassDecl = OCIT->getDecl();
+ if (TypedefDecl *OCTD = dyn_cast_or_null<TypedefDecl>(IDecl))
+ if (const ObjCInterfaceType *OCIT
+ = OCTD->getUnderlyingType()->getAs<ObjCInterfaceType>())
+ ClassDecl = OCIT->getDecl();
+
+ if (!ClassDecl) {
+ Diag(receiverLoc, diag::err_invalid_receiver_to_message);
+ return true;
}
}
assert(ClassDecl && "missing interface declaration");
diff --git a/test/SemaObjCXX/message.mm b/test/SemaObjCXX/message.mm
new file mode 100644
index 0000000..6aa62c8
--- /dev/null
+++ b/test/SemaObjCXX/message.mm
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@interface I1
+- (void)method;
+@end
+
+@implementation I1
+- (void)method {
+ struct x { };
+ [x method]; // expected-error{{invalid receiver to message expression}}
+}
+@end