[cfe-commits] r154670 - in /cfe/trunk: lib/Rewrite/RewriteModernObjC.cpp test/Rewriter/rewrite-modern-super.mm

Fariborz Jahanian fjahanian at apple.com
Fri Apr 13 09:20:05 PDT 2012


Author: fjahanian
Date: Fri Apr 13 11:20:05 2012
New Revision: 154670

URL: http://llvm.org/viewvc/llvm-project?rev=154670&view=rev
Log:
modern objective-c translator: When translating
call to 'super' use __rw_objc_super as type of the
'super' meta-data instead of objc_super.
// rdar://11239894

Added:
    cfe/trunk/test/Rewriter/rewrite-modern-super.mm
Modified:
    cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp

Modified: cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp?rev=154670&r1=154669&r2=154670&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Fri Apr 13 11:20:05 2012
@@ -2270,7 +2270,7 @@
   CurFunctionDeclToDeclareForBlock = 0;
 }
 
-// SynthSuperContructorFunctionDecl - id objc_super(id obj, id super);
+// SynthSuperContructorFunctionDecl - id __rw_objc_super(id obj, id super);
 void RewriteModernObjC::SynthSuperContructorFunctionDecl() {
   if (SuperContructorFunctionDecl)
     return;
@@ -2311,21 +2311,13 @@
                                          SC_None, false);
 }
 
-// SynthMsgSendSuperFunctionDecl - id objc_msgSendSuper(struct objc_super *, SEL op, ...);
+// SynthMsgSendSuperFunctionDecl - id objc_msgSendSuper(void);
 void RewriteModernObjC::SynthMsgSendSuperFunctionDecl() {
   IdentifierInfo *msgSendIdent = &Context->Idents.get("objc_msgSendSuper");
-  SmallVector<QualType, 16> ArgTys;
-  RecordDecl *RD = RecordDecl::Create(*Context, TTK_Struct, TUDecl,
-                                      SourceLocation(), SourceLocation(),
-                                      &Context->Idents.get("objc_super"));
-  QualType argT = Context->getPointerType(Context->getTagDeclType(RD));
-  assert(!argT.isNull() && "Can't build 'struct objc_super *' type");
-  ArgTys.push_back(argT);
-  argT = Context->getObjCSelType();
-  assert(!argT.isNull() && "Can't find 'SEL' type");
-  ArgTys.push_back(argT);
+  SmallVector<QualType, 2> ArgTys;
+  ArgTys.push_back(Context->VoidTy);
   QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(),
-                                               &ArgTys[0], ArgTys.size(),
+                                               &ArgTys[0], 1,
                                                true /*isVariadic*/);
   MsgSendSuperFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
                                               SourceLocation(),
@@ -2357,22 +2349,14 @@
 }
 
 // SynthMsgSendSuperStretFunctionDecl -
-// id objc_msgSendSuper_stret(struct objc_super *, SEL op, ...);
+// id objc_msgSendSuper_stret(void);
 void RewriteModernObjC::SynthMsgSendSuperStretFunctionDecl() {
   IdentifierInfo *msgSendIdent =
     &Context->Idents.get("objc_msgSendSuper_stret");
-  SmallVector<QualType, 16> ArgTys;
-  RecordDecl *RD = RecordDecl::Create(*Context, TTK_Struct, TUDecl,
-                                      SourceLocation(), SourceLocation(),
-                                      &Context->Idents.get("objc_super"));
-  QualType argT = Context->getPointerType(Context->getTagDeclType(RD));
-  assert(!argT.isNull() && "Can't build 'struct objc_super *' type");
-  ArgTys.push_back(argT);
-  argT = Context->getObjCSelType();
-  assert(!argT.isNull() && "Can't find 'SEL' type");
-  ArgTys.push_back(argT);
+  SmallVector<QualType, 2> ArgTys;
+  ArgTys.push_back(Context->VoidTy);
   QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(),
-                                               &ArgTys[0], ArgTys.size(),
+                                               &ArgTys[0], 1,
                                                true /*isVariadic*/);
   MsgSendSuperStretFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
                                                        SourceLocation(),
@@ -2925,18 +2909,20 @@
   return CE;
 }
 
