[cfe-commits] r128389 - in /cfe/trunk: lib/Sema/SemaExprObjC.cpp test/SemaObjC/self-in-function.m

Fariborz Jahanian fjahanian at apple.com
Sun Mar 27 12:53:47 PDT 2011


Author: fjahanian
Date: Sun Mar 27 14:53:47 2011
New Revision: 128389

URL: http://llvm.org/viewvc/llvm-project?rev=128389&view=rev
Log:
'self' is objective-c's 'self' objc pointer only in
an objc method. Fixes // rdar://9181463


Added:
    cfe/trunk/test/SemaObjC/self-in-function.m
Modified:
    cfe/trunk/lib/Sema/SemaExprObjC.cpp

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=128389&r1=128388&r2=128389&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Sun Mar 27 14:53:47 2011
@@ -324,6 +324,9 @@
 }
 
 bool Sema::isSelfExpr(Expr *RExpr) {
+  // 'self' is objc 'self' in an objc method only.
+  if (!isa<ObjCMethodDecl>(CurContext))
+    return false;
   if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(RExpr))
     if (ICE->getCastKind() == CK_LValueToRValue)
       RExpr = ICE->getSubExpr();

Added: cfe/trunk/test/SemaObjC/self-in-function.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/self-in-function.m?rev=128389&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/self-in-function.m (added)
+++ cfe/trunk/test/SemaObjC/self-in-function.m Sun Mar 27 14:53:47 2011
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1  -fsyntax-only -verify %s
+// rdar://9181463
+
+typedef struct objc_class *Class;
+
+typedef struct objc_object {
+    Class isa;
+} *id;
+
+ at interface NSObject
++ (id) alloc;
+ at end
+
+
+void foo(Class self) {
+  [self alloc];
+}
+
+void bar(Class self) {
+  Class y = self;
+  [y alloc];
+}
+





More information about the cfe-commits mailing list