[cfe-commits] r141335 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExpr.cpp test/SemaObjC/attr-deprecated.m test/SemaObjC/class-unavail-warning.m test/SemaObjC/warn-deprecated-implementations.m

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Oct 6 16:23:27 PDT 2011


Author: akirtzidis
Date: Thu Oct  6 18:23:27 2011
New Revision: 141335

URL: http://llvm.org/viewvc/llvm-project?rev=141335&view=rev
Log:
Implicitly assume that a ObjC category to an unavailable interface is also unavailable;
only give an 'unavailable' error on the @implementation of the category. rdar://10234078

Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaObjC/attr-deprecated.m
    cfe/trunk/test/SemaObjC/class-unavail-warning.m
    cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=141335&r1=141334&r2=141335&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Oct  6 18:23:27 2011
@@ -6165,6 +6165,8 @@
   DeclContext *getCurLexicalContext() const {
     return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
   }
+
+  AvailabilityResult getCurContextAvailability() const;
 };
 
 /// \brief RAII object that enters a new expression evaluation context.

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=141335&r1=141334&r2=141335&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Oct  6 18:23:27 2011
@@ -9663,3 +9663,12 @@
 Decl *Sema::getObjCDeclContext() const {
   return (dyn_cast_or_null<ObjCContainerDecl>(CurContext));
 }
+
+AvailabilityResult Sema::getCurContextAvailability() const {
+  const Decl *D = cast<Decl>(getCurLexicalContext());
+  // A category implicitly has the availability of the interface.
+  if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(D))
+    D = CatD->getClassInterface();
+  
+  return D->getAvailability();
+}

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=141335&r1=141334&r2=141335&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Oct  6 18:23:27 2011
@@ -4002,6 +4002,9 @@
   do {
     if (D->isDeprecated())
       return true;
+    // A category implicitly has the availability of the interface.
+    if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(D))
+      return CatD->getClassInterface()->isDeprecated();
   } while ((D = cast_or_null<Decl>(D->getDeclContext())));
   return false;
 }

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=141335&r1=141334&r2=141335&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Oct  6 18:23:27 2011
@@ -770,9 +770,6 @@
   // FIXME: PushOnScopeChains?
   CurContext->addDecl(CDecl);
 
-  // If the interface is deprecated, warn about it.
-  (void)DiagnoseUseOfDecl(IDecl, ClassLoc);
-
   if (NumProtoRefs) {
     CDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs, 
                            ProtoLocs, Context);
@@ -818,6 +815,10 @@
   // FIXME: PushOnScopeChains?
   CurContext->addDecl(CDecl);
 
+  // If the interface is deprecated/unavailable, warn/error about it.
+  if (IDecl)
+    DiagnoseUseOfDecl(IDecl, ClassLoc);
+
   /// Check that CatName, category name, is not used in another implementation.
   if (CatIDecl) {
     if (CatIDecl->getImplementation()) {

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=141335&r1=141334&r2=141335&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Oct  6 18:23:27 2011
@@ -72,8 +72,7 @@
       break;
             
     case AR_Unavailable:
-      if (cast<Decl>(S.getCurLexicalContext())->getAvailability() !=
-            AR_Unavailable) {
+      if (S.getCurContextAvailability() != AR_Unavailable) {
         if (Message.empty()) {
           if (!UnknownObjCClass)
             S.Diag(Loc, diag::err_unavailable) << D->getDeclName();

Modified: cfe/trunk/test/SemaObjC/attr-deprecated.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/attr-deprecated.m?rev=141335&r1=141334&r2=141335&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/attr-deprecated.m (original)
+++ cfe/trunk/test/SemaObjC/attr-deprecated.m Thu Oct  6 18:23:27 2011
@@ -92,7 +92,14 @@
 @property  int prop; 
 @end
 
- at interface DEPRECATED (Category) // expected-warning {{warning: 'DEPRECATED' is deprecated}}
+ at interface DEPRECATED (Category) // no warning.
+- (DEPRECATED *) meth2; // no warning.
+ at end
+
+ at interface DEPRECATED (Category2) // no warning.
+ at end
+
+ at implementation DEPRECATED (Category2) // expected-warning {{warning: 'DEPRECATED' is deprecated}}
 @end
 
 @interface NS : DEPRECATED  // expected-warning {{warning: 'DEPRECATED' is deprecated}}

Modified: cfe/trunk/test/SemaObjC/class-unavail-warning.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/class-unavail-warning.m?rev=141335&r1=141334&r2=141335&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/class-unavail-warning.m (original)
+++ cfe/trunk/test/SemaObjC/class-unavail-warning.m Thu Oct  6 18:23:27 2011
@@ -2,7 +2,7 @@
 // rdar://9092208
 
 __attribute__((unavailable("not available")))
- at interface MyClass { // expected-note 7 {{declaration has been explicitly marked unavailable here}}
+ at interface MyClass { // expected-note 8 {{declaration has been explicitly marked unavailable here}}
 @public
     void *_test;
     MyClass *ivar; // no error.
@@ -21,6 +21,16 @@
 - (MyClass *)meth; // expected-error {{unavailable}}
 @end
 
+ at interface MyClass (Cat1)
+- (MyClass *)meth; // no error.
+ at end
+
+ at interface MyClass (Cat2) // no error.
+ at end
+
+ at implementation MyClass (Cat2) // expected-error {{unavailable}}
+ at end
+
 int main() {
  [MyClass new]; // expected-error {{'MyClass' is unavailable: not available}}
  [MyClass self]; // expected-error {{'MyClass' is unavailable: not available}}

Modified: cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m?rev=141335&r1=141334&r2=141335&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m (original)
+++ cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m Thu Oct  6 18:23:27 2011
@@ -26,7 +26,8 @@
 @implementation CL // expected-warning {{Implementing deprecated class}}
 @end
 
- at implementation CL ( SomeCategory ) // expected-warning {{Implementing deprecated category}}
+ at implementation CL ( SomeCategory ) // expected-warning {{'CL' is deprecated}} \
+                                    // expected-warning {{Implementing deprecated category}}
 @end
 
 @interface CL_SUB : CL // expected-warning {{'CL' is deprecated}}





More information about the cfe-commits mailing list