From 1dad5b2f0e5737afe6847b97a18492bab93517d5 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 25 Jan 2008 17:43:39 +0000 Subject: [PATCH] Diagnose bad receiver type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46358 91177308-0d34-0410-b5e6-96231b3b80d8 --- Sema/SemaExprObjC.cpp | 6 ++++-- include/clang/Basic/DiagnosticKinds.def | 2 ++ test/Sema/objc-bad-receiver-1.m | 9 +++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/Sema/objc-bad-receiver-1.m diff --git a/Sema/SemaExprObjC.cpp b/Sema/SemaExprObjC.cpp index 125a4c4f9d..f4d16d9736 100644 --- a/Sema/SemaExprObjC.cpp +++ b/Sema/SemaExprObjC.cpp @@ -258,8 +258,10 @@ Sema::ExprResult Sema::ActOnInstanceMessage( SourceRange(lbrac, rbrac)); } else { - assert(ObjCInterfaceType::classof(receiverType.getTypePtr()) && - "bad receiver type"); + if (!isa(receiverType.getTypePtr())) { + Diag(lbrac, diag::error_bad_receiver_type, receiverType.getAsString()); + return true; + } ClassDecl = static_cast( receiverType.getTypePtr())->getDecl(); // FIXME: consider using InstanceMethodPool, since it will be faster diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 53d4946049..81f9b97544 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -482,6 +482,8 @@ DIAG(err_toomany_element_decls, ERROR, "Only one element declaration is allowed") DIAG(warn_expected_implementation, WARNING, "@end must appear in an @implementation context") +DIAG(error_bad_receiver_type, ERROR, + "bad receiver type (its type is '%0')") //===----------------------------------------------------------------------===// // Semantic Analysis diff --git a/test/Sema/objc-bad-receiver-1.m b/test/Sema/objc-bad-receiver-1.m new file mode 100644 index 0000000000..b18190894b --- /dev/null +++ b/test/Sema/objc-bad-receiver-1.m @@ -0,0 +1,9 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface I +- (id) retain; +@end + +void __raiseExc1() { + [objc_lookUpClass("NSString") retain]; // expected-error {{ "bad receiver type (its type is 'int')" }} +} -- 2.40.0