]> granicus.if.org Git - clang/commitdiff
objective-c: Exclude -Wdirect-ivar-access for arc.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 7 Aug 2012 16:38:44 +0000 (16:38 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 7 Aug 2012 16:38:44 +0000 (16:38 +0000)
Allow direct ivar access in init and dealloc methods
in mrr. // rdar://650197

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161426 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
lib/Sema/SemaExprMember.cpp
test/SemaObjC/warn-direct-ivar-access.m

index e8ba54d24fb837c69c76aae86418d80483e603d4..c62df00a8750a53cd5f0f3928556a8a69ba892d7 100644 (file)
@@ -1962,8 +1962,12 @@ Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S,
 
       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));
index 5a116b4496479ad17b483d97285a7b99c83b1579..a23155d85e1d31212ac9bbd656378179d346a4a7 100644 (file)
@@ -1261,8 +1261,17 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr,
           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));
index 6850db64a3c410b91ffae1e1c1be00518af0b93a..dfddd823e38161a84406bf1923ad4b56f630a891 100644 (file)
@@ -20,6 +20,11 @@ __attribute__((objc_root_class)) @interface MyObject {
     // expected-warning {{instance variable '_isTickledPink' is being directly accessed}}
 }
 
+- (id) init {
+    _myMaster=0;
+    return _myMaster;
+}
+- (void) dealloc { _myMaster = 0; }
 @end
 
 MyObject * foo ()