[cfe-commits] r129412 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/SemaObjC/self-declared-in-block.m

Fariborz Jahanian fjahanian at apple.com
Tue Apr 12 16:39:33 PDT 2011


Author: fjahanian
Date: Tue Apr 12 18:39:33 2011
New Revision: 129412

URL: http://llvm.org/viewvc/llvm-project?rev=129412&view=rev
Log:
Redeclaration of 'self' should be flagged in
objective-c instead of crashing in IRgen.
// rdar://9154582.

Added:
    cfe/trunk/test/SemaObjC/self-declared-in-block.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=129412&r1=129411&r2=129412&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 12 18:39:33 2011
@@ -3797,6 +3797,8 @@
   "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">,

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=129412&r1=129411&r2=129412&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Apr 12 18:39:33 2011
@@ -1915,6 +1915,17 @@
         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));

Added: cfe/trunk/test/SemaObjC/self-declared-in-block.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/self-declared-in-block.m?rev=129412&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/self-declared-in-block.m (added)
+++ cfe/trunk/test/SemaObjC/self-declared-in-block.m Tue Apr 12 18:39:33 2011
@@ -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
+
+ at interface Blocky @end
+
+ at 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}}
+    }();
+}
+
+ at end
+





More information about the cfe-commits mailing list