-Warc-repeated-use-of-weak: Check messages to property accessors as well.
Previously, [foo weakProp] was not being treated the same as foo.weakProp.
Now, for every explicit message send, we check if it's a property access,
and if so, if the property is weak. Then for every assignment of a
message, we have to do the same thing again.
This is a potentially expensive increase because determining whether a
method is a property accessor requires searching through the methods it
overrides. However, without it -Warc-repeated-use-of-weak will miss cases
from people who prefer not to use dot syntax. If this turns out to be
too expensive, we can try caching the result somewhere, or even lose
precision by not checking superclass methods. The warning is off-by-default,
though.
<rdar://problem/12407765>
llvm-svn: 165718
diff --git a/clang/test/SemaObjC/arc-repeated-weak.mm b/clang/test/SemaObjC/arc-repeated-weak.mm
index 1c6578e..ca13e20 100644
--- a/clang/test/SemaObjC/arc-repeated-weak.mm
+++ b/clang/test/SemaObjC/arc-repeated-weak.mm
@@ -99,6 +99,29 @@
use(a); // expected-note{{also accessed here}}
}
+void messageGetter(Test *a) {
+ use([a weakProp]); // expected-warning{{weak property 'weakProp' is accessed multiple times}}
+ use([a weakProp]); // expected-note{{also accessed here}}
+}
+
+void messageSetter(Test *a) {
+ [a setWeakProp:get()]; // no-warning
+ [a setWeakProp:get()]; // no-warning
+}
+
+void messageSetterAndGetter(Test *a) {
+ [a setWeakProp:get()]; // expected-note{{also accessed here}}
+ use([a weakProp]); // expected-warning{{weak property 'weakProp' is accessed multiple times}}
+}
+
+void mixDotAndMessageSend(Test *a, Test *b) {
+ use(a.weakProp); // expected-warning{{weak property 'weakProp' is accessed multiple times}}
+ use([a weakProp]); // expected-note{{also accessed here}}
+
+ use([b weakProp]); // expected-warning{{weak property 'weakProp' is accessed multiple times}}
+ use(b.weakProp); // expected-note{{also accessed here}}
+}
+
void assignToStrongWrongInit(Test *a) {
id val = a.weakProp; // expected-note{{also accessed here}}