Warn if direct accessing synthesized ivar backing the property in

nonofragile-abi2. Fixes //rdar://8673791

llvm-svn: 119543
This commit is contained in:
Fariborz Jahanian 2010-11-17 19:41:23 +00:00
parent d82684c7fc
commit 8046af7d50
3 changed files with 24 additions and 1 deletions

View File

@ -2698,6 +2698,9 @@ def note_condition_assign_to_comparison : Note<
def note_condition_assign_silence : Note< def note_condition_assign_silence : Note<
"place parentheses around the assignment to silence this warning">; "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< def warn_ivar_variable_conflict : Warning<
"when default property synthesis is on, " "when default property synthesis is on, "
"%0 lookup will access property ivar instead of global variable">, "%0 lookup will access property ivar instead of global variable">,

View File

@ -1446,9 +1446,15 @@ ExprResult Sema::ActOnIdExpression(Scope *S,
if (Ex) return Owned(Ex); if (Ex) return Owned(Ex);
// Synthesize ivars lazily // Synthesize ivars lazily
if (getLangOptions().ObjCNonFragileABI2) { 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, return ActOnIdExpression(S, SS, Id, HasTrailingLParen,
isAddressOfOperand); isAddressOfOperand);
}
} }
// for further use, this must be set to false if in class method. // for further use, this must be set to false if in class method.
IvarLookupFollowUp = getCurMethodDecl()->isInstanceMethod(); IvarLookupFollowUp = getCurMethodDecl()->isInstanceMethod();

View File

@ -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