summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-04-12 23:39:33 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-04-12 23:39:33 +0000
commit82bc436c28fdb6651d5dccb70dae780e162e6bd4 (patch)
tree2443154893cdd5802e3f24e94e78f7345635cf53
parent3c2f74c9f30013ae5885f3e0a80798cf5ea6d253 (diff)
downloadbcm5719-llvm-82bc436c28fdb6651d5dccb70dae780e162e6bd4.tar.gz
bcm5719-llvm-82bc436c28fdb6651d5dccb70dae780e162e6bd4.zip
Redeclaration of 'self' should be flagged in
objective-c instead of crashing in IRgen. // rdar://9154582. llvm-svn: 129412
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--clang/lib/Sema/SemaExpr.cpp11
-rw-r--r--clang/test/SemaObjC/self-declared-in-block.m18
3 files changed, 31 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1dc3282c755..1bdcb88445a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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">,
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index be1d666c3a1..96b2e56b415 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -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));
diff --git a/clang/test/SemaObjC/self-declared-in-block.m b/clang/test/SemaObjC/self-declared-in-block.m
new file mode 100644
index 00000000000..c82089999c5
--- /dev/null
+++ b/clang/test/SemaObjC/self-declared-in-block.m
@@ -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
+
OpenPOWER on IntegriCloud