mirror of
https://github.com/intel/llvm.git
synced 2026-01-26 21:53:12 +08:00
Redeclaration of 'self' should be flagged in
objective-c instead of crashing in IRgen. // rdar://9154582. llvm-svn: 129412
This commit is contained in:
@@ -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">,
|
||||
|
||||
@@ -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));
|
||||
|
||||
18
clang/test/SemaObjC/self-declared-in-block.m
Normal file
18
clang/test/SemaObjC/self-declared-in-block.m
Normal 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
|
||||
|
||||
Reference in New Issue
Block a user