diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2014-06-16 17:25:41 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2014-06-16 17:25:41 +0000 |
commit | 89ea9610b3061c4a897fedbe3bec319723e43066 (patch) | |
tree | 67aa0fb4a5357f16efb9c1bbda4c4d503606f12e /clang/lib | |
parent | fff5663d4864a20633b3f86efb2b437de54a4dc7 (diff) | |
download | bcm5719-llvm-89ea9610b3061c4a897fedbe3bec319723e43066.tar.gz bcm5719-llvm-89ea9610b3061c4a897fedbe3bec319723e43066.zip |
Objective-C. Diagnose when property access is using declared
property accessor methods which have become deprecated
or available. // rdar://15951801
llvm-svn: 211039
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/DelayedDiagnostic.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 19 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 14 | ||||
-rw-r--r-- | clang/lib/Sema/SemaPseudoObject.cpp | 5 |
4 files changed, 28 insertions, 14 deletions
diff --git a/clang/lib/Sema/DelayedDiagnostic.cpp b/clang/lib/Sema/DelayedDiagnostic.cpp index 13a428ca8c2..664a6b1a899 100644 --- a/clang/lib/Sema/DelayedDiagnostic.cpp +++ b/clang/lib/Sema/DelayedDiagnostic.cpp @@ -25,7 +25,8 @@ DelayedDiagnostic::makeAvailability(Sema::AvailabilityDiagnostic AD, const NamedDecl *D, const ObjCInterfaceDecl *UnknownObjCClass, const ObjCPropertyDecl *ObjCProperty, - StringRef Msg) { + StringRef Msg, + bool ObjCPropertyAccess) { DelayedDiagnostic DD; switch (AD) { case Sema::AD_Deprecation: @@ -48,6 +49,7 @@ DelayedDiagnostic::makeAvailability(Sema::AvailabilityDiagnostic AD, DD.DeprecationData.Message = MessageData; DD.DeprecationData.MessageLen = Msg.size(); + DD.DeprecationData.ObjCPropertyAccess = ObjCPropertyAccess; return DD; } diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index bd9f6508518..5c868e94e35 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -4850,7 +4850,8 @@ DoEmitAvailabilityWarning(Sema &S, StringRef Message, SourceLocation Loc, const ObjCInterfaceDecl *UnknownObjCClass, - const ObjCPropertyDecl *ObjCProperty) { + const ObjCPropertyDecl *ObjCProperty, + bool ObjCPropertyAccess) { // Diagnostics for deprecated or unavailable. unsigned diag, diag_message, diag_fwdclass_message; @@ -4866,7 +4867,8 @@ DoEmitAvailabilityWarning(Sema &S, case DelayedDiagnostic::Deprecation: if (isDeclDeprecated(Ctx)) return; - diag = diag::warn_deprecated; + diag = !ObjCPropertyAccess ? diag::warn_deprecated + : diag::warn_property_method_deprecated; diag_message = diag::warn_deprecated_message; diag_fwdclass_message = diag::warn_deprecated_fwdclass_message; property_note_select = /* deprecated */ 0; @@ -4876,7 +4878,8 @@ DoEmitAvailabilityWarning(Sema &S, case DelayedDiagnostic::Unavailable: if (isDeclUnavailable(Ctx)) return; - diag = diag::err_unavailable; + diag = !ObjCPropertyAccess ? diag::err_unavailable + : diag::err_property_method_unavailable; diag_message = diag::err_unavailable_message; diag_fwdclass_message = diag::warn_unavailable_fwdclass_message; property_note_select = /* unavailable */ 1; @@ -4917,20 +4920,22 @@ void Sema::HandleDelayedAvailabilityCheck(DelayedDiagnostic &DD, DD.getDeprecationMessage(), DD.Loc, DD.getUnknownObjCClass(), - DD.getObjCProperty()); + DD.getObjCProperty(), false); } void Sema::EmitAvailabilityWarning(AvailabilityDiagnostic AD, NamedDecl *D, StringRef Message, SourceLocation Loc, const ObjCInterfaceDecl *UnknownObjCClass, - const ObjCPropertyDecl *ObjCProperty) { + const ObjCPropertyDecl *ObjCProperty, + bool ObjCPropertyAccess) { // Delay if we're currently parsing a declaration. if (DelayedDiagnostics.shouldDelayDiagnostics()) { DelayedDiagnostics.add(DelayedDiagnostic::makeAvailability(AD, Loc, D, UnknownObjCClass, ObjCProperty, - Message)); + Message, + ObjCPropertyAccess)); return; } @@ -4946,5 +4951,5 @@ void Sema::EmitAvailabilityWarning(AvailabilityDiagnostic AD, } DoEmitAvailabilityWarning(*this, K, Ctx, D, Message, Loc, - UnknownObjCClass, ObjCProperty); + UnknownObjCClass, ObjCProperty, ObjCPropertyAccess); } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 4c329d925f6..0e1aadefe73 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -83,7 +83,8 @@ static void DiagnoseUnusedOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc) { static AvailabilityResult DiagnoseAvailabilityOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc, - const ObjCInterfaceDecl *UnknownObjCClass) { + const ObjCInterfaceDecl *UnknownObjCClass, + bool ObjCPropertyAccess) { // See if this declaration is unavailable or deprecated. std::string Message; AvailabilityResult Result = D->getAvailability(&Message); @@ -113,13 +114,15 @@ static AvailabilityResult DiagnoseAvailabilityOfDecl(Sema &S, case AR_Deprecated: if (S.getCurContextAvailability() != AR_Deprecated) S.EmitAvailabilityWarning(Sema::AD_Deprecation, - D, Message, Loc, UnknownObjCClass, ObjCPDecl); + D, Message, Loc, UnknownObjCClass, ObjCPDecl, + ObjCPropertyAccess); break; case AR_Unavailable: if (S.getCurContextAvailability() != AR_Unavailable) S.EmitAvailabilityWarning(Sema::AD_Unavailable, - D, Message, Loc, UnknownObjCClass, ObjCPDecl); + D, Message, Loc, UnknownObjCClass, ObjCPDecl, + ObjCPropertyAccess); break; } @@ -251,7 +254,8 @@ void Sema::MaybeSuggestAddingStaticToDecl(const FunctionDecl *Cur) { /// referenced), false otherwise. /// bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, - const ObjCInterfaceDecl *UnknownObjCClass) { + const ObjCInterfaceDecl *UnknownObjCClass, + bool ObjCPropertyAccess) { if (getLangOpts().CPlusPlus && isa<FunctionDecl>(D)) { // If there were any diagnostics suppressed by template argument deduction, // emit them now. @@ -296,7 +300,7 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, DeduceReturnType(FD, Loc)) return true; } - DiagnoseAvailabilityOfDecl(*this, D, Loc, UnknownObjCClass); + DiagnoseAvailabilityOfDecl(*this, D, Loc, UnknownObjCClass, ObjCPropertyAccess); DiagnoseUnusedOfDecl(*this, D, Loc); diff --git a/clang/lib/Sema/SemaPseudoObject.cpp b/clang/lib/Sema/SemaPseudoObject.cpp index 3c9e83c4920..eaf170c176b 100644 --- a/clang/lib/Sema/SemaPseudoObject.cpp +++ b/clang/lib/Sema/SemaPseudoObject.cpp @@ -696,7 +696,8 @@ ExprResult ObjCPropertyOpBuilder::buildGet() { assert(InstanceReceiver); receiverType = InstanceReceiver->getType(); } - + if (!Getter->isImplicit()) + S.DiagnoseUseOfDecl(Getter, GenericLoc, nullptr, true); // Build a message-send. ExprResult msg; if ((Getter->isInstanceMethod() && !RefExpr->isClassReceiver()) || @@ -771,6 +772,8 @@ ExprResult ObjCPropertyOpBuilder::buildSet(Expr *op, SourceLocation opcLoc, // Build a message-send. ExprResult msg; + if (!Setter->isImplicit()) + S.DiagnoseUseOfDecl(Setter, GenericLoc, nullptr, true); if ((Setter->isInstanceMethod() && !RefExpr->isClassReceiver()) || RefExpr->isObjectReceiver()) { msg = S.BuildInstanceMessageImplicit(InstanceReceiver, receiverType, |