diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index 548389db373b..8f4d67717966 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -239,8 +239,9 @@ Sema::ExprResult Sema::ActOnClassMessage( if (TypedefDecl *OCTD = dyn_cast_or_null(IDecl)) { const ObjCInterfaceType *OCIT; OCIT = OCTD->getUnderlyingType()->getAsObjCInterfaceType(); - if (OCIT) - ClassDecl = OCIT->getDecl(); + if (!OCIT) + return Diag(receiverLoc, diag::err_invalid_receiver_to_message); + ClassDecl = OCIT->getDecl(); } } assert(ClassDecl && "missing interface declaration"); diff --git a/clang/test/SemaObjC/invalid-receiver.m b/clang/test/SemaObjC/invalid-receiver.m new file mode 100644 index 000000000000..829ec5dc97e2 --- /dev/null +++ b/clang/test/SemaObjC/invalid-receiver.m @@ -0,0 +1,9 @@ +// RUN: clang -fsyntax-only -verify %s + +typedef struct NotAClass { + int a, b; +} NotAClass; + +void foo() { + [NotAClass nonexistent_method]; // expected-error {{invalid receiver to message expression}} +}