From 6e10a08fe0427ab34c463dd59d9c0997d4f72170 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 1 Feb 2008 06:57:39 +0000 Subject: [PATCH] make some diagnostics more terse, update testcases. Fix Sema::ActOnInstanceMessage to correctly do things in terms of canonical types, fixing bogus errors like: NSDistantObject.m:10383:120: error: bad receiver type 'typeof((id)self)' id mess = ({ id __inv__ = ((void *)0); id __mb__ = _NSMessageBuilder((id )self, &__inv__); (void)[(__typeof__((id )self))__mb__ mutableCopyWithZone:((void *)0)]; if (!objc_collecting_enabled()) object_dispose(__mb__); __inv__; }); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46633 91177308-0d34-0410-b5e6-96231b3b80d8 --- Sema/SemaExprObjC.cpp | 17 ++++++++--------- include/clang/Basic/DiagnosticKinds.def | 6 +++--- test/Parser/objc-forcollection-neg-2.m | 2 +- test/Parser/objc-forcollection-neg.m | 8 ++++---- test/Sema/objc-bad-receiver-1.m | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Sema/SemaExprObjC.cpp b/Sema/SemaExprObjC.cpp index 0f53bbd804..3e73930e9b 100644 --- a/Sema/SemaExprObjC.cpp +++ b/Sema/SemaExprObjC.cpp @@ -197,18 +197,16 @@ Sema::ExprResult Sema::ActOnInstanceMessage( Expr **ArgExprs = reinterpret_cast(Args); Expr *RExpr = static_cast(receiver); - QualType receiverType = RExpr->getType(); + QualType receiverType = RExpr->getType().getCanonicalType(); QualType returnType; ObjCMethodDecl *Method = 0; - // FIXME: - // FIXME: This code is not stripping off type qualifiers or typedefs! - // FIXME: - if (receiverType == Context.getObjCIdType() || - receiverType == Context.getObjCClassType()) { + // FIXME: This code is not stripping off type qualifiers! Should it? + if (receiverType == Context.getObjCIdType().getCanonicalType() || + receiverType == Context.getObjCClassType().getCanonicalType()) { Method = InstanceMethodPool[Sel].Method; - if (!Method) - Method = FactoryMethodPool[Sel].Method; + if (!Method) + Method = FactoryMethodPool[Sel].Method; if (!Method) { Diag(lbrac, diag::warn_method_not_found, std::string("-"), Sel.getName(), SourceRange(lbrac, rbrac)); @@ -261,7 +259,8 @@ Sema::ExprResult Sema::ActOnInstanceMessage( else { ObjCInterfaceType *OCIReceiver =dyn_cast(receiverType); if (OCIReceiver == 0) { - Diag(lbrac, diag::error_bad_receiver_type, receiverType.getAsString()); + Diag(lbrac, diag::error_bad_receiver_type, + RExpr->getType().getAsString()); return true; } ClassDecl = OCIReceiver->getDecl(); diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 02d3159c6a..489575c989 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -477,15 +477,15 @@ DIAG(warn_method_not_found, WARNING, DIAG(warn_method_not_found_in_protocol, WARNING, "method '%0%1' not found in protocol (return type defaults to 'id')") DIAG(err_collection_expr_type, ERROR, - "collection expression is not of valid object type (its type is '%0')") + "collection expression type ('%0') is not a valid object") DIAG(err_selector_element_type, ERROR, - "selector element is not of valid object type (its type is '%0')") + "selector element type ('%0') is not a valid object") 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')") + "bad receiver type '%0'") //===----------------------------------------------------------------------===// // Semantic Analysis diff --git a/test/Parser/objc-forcollection-neg-2.m b/test/Parser/objc-forcollection-neg-2.m index ba870aac20..bde7d22359 100644 --- a/test/Parser/objc-forcollection-neg-2.m +++ b/test/Parser/objc-forcollection-neg-2.m @@ -30,7 +30,7 @@ typedef struct objc_object { for (id el in self) ++i; MyList

***p; - for (p in self) // expected-error {{selector element is not of valid object type (its type is 'MyList

***')}} + for (p in self) // expected-error {{selector element type ('MyList

***') is not a valid object type}} ++i; } diff --git a/test/Parser/objc-forcollection-neg.m b/test/Parser/objc-forcollection-neg.m index 4137e6304b..8e1c05a059 100644 --- a/test/Parser/objc-forcollection-neg.m +++ b/test/Parser/objc-forcollection-neg.m @@ -24,13 +24,13 @@ typedef struct objc_object { - (void)compilerTestAgainst { int i=0; - for (int * elem in elem) // expected-error {{selector element is not of valid object type (its type is 'int *')}} \ - expected-error {{collection expression is not of valid object type (its type is 'int *')}} + for (int * elem in elem) // expected-error {{selector element type ('int *') is not a valid object}} \ + expected-error {{collection expression type ('int *') is not a valid object}} ++i; for (i in elem) // expected-error {{use of undeclared identifier 'elem'}} \ - expected-error {{selector element is not of valid object type (its type is 'int')}} + expected-error {{selector element type ('int') is not a valid object}} ++i; - for (id se in i) // expected-error {{collection expression is not of valid object type (its type is 'int')}} + for (id se in i) // expected-error {{collection expression type ('int') is not a valid object}} ++i; } @end diff --git a/test/Sema/objc-bad-receiver-1.m b/test/Sema/objc-bad-receiver-1.m index b18190894b..8376a5ced7 100644 --- a/test/Sema/objc-bad-receiver-1.m +++ b/test/Sema/objc-bad-receiver-1.m @@ -5,5 +5,5 @@ @end void __raiseExc1() { - [objc_lookUpClass("NSString") retain]; // expected-error {{ "bad receiver type (its type is 'int')" }} + [objc_lookUpClass("NSString") retain]; // expected-error {{ "bad receiver type 'int'" }} } -- 2.40.0