[cfe-commits] r154869 - in /cfe/trunk: lib/Rewrite/ test/Rewriter/

Fariborz Jahanian fjahanian at apple.com
Mon Apr 16 15:14:01 PDT 2012


Author: fjahanian
Date: Mon Apr 16 17:14:01 2012
New Revision: 154869

URL: http://llvm.org/viewvc/llvm-project?rev=154869&view=rev
Log:
modern objective-c translator: translation of implicit
cast to/from block pointer types. // rdar://11202764
Also, many more modern translator tests.

Modified:
    cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
    cfe/trunk/test/Rewriter/blockcast3.mm
    cfe/trunk/test/Rewriter/instancetype-test.mm
    cfe/trunk/test/Rewriter/objc-modern-implicit-cast.mm
    cfe/trunk/test/Rewriter/rewrite-block-consts.mm
    cfe/trunk/test/Rewriter/rewrite-block-literal.mm
    cfe/trunk/test/Rewriter/rewrite-block-pointer.mm
    cfe/trunk/test/Rewriter/rewrite-byref-in-nested-blocks.mm
    cfe/trunk/test/Rewriter/rewrite-elaborated-type.mm
    cfe/trunk/test/Rewriter/rewrite-foreach-in-block.mm
    cfe/trunk/test/Rewriter/rewrite-nested-blocks-1.mm
    cfe/trunk/test/Rewriter/rewrite-nested-blocks-2.mm
    cfe/trunk/test/Rewriter/rewrite-nested-blocks.mm
    cfe/trunk/test/Rewriter/rewrite-nested-property-in-blocks.mm
    cfe/trunk/test/Rewriter/rewrite-unique-block-api.mm

Modified: cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Mon Apr 16 17:14:01 2012
@@ -4460,19 +4460,18 @@
 
 void RewriteModernObjC::RewriteImplicitCastObjCExpr(CastExpr *IC) {
   CastKind CastKind = IC->getCastKind();
+  if (CastKind != CK_BlockPointerToObjCPointerCast &&
+      CastKind != CK_AnyPointerToBlockPointerCast)
+    return;
   
-  if (CastKind == CK_BlockPointerToObjCPointerCast) {
-    CStyleCastExpr * CastExpr = 
-      NoTypeInfoCStyleCastExpr(Context, IC->getType(), CK_BitCast, IC);
-    ReplaceStmt(IC, CastExpr);
-  }
-  else if (CastKind == CK_AnyPointerToBlockPointerCast) {
-    QualType BlockT = IC->getType();
-    (void)convertBlockPointerToFunctionPointer(BlockT);
-    CStyleCastExpr * CastExpr = 
-      NoTypeInfoCStyleCastExpr(Context, BlockT, CK_BitCast, IC);
-    ReplaceStmt(IC, CastExpr);
-  }
+  QualType QT = IC->getType();
+  (void)convertBlockPointerToFunctionPointer(QT);
+  std::string TypeString(QT.getAsString(Context->getPrintingPolicy()));
+  std::string Str = "(";
+  Str += TypeString;
+  Str += ")";
+  InsertText(IC->getSubExpr()->getLocStart(), &Str[0], Str.size());
+
   return;
 }
 
@@ -5357,12 +5356,10 @@
   if (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(S)) {
     RewriteCastExpr(CE);
   }
-#if 0
-  // FIXME. Cannot safely rewrite ImplicitCasts. This is the 2nd failed
-  // attempt: (id)((__typeof(z))_Block_copy((const void *)(z)));
   if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(S)) {
     RewriteImplicitCastObjCExpr(ICE);
   }
+#if 0
 
   if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(S)) {
     CastExpr *Replacement = new (Context) CastExpr(ICE->getType(),

Modified: cfe/trunk/test/Rewriter/blockcast3.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/blockcast3.mm?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/blockcast3.mm (original)
+++ cfe/trunk/test/Rewriter/blockcast3.mm Mon Apr 16 17:14:01 2012
@@ -1,5 +1,8 @@
-// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
+// RUN: %clang_cc1 -E %s -o %t.mm
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %t.mm -o %t-rw.cpp
 // RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o %t-modern-rw.cpp
+// RUN: FileCheck -check-prefix LP --input-file=%t-modern-rw.cpp %s
 // radar 7607781
 
 typedef struct {
@@ -20,4 +23,4 @@
 		});
 }
 
-// CHECK-LP: (struct __Block_byref_q_0 *)&q
+// CHECK-LP: (__Block_byref_q_0 *)&q

