summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2010-11-17 19:41:23 +0000
committerFariborz Jahanian <fjahanian@apple.com>2010-11-17 19:41:23 +0000
commit8046af7d50856f287da370caa24f38cce241c376 (patch)
tree1c9235d6429afd9979dae34f00673533df345425
parentd82684c7fc226c14b87f72e934969c3b07fc2a3f (diff)
downloadbcm5719-llvm-8046af7d50856f287da370caa24f38cce241c376.tar.gz
bcm5719-llvm-8046af7d50856f287da370caa24f38cce241c376.zip
Warn if direct accessing synthesized ivar backing the property in
nonofragile-abi2. Fixes //rdar://8673791 llvm-svn: 119543
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--clang/lib/Sema/SemaExpr.cpp8
-rw-r--r--clang/test/SemaObjC/direct-synthesized-ivar-access.m14
3 files changed, 24 insertions, 1 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 277653e7ea1..4610a72d28c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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">,
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4728b0d1990..277da3b78c2 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -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/clang/test/SemaObjC/direct-synthesized-ivar-access.m b/clang/test/SemaObjC/direct-synthesized-ivar-access.m
new file mode 100644
index 00000000000..e59fa81662d
--- /dev/null
+++ b/clang/test/SemaObjC/direct-synthesized-ivar-access.m
@@ -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
OpenPOWER on IntegriCloud