xref: /llvm-project/clang/test/Rewriter/rewrite-byref-vars.mm (revision 0f1c1be1968076d6f96f8a7bcc4a15cf195ecd97)
1// 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
2// RUN: %clang_cc1 -fsyntax-only -std=gnu++98 -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
3
4extern "C" __declspec(dllexport) void BreakTheRewriter(int i) {
5        __block int aBlockVariable = 0;
6        void (^aBlock)(void) = ^ {
7                aBlockVariable = 42;
8        };
9        aBlockVariable++;
10	if (i) {
11	  __block int bbBlockVariable = 0;
12	  void (^aBlock)(void) = ^ {
13                bbBlockVariable = 42;
14          };
15        }
16}
17
18__declspec(dllexport) extern "C" __declspec(dllexport) void XXXXBreakTheRewriter(void) {
19
20        __block int aBlockVariable = 0;
21        void (^aBlock)(void) = ^ {
22                aBlockVariable = 42;
23        };
24        aBlockVariable++;
25        void (^bBlocks)(void) = ^ {
26                aBlockVariable = 43;
27        };
28        void (^c)(void) = ^ {
29                aBlockVariable = 44;
30        };
31
32}
33
34@interface I
35{
36   id list;
37}
38- (void) Meth;
39// use before definition
40- (void) allObjects;
41@end
42
43@implementation I
44// use before definition
45- (void) allObjects {
46    __attribute__((__blocks__(byref))) id *listp;
47
48    ^(void) {
49      *listp++ = 0;
50    };
51}
52- (void) Meth { __attribute__((__blocks__(byref))) void ** listp = (void **)list; }
53@end
54
55// $CLANG -cc1 -fms-extensions -rewrite-objc -fobjc-runtime=macosx-fragile-10.5 -x objective-c++ -fblocks bug.mm
56// g++ -c -D"__declspec(X)=" bug.cpp
57