summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaObjC/arc-repeated-weak.mm
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/SemaObjC/arc-repeated-weak.mm')
-rw-r--r--clang/test/SemaObjC/arc-repeated-weak.mm83
1 files changed, 64 insertions, 19 deletions
diff --git a/clang/test/SemaObjC/arc-repeated-weak.mm b/clang/test/SemaObjC/arc-repeated-weak.mm
index 728ffcb951d..90ba75f6efd 100644
--- a/clang/test/SemaObjC/arc-repeated-weak.mm
+++ b/clang/test/SemaObjC/arc-repeated-weak.mm
@@ -3,6 +3,7 @@
@interface Test {
@public
Test *ivar;
+ __weak id weakIvar;
}
@property(weak) Test *weakProp;
@property(strong) Test *strongProp;
@@ -18,7 +19,7 @@ extern bool condition();
#define nil ((id)0)
void sanity(Test *a) {
- use(a.weakProp); // expected-warning{{weak property is accessed multiple times in this function but may be unpredictably set to nil; assign to a strong variable to keep the object alive}}
+ use(a.weakProp); // expected-warning{{weak property 'weakProp' is accessed multiple times in this function but may be unpredictably set to nil; assign to a strong variable to keep the object alive}}
use(a.weakProp); // expected-note{{also accessed here}}
use(a.strongProp);
@@ -38,11 +39,22 @@ void assignsOnly(Test *a) {
id next = get();
if (next)
a.weakProp = next; // no-warning
+
+ a->weakIvar = get(); // no-warning
+ next = get();
+ if (next)
+ a->weakIvar = next; // no-warning
+
+ extern __weak id x;
+ x = get(); // no-warning
+ next = get();
+ if (next)
+ x = next; // no-warning
}
void assignThenRead(Test *a) {
a.weakProp = get(); // expected-note{{also accessed here}}
- use(a.weakProp); // expected-warning{{weak property is accessed multiple times}}
+ use(a.weakProp); // expected-warning{{weak property 'weakProp' is accessed multiple times}}
}
void twoVariables(Test *a, Test *b) {
@@ -51,22 +63,22 @@ void twoVariables(Test *a, Test *b) {
}
void doubleLevelAccess(Test *a) {
- use(a.strongProp.weakProp); // expected-warning{{weak property may be accessed multiple times in this function but may be unpredictably set to nil; assign to a strong variable to keep the object alive}}
+ use(a.strongProp.weakProp); // expected-warning{{weak property 'weakProp' may be accessed multiple times in this function and may be unpredictably set to nil; assign to a strong variable to keep the object alive}}
use(a.strongProp.weakProp); // expected-note{{also accessed here}}
}
void doubleLevelAccessIvar(Test *a) {
- use(a.strongProp.weakProp); // expected-warning{{weak property may be accessed multiple times}}
+ use(a.strongProp.weakProp); // expected-warning{{weak property 'weakProp' may be accessed multiple times}}
use(a.strongProp.weakProp); // expected-note{{also accessed here}}
}
void implicitProperties(Test *a) {
- use(a.implicitProp); // expected-warning{{weak property is accessed multiple times}}
+ use(a.implicitProp); // expected-warning{{weak implicit property 'implicitProp' is accessed multiple times}}
use(a.implicitProp); // expected-note{{also accessed here}}
}
void classProperties() {
- use(Test.weakProp); // expected-warning{{weak property is accessed multiple times}}
+ use(Test.weakProp); // expected-warning{{weak implicit property 'weakProp' is accessed multiple times}}
use(Test.weakProp); // expected-note{{also accessed here}}
}
@@ -76,16 +88,38 @@ void classPropertiesAreDifferent(Test *a) {
use(a.strongProp.weakProp); // no-warning
}
+void ivars(Test *a) {
+ use(a->weakIvar); // expected-warning{{weak instance variable 'weakIvar' is accessed multiple times}}
+ use(a->weakIvar); // expected-note{{also accessed here}}
+}
+
+void globals() {
+ extern __weak id a;
+ use(a); // expected-warning{{weak variable 'a' is accessed multiple times}}
+ use(a); // expected-note{{also accessed here}}
+}
+
void assignToStrongWrongInit(Test *a) {
id val = a.weakProp; // expected-note{{also accessed here}}
- use(a.weakProp); // expected-warning{{weak property is accessed multiple times}}
+ use(a.weakProp); // expected-warning{{weak property 'weakProp' is accessed multiple times}}
}
void assignToStrongWrong(Test *a) {
id val;
val = a.weakProp; // expected-note{{also accessed here}}
- use(a.weakProp); // expected-warning{{weak property is accessed multiple times}}
+ use(a.weakProp); // expected-warning{{weak property 'weakProp' is accessed multiple times}}
+}
+
+void assignToIvarWrong(Test *a) {
+ a->weakIvar = get(); // expected-note{{also accessed here}}
+ use(a->weakIvar); // expected-warning{{weak instance variable 'weakIvar' is accessed multiple times}}
+}
+
+void assignToGlobalWrong() {
+ extern __weak id a;
+ a = get(); // expected-note{{also accessed here}}
+ use(a); // expected-warning{{weak variable 'a' is accessed multiple times}}
}
void assignToStrongOK(Test *a) {
@@ -108,7 +142,7 @@ void testBlock(Test *a) {
use(a.weakProp); // no-warning
use(^{
- use(a.weakProp); // expected-warning{{weak property is accessed multiple times in this block}}
+ use(a.weakProp); // expected-warning{{weak property 'weakProp' is accessed multiple times in this block}}
use(a.weakProp); // expected-note{{also accessed here}}
});
}
@@ -119,16 +153,24 @@ void testBlock(Test *a) {
@implementation Test (Methods)
- (void)sanity {
- use(self.weakProp); // expected-warning{{weak property is accessed multiple times in this method but may be unpredictably set to nil; assign to a strong variable to keep the object alive}}
+ use(self.weakProp); // expected-warning{{weak property 'weakProp' is accessed multiple times in this method but may be unpredictably set to nil; assign to a strong variable to keep the object alive}}
use(self.weakProp); // expected-note{{also accessed here}}
}
+- (void)ivars {
+ use(weakIvar); // expected-warning{{weak instance variable 'weakIvar' is accessed multiple times in this method but may be unpredictably set to nil; assign to a strong variable to keep the object alive}}
+ use(weakIvar); // expected-note{{also accessed here}}
+}
+
- (void)doubleLevelAccessForSelf {
- use(self.strongProp.weakProp); // expected-warning{{weak property is accessed multiple times}}
+ use(self.strongProp.weakProp); // expected-warning{{weak property 'weakProp' is accessed multiple times}}
use(self.strongProp.weakProp); // expected-note{{also accessed here}}
- use(self->ivar.weakProp); // expected-warning{{weak property is accessed multiple times}}
+ use(self->ivar.weakProp); // expected-warning{{weak property 'weakProp' is accessed multiple times}}
use(self->ivar.weakProp); // expected-note{{also accessed here}}
+
+ use(self->ivar->weakIvar); // expected-warning{{weak instance variable 'weakIvar' is accessed multiple times}}
+ use(self->ivar->weakIvar); // expected-note{{also accessed here}}
}
- (void)distinctFromOther:(Test *)other {
@@ -137,6 +179,9 @@ void testBlock(Test *a) {
use(self->ivar.weakProp); // no-warning
use(other->ivar.weakProp); // no-warning
+
+ use(self.strongProp->weakIvar); // no-warning
+ use(other.strongProp->weakIvar); // no-warning
}
@end
@@ -146,7 +191,7 @@ class Wrapper {
public:
void fields() {
- use(a.weakProp); // expected-warning{{weak property is accessed multiple times in this function but may be unpredictably set to nil; assign to a strong variable to keep the object alive}}
+ use(a.weakProp); // expected-warning{{weak property 'weakProp' is accessed multiple times in this function but may be unpredictably set to nil; assign to a strong variable to keep the object alive}}
use(a.weakProp); // expected-note{{also accessed here}}
}
@@ -157,7 +202,7 @@ public:
}
static void doubleLevelAccessField(const Wrapper &x, const Wrapper &y) {
- use(x.a.weakProp); // expected-warning{{weak property may be accessed multiple times}}
+ use(x.a.weakProp); // expected-warning{{weak property 'weakProp' may be accessed multiple times}}
use(y.a.weakProp); // expected-note{{also accessed here}}
}
};
@@ -170,7 +215,7 @@ public:
// Most of these would require flow-sensitive analysis to silence correctly.
void assignAfterRead(Test *a) {
- if (!a.weakProp) // expected-warning{{weak property is accessed multiple times}}
+ if (!a.weakProp) // expected-warning{{weak property 'weakProp' is accessed multiple times}}
a.weakProp = get(); // expected-note{{also accessed here}}
}
@@ -178,25 +223,25 @@ void assignNil(Test *a) {
if (condition())
a.weakProp = nil; // expected-note{{also accessed here}}
- use(a.weakProp); // expected-warning{{weak property is accessed multiple times}}
+ use(a.weakProp); // expected-warning{{weak property 'weakProp' is accessed multiple times}}
}
void branch(Test *a) {
if (condition())
- use(a.weakProp); // expected-warning{{weak property is accessed multiple times}}
+ use(a.weakProp); // expected-warning{{weak property 'weakProp' is accessed multiple times}}
else
use(a.weakProp); // expected-note{{also accessed here}}
}
void doubleLevelAccess(Test *a, Test *b) {
- use(a.strongProp.weakProp); // expected-warning{{weak property may be accessed multiple times}}
+ use(a.strongProp.weakProp); // expected-warning{{weak property 'weakProp' may be accessed multiple times}}
use(b.strongProp.weakProp); // expected-note{{also accessed here}}
use(a.weakProp.weakProp); // no-warning
}
void doubleLevelAccessIvar(Test *a, Test *b) {
- use(a->ivar.weakProp); // expected-warning{{weak property may be accessed multiple times}}
+ use(a->ivar.weakProp); // expected-warning{{weak property 'weakProp' may be accessed multiple times}}
use(b->ivar.weakProp); // expected-note{{also accessed here}}
use(a.strongProp.weakProp); // no-warning
OpenPOWER on IntegriCloud