[cfe-commits] r119543 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/SemaObjC/direct-synthesized-ivar-access.m
Fariborz Jahanian
fjahanian at apple.com
Wed Nov 17 11:41:23 PST 2010
Author: fjahanian
Date: Wed Nov 17 13:41:23 2010
New Revision: 119543
URL: http://llvm.org/viewvc/llvm-project?rev=119543&view=rev
Log:
Warn if direct accessing synthesized ivar backing the property in
nonofragile-abi2. Fixes //rdar://8673791
Added:
cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=119543&r1=119542&r2=119543&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Nov 17 13:41:23 2010
@@ -2698,6 +2698,9 @@
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">,
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=119543&r1=119542&r2=119543&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Nov 17 13:41:23 2010
@@ -1446,9 +1446,15 @@
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();
Added: cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m?rev=119543&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m (added)
+++ cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m Wed Nov 17 13:41:23 2010
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -Wnonfragile-abi2 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s
+// rdar://8673791
+
+ at interface I {
+}
+
+ at property int IVAR; // expected-note {{property declared here}}
+- (int) OK;
+ at end
+
+ at implementation I
+- (int) Meth { return IVAR; } // expected-warning {{direct access of synthesized ivar by using property access 'IVAR'}}
+- (int) OK { return self.IVAR; }
+ at end
More information about the cfe-commits
mailing list