-// struct objc_super { struct objc_object *receiver; struct objc_class *super; };
+// struct __rw_objc_super { 
+//   struct objc_object *object; struct objc_object *superClass; 
+// };
 QualType RewriteModernObjC::getSuperStructType() {
   if (!SuperStructDecl) {
     SuperStructDecl = RecordDecl::Create(*Context, TTK_Struct, TUDecl,
                                          SourceLocation(), SourceLocation(),
-                                         &Context->Idents.get("objc_super"));
+                                         &Context->Idents.get("__rw_objc_super"));
     QualType FieldTypes[2];
 
-    // struct objc_object *receiver;
+    // struct objc_object *object;
     FieldTypes[0] = Context->getObjCIdType();
-    // struct objc_class *super;
-    FieldTypes[1] = Context->getObjCClassType();
+    // struct objc_object *superClass;
+    FieldTypes[1] = Context->getObjCIdType();
 
     // Create fields
     for (unsigned i = 0; i < 2; ++i) {
@@ -3073,7 +3059,7 @@
                         NoTypeInfoCStyleCastExpr(Context,
                                                  Context->getObjCIdType(),
                                                  CK_BitCast, Cls));
-    // struct objc_super
+    // struct __rw_objc_super
     QualType superType = getSuperStructType();
     Expr *SuperRep;
 
@@ -3091,7 +3077,7 @@
       // the structure definition in the header. The rewriter has it's own
       // internal definition (__rw_objc_super) that is uses. This is why
       // we need the cast below. For example:
-      // (struct objc_super *)&__rw_objc_super((id)self, (id)objc_getClass("SUPER"))
+      // (struct __rw_objc_super *)&__rw_objc_super((id)self, (id)objc_getClass("SUPER"))
       //
       SuperRep = new (Context) UnaryOperator(SuperRep, UO_AddrOf,
                                Context->getPointerType(SuperRep->getType()),
@@ -3101,7 +3087,7 @@
                                           Context->getPointerType(superType),
                                           CK_BitCast, SuperRep);
     } else {
-      // (struct objc_super) { <exprs from above> }
+      // (struct __rw_objc_super) { <exprs from above> }
       InitListExpr *ILE =
         new (Context) InitListExpr(*Context, SourceLocation(),
                                    &InitExprs[0], InitExprs.size(),
@@ -3111,7 +3097,7 @@
       SuperRep = new (Context) CompoundLiteralExpr(SourceLocation(), superTInfo,
                                                    superType, VK_LValue,
                                                    ILE, false);
-      // struct objc_super *
+      // struct __rw_objc_super *
       SuperRep = new (Context) UnaryOperator(SuperRep, UO_AddrOf,
                                Context->getPointerType(SuperRep->getType()),
                                              VK_RValue, OK_Ordinary,
@@ -3183,7 +3169,7 @@
       // set 'super class', using class_getSuperclass().
       NoTypeInfoCStyleCastExpr(Context, Context->getObjCIdType(),
                                CK_BitCast, Cls));
-    // struct objc_super
+    // struct __rw_objc_super
     QualType superType = getSuperStructType();
     Expr *SuperRep;
 
@@ -3200,7 +3186,7 @@
       // the structure definition in the header. The rewriter has it's own
       // internal definition (__rw_objc_super) that is uses. This is why
       // we need the cast below. For example:
-      // (struct objc_super *)&__rw_objc_super((id)self, (id)objc_getClass("SUPER"))
+      // (struct __rw_objc_super *)&__rw_objc_super((id)self, (id)objc_getClass("SUPER"))
       //
       SuperRep = new (Context) UnaryOperator(SuperRep, UO_AddrOf,
                                Context->getPointerType(SuperRep->getType()),
@@ -3210,7 +3196,7 @@
                                Context->getPointerType(superType),
                                CK_BitCast, SuperRep);
     } else {
-      // (struct objc_super) { <exprs from above> }
+      // (struct __rw_objc_super) { <exprs from above> }
       InitListExpr *ILE =
         new (Context) InitListExpr(*Context, SourceLocation(),
                                    &InitExprs[0], InitExprs.size(),

Added: cfe/trunk/test/Rewriter/rewrite-modern-super.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-modern-super.mm?rev=154670&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-modern-super.mm (added)
+++ cfe/trunk/test/Rewriter/rewrite-modern-super.mm Fri Apr 13 11:20:05 2012
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp 
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=struct objc_object *" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// rdar://11239894
+
+extern "C" void *sel_registerName(const char *);
+
+typedef struct objc_class * Class;
+
+ at interface Sub
+- (void)dealloc;
+ at end
+
+ at interface I : Sub
+- (void)dealloc;
+ at end
+
+ at implementation I
+- (void)dealloc {
+    return;
+    [super dealloc];
+}
+ at end
+





More information about the cfe-commits mailing list