]> granicus.if.org Git - clang/commitdiff
arc-repeated-use-of-weak should not warn about IBOutlet properties
authorBob Wilson <bob.wilson@apple.com>
Wed, 25 May 2016 05:41:57 +0000 (05:41 +0000)
committerBob Wilson <bob.wilson@apple.com>
Wed, 25 May 2016 05:41:57 +0000 (05:41 +0000)
Revision r211132 was supposed to disable -Warc-repeated-use-of-weak for
Objective-C properties marked with the IBOutlet attribute. Those properties
are supposed to be weak but they are only accessed from the main thread
so there is no risk of asynchronous updates setting them to nil. That
combination makes -Warc-repeated-use-of-weak very noisy. The previous
change only handled one kind of access to weak IBOutlet properties.
Instead of trying to add checks for all the different kinds of property
accesses, this patch removes the previous special case check and adds a
check at the point where the diagnostic is reported. rdar://21366461

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

lib/Sema/AnalysisBasedWarnings.cpp
lib/Sema/SemaPseudoObject.cpp
test/SemaObjC/iboutlet.m

index 3f2c41b67bcc0ce0d48519d3084137e6962b2a2e..eb45315a31a9d24c04a537665af8e07fc469e5f0 100644 (file)
@@ -1334,6 +1334,12 @@ static void diagnoseRepeatedUseOfWeak(Sema &S,
     else
       llvm_unreachable("Unexpected weak object kind!");
 
+    // Do not warn about IBOutlet weak property receivers being set to null
+    // since they are typically only used from the main thread.
+    if (const ObjCPropertyDecl *Prop = dyn_cast<ObjCPropertyDecl>(D))
+      if (Prop->hasAttr<IBOutletAttr>())
+        continue;
+
     // Show the first time the object was read.
     S.Diag(FirstRead->getLocStart(), DiagKind)
       << int(ObjectKind) << D << int(FunctionKind)
index 62c823b363d07ef8bc60614841aebf6b91508121..c93d800f96d1e16d9b86e6e534722b3b7e53fc4e 100644 (file)
@@ -578,7 +578,7 @@ bool ObjCPropertyOpBuilder::isWeakProperty() const {
   if (RefExpr->isExplicitProperty()) {
     const ObjCPropertyDecl *Prop = RefExpr->getExplicitProperty();
     if (Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak)
-      return !Prop->hasAttr<IBOutletAttr>();
+      return true;
 
     T = Prop->getType();
   } else if (Getter) {
index 2ce4ce1d87af2695a54573f0bd6d2c2722ce06b5..7bd86d4668b3aa2d4f5ab10de243c96918d82b2e 100644 (file)
@@ -41,6 +41,7 @@ IBInspectable @property (readonly) IBOutlet NSView *myView1; // expected-warning
 
 // rdar://15885642
 @interface WeakOutlet 
+@property int Number;
 @property IBOutlet __weak WeakOutlet* WeakProp;
 @end
 
@@ -50,3 +51,9 @@ WeakOutlet* func() {
   pwi.WeakProp = pwi.WeakProp;
   return pwi.WeakProp;
 }
+
+WeakOutlet* func2(WeakOutlet* pwi) {
+  [[pwi WeakProp] setNumber:0];
+  [[pwi WeakProp] setNumber:1];
+  return [pwi WeakProp];
+}