]> granicus.if.org Git - clang/commitdiff
Warn if direct accessing synthesized ivar backing the property in
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 17 Nov 2010 19:41:23 +0000 (19:41 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 17 Nov 2010 19:41:23 +0000 (19:41 +0000)
nonofragile-abi2. Fixes //rdar://8673791

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/SemaObjC/direct-synthesized-ivar-access.m [new file with mode: 0644]

index 277653e7ea17dd41b4b98f1ac5ec39f1cf7f77cb..4610a72d28c57e806c86c2207bb297114a4dc20d 100644 (file)
@@ -2698,6 +2698,9 @@ def note_condition_assign_to_comparison : Note<
 def note_condition_assign_silence : Note<
   "place parentheses around the assignment to silence this warning">;
 
+def warn_synthesized_ivar_access : Warning<
+  "direct access of synthesized ivar by using property access %0">,
+  InGroup<NonfragileAbi2>, DefaultIgnore;
 def warn_ivar_variable_conflict : Warning<
   "when default property synthesis is on, "
   "%0 lookup will access property ivar instead of global variable">, 
index 4728b0d1990da9109ae7d3958c79f43d17c5966a..277da3b78c2eebe3c38b1a4de43fbcfec62cad56 100644 (file)
@@ -1446,9 +1446,15 @@ ExprResult Sema::ActOnIdExpression(Scope *S,
       if (Ex) return Owned(Ex);
       // Synthesize ivars lazily
       if (getLangOptions().ObjCNonFragileABI2) {
-        if (SynthesizeProvisionalIvar(*this, R, II, NameLoc))
+        if (SynthesizeProvisionalIvar(*this, R, II, NameLoc)) {
+          if (const ObjCPropertyDecl *Property = 
+                canSynthesizeProvisionalIvar(II)) {
+            Diag(NameLoc, diag::warn_synthesized_ivar_access) << II;
+            Diag(Property->getLocation(), diag::note_property_declare);
+          }
           return ActOnIdExpression(S, SS, Id, HasTrailingLParen,
                                    isAddressOfOperand);
+        }
       }
       // for further use, this must be set to false if in class method.
       IvarLookupFollowUp = getCurMethodDecl()->isInstanceMethod();
diff --git a/test/SemaObjC/direct-synthesized-ivar-access.m b/test/SemaObjC/direct-synthesized-ivar-access.m
new file mode 100644 (file)
index 0000000..e59fa81
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -Wnonfragile-abi2 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s
+// rdar://8673791
+
+@interface I {
+}
+
+@property int IVAR; // expected-note {{property declared here}}
+- (int) OK;
+@end
+
+@implementation I
+- (int) Meth { return IVAR; } // expected-warning {{direct access of synthesized ivar by using property access 'IVAR'}}
+- (int) OK { return self.IVAR; }
+@end