]> granicus.if.org Git - clang/commitdiff
Redeclaration of 'self' should be flagged in
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 12 Apr 2011 23:39:33 +0000 (23:39 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 12 Apr 2011 23:39:33 +0000 (23:39 +0000)
objective-c instead of crashing in IRgen.
// rdar://9154582.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129412 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/SemaObjC/self-declared-in-block.m [new file with mode: 0644]

index 1dc3282c75591b381127b714912f291c3ae70fd9..1bdcb88445a199661e292a9c8a4eaadf6579d67b 100644 (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">,
index be1d666c3a1bfc1e34366401ceee3ad5b54bddde..96b2e56b4154fa4857b417804cbe894e9bc2afcd 100644 (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));
diff --git a/test/SemaObjC/self-declared-in-block.m b/test/SemaObjC/self-declared-in-block.m
new file mode 100644 (file)
index 0000000..c820899
--- /dev/null
@@ -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
+