diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-12-21 00:44:01 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-12-21 00:44:01 +0000 |
commit | 8e5fc9be37c6828ad008f22730e3baac1bef1686 (patch) | |
tree | ce5d1beabb36370e5dcbecc2cc6a345162aafd49 /lib/Sema | |
parent | a04426c5416f22df1078f6b31c1619de73c40b59 (diff) |
Warn when message is sent to receiver of
unknown type and there is a possibility that
at runtime method is resolved to a deprecated or
unavailable method. Addreses // rdar://8769853
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122294 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 11 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 16 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 18 | ||||
-rw-r--r-- | lib/Sema/SemaExprObjC.cpp | 8 |
4 files changed, 40 insertions, 13 deletions
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index e77a660ada..06cb42ec0e 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -2903,7 +2903,8 @@ void Sema::HandleDelayedDeprecationCheck(DelayedDiagnostic &DD, } void Sema::EmitDeprecationWarning(NamedDecl *D, llvm::StringRef Message, - SourceLocation Loc) { + SourceLocation Loc, + bool UnkownObjCClass) { // Delay if we're currently parsing a declaration. if (ParsingDeclDepth) { DelayedDiagnostics.push_back(DelayedDiagnostic::makeDeprecation(Loc, D, @@ -2917,6 +2918,10 @@ void Sema::EmitDeprecationWarning(NamedDecl *D, llvm::StringRef Message, if (!Message.empty()) Diag(Loc, diag::warn_deprecated_message) << D->getDeclName() << Message; - else - Diag(Loc, diag::warn_deprecated) << D->getDeclName(); + else { + if (!UnkownObjCClass) + Diag(Loc, diag::warn_deprecated) << D->getDeclName(); + else + Diag(Loc, diag::warn_deprecated_fwdclass_message) << D->getDeclName(); + } } diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 38e91465d2..5d9a924ed8 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1302,7 +1302,21 @@ void Sema::AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, // signature. for (ObjCMethodList *List = &Entry; List; List = List->Next) if (MatchTwoMethodDeclarations(Method, List->Method)) { - List->Method->setDefined(impl); + ObjCMethodDecl *PrevObjCMethod = List->Method; + PrevObjCMethod->setDefined(impl); + // If a method is deprecated, push it in the global pool. + // This is used for better diagnostics. + if (Method->getAttr<DeprecatedAttr>()) { + if (!PrevObjCMethod->getAttr<DeprecatedAttr>()) + List->Method = Method; + } + // If new method is unavailable, push it into global pool + // unless previous one is deprecated. + if (Method->getAttr<UnavailableAttr>()) { + if (!PrevObjCMethod->getAttr<UnavailableAttr>() && + !PrevObjCMethod->getAttr<DeprecatedAttr>()) + List->Method = Method; + } return; } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 01a505bb08..56ad9b4241 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -49,13 +49,14 @@ using namespace sema; /// used, or produce an error (and return true) if a C++0x deleted /// function is being used. /// -/// If IgnoreDeprecated is set to true, this should not want about deprecated +/// If IgnoreDeprecated is set to true, this should not warn about deprecated /// decls. /// /// \returns true if there was an error (this declaration cannot be /// referenced), false otherwise. /// -bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) { +bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, + bool UnkownObjCClass) { if (getLangOptions().CPlusPlus && isa<FunctionDecl>(D)) { // If there were any diagnostics suppressed by template argument deduction, // emit them now. @@ -76,13 +77,18 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) { // See if the decl is deprecated. if (const DeprecatedAttr *DA = D->getAttr<DeprecatedAttr>()) - EmitDeprecationWarning(D, DA->getMessage(), Loc); + EmitDeprecationWarning(D, DA->getMessage(), Loc, UnkownObjCClass); // See if the decl is unavailable if (const UnavailableAttr *UA = D->getAttr<UnavailableAttr>()) { - if (UA->getMessage().empty()) - Diag(Loc, diag::err_unavailable) << D->getDeclName(); - else + if (UA->getMessage().empty()) { + if (!UnkownObjCClass) + Diag(Loc, diag::err_unavailable) << D->getDeclName(); + else + Diag(Loc, diag::warn_unavailable_fwdclass_message) + << D->getDeclName(); + } + else Diag(Loc, diag::err_unavailable_message) << D->getDeclName() << UA->getMessage(); Diag(D->getLocation(), diag::note_unavailable_here) << 0; diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index baa34f9ce8..bbb047990b 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -1023,6 +1023,7 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver, break; } } + bool forwardClass = false; if (!Method) { // If we have implementations in scope, check "private" methods. Method = LookupPrivateInstanceMethod(Sel, ClassDecl); @@ -1033,14 +1034,15 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver, // compatibility. FIXME: should we deviate?? if (OCIType->qual_empty()) { Method = LookupInstanceMethodInGlobalPool(Sel, - SourceRange(LBracLoc, RBracLoc)); - if (Method && !OCIType->getInterfaceDecl()->isForwardDecl()) + SourceRange(LBracLoc, RBracLoc)); + forwardClass = OCIType->getInterfaceDecl()->isForwardDecl(); + if (Method && !forwardClass) Diag(Loc, diag::warn_maynot_respond) << OCIType->getInterfaceDecl()->getIdentifier() << Sel; } } } - if (Method && DiagnoseUseOfDecl(Method, Loc)) + if (Method && DiagnoseUseOfDecl(Method, Loc, forwardClass)) return ExprError(); } else if (!Context.getObjCIdType().isNull() && (ReceiverType->isPointerType() || |