Redeclaration of 'self' should be flagged in

objective-c instead of crashing in IRgen.
// rdar://9154582.

llvm-svn: 129412
This commit is contained in:
Fariborz Jahanian 2011-04-12 23:39:33 +00:00
parent 3c2f74c9f3
commit 82bc436c28
3 changed files with 31 additions and 0 deletions

View File

@ -3797,6 +3797,8 @@ def warn_ivar_use_hidden : Warning<
"local declaration of %0 hides instance variable">;
def error_ivar_use_in_class_method : Error<
"instance variable %0 accessed in class method">;
def error_implicit_ivar_access : Error<
"instance variable %0 cannot be accessed because 'self' has been redeclared">;
def error_private_ivar_access : Error<"instance variable %0 is private">,
AccessControl;
def error_protected_ivar_access : Error<"instance variable %0 is protected">,

View File

@ -1915,6 +1915,17 @@ Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S,
return ExprError();
MarkDeclarationReferenced(Loc, IV);
Expr *base = SelfExpr.take();
base = base->IgnoreParenImpCasts();
if (const DeclRefExpr *DE = dyn_cast<DeclRefExpr>(base)) {
const NamedDecl *ND = DE->getDecl();
if (!isa<ImplicitParamDecl>(ND)) {
Diag(Loc, diag::error_implicit_ivar_access)
<< IV->getDeclName();
Diag(ND->getLocation(), diag::note_declared_at);
return ExprError();
}
}
return Owned(new (Context)
ObjCIvarRefExpr(IV, IV->getType(), Loc,
SelfExpr.take(), true, true));

View File

@ -0,0 +1,18 @@
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10 -fblocks -fobjc-nonfragile-abi -verify %s
// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -triple x86_64-apple-darwin10 -fblocks -fobjc-nonfragile-abi -verify %s
// rdar://9154582
@interface Blocky @end
@implementation Blocky {
int _a;
}
- (void)doAThing {
^{
char self; // expected-note {{declared here}}
_a; // expected-error {{instance variable '_a' cannot be accessed because 'self' has been redeclared}}
}();
}
@end