Home | History | Annotate | Download | only in Rewriter
      1 // RUN: %clang_cc1 -E %s -o %t.mm
      2 // RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s
      3 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-runtime=macosx-fragile-10.5 %s -o %t-rw.cpp
      4 // RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
      5 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
      6 // 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
      7 
      8 // rdar://11375908
      9 typedef unsigned long size_t;
     10 
     11 // rdar: // 11006566
     12 
     13 void I( void (^)(void));
     14 void (^noop)(void);
     15 
     16 void nothing();
     17 int printf(const char*, ...);
     18 
     19 typedef void (^T) (void);
     20 
     21 void takeblock(T);
     22 int takeintint(int (^C)(int)) { return C(4); }
     23 
     24 T somefunction() {
     25   if (^{ })
     26     nothing();
     27 
     28   noop = ^{};
     29 
     30   noop = ^{printf("\nClosure\n"); };
     31 
     32   I(^{ });
     33 
     34   return ^{printf("\nClosure\n"); };
     35 }
     36 void test2() {
     37   int x = 4;
     38 
     39   takeblock(^{ printf("%d\n", x); });
     40 
     41   while (1) {
     42     takeblock(^{ 
     43         while(1) break;  // ok
     44       });
     45     break;
     46   }
     47 }
     48 
     49 void test4() {
     50   void (^noop)(void) = ^{};
     51   void (*noop2)() = 0;
     52 }
     53 
     54 void myfunc(int (^block)(int)) {}
     55 
     56 void myfunc3(const int *x);
     57 
     58 void test5() {
     59   int a;
     60 
     61   myfunc(^(int abcd) {
     62       myfunc3(&a);
     63       return 1;
     64     });
     65 }
     66 
     67 void *X;
     68 
     69 static int global_x = 10;
     70 void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); };
     71 
     72 // CHECK: static __global_block_block_impl_0 __global_global_block_block_impl_0((void *)__global_block_block_func_0, &__global_block_block_desc_0_DATA);
     73 // CHECK: void (*global_block)(void) = (void (*)())&__global_global_block_block_impl_0;
     74 
     75 typedef void (^void_block_t)(void);
     76 
     77 static const void_block_t myBlock = ^{ };
     78 
     79 static const void_block_t myBlock2 = ^ void(void) { }; 
     80