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