Modified: cfe/trunk/test/Rewriter/instancetype-test.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/instancetype-test.mm?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/instancetype-test.mm (original)
+++ cfe/trunk/test/Rewriter/instancetype-test.mm Mon Apr 16 17:14:01 2012
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
-// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 
 void *sel_registerName(const char *);
 

Modified: cfe/trunk/test/Rewriter/objc-modern-implicit-cast.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-modern-implicit-cast.mm?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/objc-modern-implicit-cast.mm (original)
+++ cfe/trunk/test/Rewriter/objc-modern-implicit-cast.mm Mon Apr 16 17:14:01 2012
@@ -1,7 +1,6 @@
 // RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
 // rdar://11202764
-// XFAIL: *
 
 typedef void(^BL)(void);
 

Modified: cfe/trunk/test/Rewriter/rewrite-block-consts.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-block-consts.mm?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-block-consts.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-block-consts.mm Mon Apr 16 17:14:01 2012
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
-// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D__block="" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
 // rdar:// 8243071
 
 void x(int y) {}

Modified: cfe/trunk/test/Rewriter/rewrite-block-literal.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-block-literal.mm?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-block-literal.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-block-literal.mm Mon Apr 16 17:14:01 2012
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -E %s -o %t.mm
 // RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
-// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 
 // rdar: // 11006566
 

Modified: cfe/trunk/test/Rewriter/rewrite-block-pointer.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-block-pointer.mm?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-block-pointer.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-block-pointer.mm Mon Apr 16 17:14:01 2012
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // radar 7638400
 
 typedef void * id;

Modified: cfe/trunk/test/Rewriter/rewrite-byref-in-nested-blocks.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-byref-in-nested-blocks.mm?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-byref-in-nested-blocks.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-byref-in-nested-blocks.mm Mon Apr 16 17:14:01 2012
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // radar 7692350
 
 void f(void (^block)(void));

Modified: cfe/trunk/test/Rewriter/rewrite-elaborated-type.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-elaborated-type.mm?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-elaborated-type.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-elaborated-type.mm Mon Apr 16 17:14:01 2012
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D_Bool=bool -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D_Bool=bool -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // radar 8143056
 
 typedef struct objc_class *Class;
@@ -29,6 +31,8 @@
   }
 @end
 
+ at interface I1 @end
+
 @implementation I1
 + (struct s1 *) f0 {
   return 0;

Modified: cfe/trunk/test/Rewriter/rewrite-foreach-in-block.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-foreach-in-block.mm?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-foreach-in-block.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-foreach-in-block.mm Mon Apr 16 17:14:01 2012
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // rdar:// 9878420
 
 void objc_enumerationMutation(id);

Modified: cfe/trunk/test/Rewriter/rewrite-nested-blocks-1.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-nested-blocks-1.mm?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-nested-blocks-1.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-nested-blocks-1.mm Mon Apr 16 17:14:01 2012
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // radar 7696893
 
 void *sel_registerName(const char *);

Modified: cfe/trunk/test/Rewriter/rewrite-nested-blocks-2.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-nested-blocks-2.mm?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-nested-blocks-2.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-nested-blocks-2.mm Mon Apr 16 17:14:01 2012
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
 // grep "static void __FUNC_block_copy_" %t-rw.cpp | count 2
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
+// grep "static void __FUNC_block_copy_" %t-modern-rw.cpp | count 2
 // rdar://8499592
 
 void Outer(void (^bk)());

Modified: cfe/trunk/test/Rewriter/rewrite-nested-blocks.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-nested-blocks.mm?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-nested-blocks.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-nested-blocks.mm Mon Apr 16 17:14:01 2012
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // radar 7682149
 
 

Modified: cfe/trunk/test/Rewriter/rewrite-nested-property-in-blocks.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-nested-property-in-blocks.mm?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-nested-property-in-blocks.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-nested-property-in-blocks.mm Mon Apr 16 17:14:01 2012
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -fms-extensions -Wno-address-of-temporary -Did="void *" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -fms-extensions -Wno-address-of-temporary -Did="void *" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // radar 8608293
 
 void *sel_registerName(const char *);

Modified: cfe/trunk/test/Rewriter/rewrite-unique-block-api.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-unique-block-api.mm?rev=154869&r1=154868&r2=154869&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-unique-block-api.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-unique-block-api.mm Mon Apr 16 17:14:01 2012
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // radar 7630551
 
 void f(void (^b)(char c));





More information about the cfe-commits mailing list