[cfe-commits] r161426 - in /cfe/trunk: lib/Sema/SemaExpr.cpp lib/Sema/SemaExprMember.cpp test/SemaObjC/warn-direct-ivar-access.m

Fariborz Jahanian fjahanian at apple.com
Tue Aug 7 09:38:44 PDT 2012


Author: fjahanian
Date: Tue Aug  7 11:38:44 2012
New Revision: 161426

URL: http://llvm.org/viewvc/llvm-project?rev=161426&view=rev
Log:
objective-c: Exclude -Wdirect-ivar-access for arc.
Allow direct ivar access in init and dealloc methods
in mrr. // rdar://650197

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaExprMember.cpp
    cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=161426&r1=161425&r2=161426&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Aug  7 11:38:44 2012
@@ -1962,8 +1962,12 @@
 
       MarkAnyDeclReferenced(Loc, IV);
       if (IV->getType()->isObjCObjectPointerType() &&
-          getLangOpts().getGC() == LangOptions::NonGC)
-        Diag(Loc, diag::warn_direct_ivar_access) << IV->getDeclName();
+          getLangOpts().getGC() == LangOptions::NonGC &&
+          !getLangOpts().ObjCAutoRefCount) {
+        ObjCMethodFamily MF = CurMethod->getMethodFamily();
+        if (MF != OMF_init && MF != OMF_dealloc && MF != OMF_finalize)
+          Diag(Loc, diag::warn_direct_ivar_access) << IV->getDeclName();
+      }
       return Owned(new (Context)
                    ObjCIvarRefExpr(IV, IV->getType(), Loc,
                                    SelfExpr.take(), true, true));

Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=161426&r1=161425&r2=161426&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Tue Aug  7 11:38:44 2012
@@ -1261,8 +1261,17 @@
           Diag(DE->getLocation(), diag::error_arc_weak_ivar_access);
     }
     if (IV->getType()->isObjCObjectPointerType() &&
-        getLangOpts().getGC() == LangOptions::NonGC)
-      Diag(MemberLoc, diag::warn_direct_ivar_access) << IV->getDeclName();
+        getLangOpts().getGC() == LangOptions::NonGC &&
+        !getLangOpts().ObjCAutoRefCount) {
+      bool warn = true;
+      if (ObjCMethodDecl *MD = getCurMethodDecl()) {
+        ObjCMethodFamily MF = MD->getMethodFamily();
+        warn = (MF != OMF_init && MF != OMF_dealloc && 
+                MF != OMF_finalize);
+      }
+      if (warn)
+        Diag(MemberLoc, diag::warn_direct_ivar_access) << IV->getDeclName();
+    }
     return Owned(new (Context) ObjCIvarRefExpr(IV, IV->getType(),
                                                MemberLoc, BaseExpr.take(),
                                                IsArrow));

Modified: cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m?rev=161426&r1=161425&r2=161426&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m (original)
+++ cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m Tue Aug  7 11:38:44 2012
@@ -20,6 +20,11 @@
     // expected-warning {{instance variable '_isTickledPink' is being directly accessed}}
 }
 
+- (id) init {
+    _myMaster=0;
+    return _myMaster;
+}
+- (void) dealloc { _myMaster = 0; }
 @end
 
 MyObject * foo ()





More information about the cfe-commits mailing list