xref: /minix3/external/bsd/llvm/dist/clang/test/Rewriter/rewrite-modern-block.mm (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
2f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -Werror -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -U__declspec -D"__declspec(X)=" %t-rw.cpp
3f4a2713aSLionel Sambuc// rdar://11230308
4f4a2713aSLionel Sambuc
5f4a2713aSLionel Sambuctypedef unsigned long size_t;
6f4a2713aSLionel Sambuctypedef struct {
7f4a2713aSLionel Sambuc    char byte0;
8f4a2713aSLionel Sambuc    char byte1;
9f4a2713aSLionel Sambuc} CFUUIDBytes;
10f4a2713aSLionel Sambuc
11f4a2713aSLionel Sambucvoid x(void *);
12f4a2713aSLionel Sambuc
13f4a2713aSLionel Sambucvoid y() {
14f4a2713aSLionel Sambuc    __block CFUUIDBytes bytes;
15f4a2713aSLionel Sambuc
16f4a2713aSLionel Sambuc    void (^bar)() = ^{
17f4a2713aSLionel Sambuc        x(&bytes);
18f4a2713aSLionel Sambuc    };
19f4a2713aSLionel Sambuc}
20f4a2713aSLionel Sambuc
21f4a2713aSLionel Sambuc// rdar://11236342
22f4a2713aSLionel Sambucint foo() {
23f4a2713aSLionel Sambuc    __block int hello;
24f4a2713aSLionel Sambuc    return hello;
25f4a2713aSLionel Sambuc}
26f4a2713aSLionel Sambuc
27f4a2713aSLionel Sambuc// rdar://7547630
28f4a2713aSLionel Sambuc// rewriting multiple __block decls on wintin same decl stmt.
29f4a2713aSLionel Sambucvoid radar7547630() {
30f4a2713aSLionel Sambuc  __block int BI1, BI2;
31f4a2713aSLionel Sambuc
32f4a2713aSLionel Sambuc  __block float FLOAT1, FT2, FFFFFFFF3,
33f4a2713aSLionel Sambuc   FFFXXX4;
34f4a2713aSLionel Sambuc
35f4a2713aSLionel Sambuc  __block void (^B)(), (^BB)();
36f4a2713aSLionel Sambuc}
37f4a2713aSLionel Sambuc
38f4a2713aSLionel Sambuc// rewriting multiple __block decls on wintin same decl stmt
39f4a2713aSLionel Sambuc// with initializers.
40f4a2713aSLionel Sambucint  rdar7547630(const char *keybuf, const char *valuebuf) {
41f4a2713aSLionel Sambuc  __block int BI1 = 1, BI2 = 2;
42f4a2713aSLionel Sambuc
43f4a2713aSLionel Sambuc  double __block BYREFVAR = 1.34, BYREFVAR_NO_INIT, BYREFVAR2 = 1.37;
44f4a2713aSLionel Sambuc
45f4a2713aSLionel Sambuc  __block const char *keys = keybuf, *values = valuebuf, *novalues;
46f4a2713aSLionel Sambuc
47f4a2713aSLionel Sambuc  return BI2;
48f4a2713aSLionel Sambuc}
49f4a2713aSLionel Sambuc
50f4a2713aSLionel Sambuc// rdar://11326988
51f4a2713aSLionel Sambuctypedef struct _z {
52f4a2713aSLionel Sambuc    int location;
53f4a2713aSLionel Sambuc    int length;
54f4a2713aSLionel Sambuc} z;
55f4a2713aSLionel Sambuc
56f4a2713aSLionel Sambucz w(int loc, int len);
57f4a2713aSLionel Sambuc
58f4a2713aSLionel Sambuc@interface rdar11326988
59f4a2713aSLionel Sambuc@end
60f4a2713aSLionel Sambuc@implementation rdar11326988
61f4a2713aSLionel Sambuc- (void)y:(int)options {
62f4a2713aSLionel Sambuc    __attribute__((__blocks__(byref))) z firstRange = w(1, 0);
63f4a2713aSLionel Sambuc    options &= ~(1 | 2);
64f4a2713aSLionel Sambuc}
65f4a2713aSLionel Sambuc@end
66*0a6a1f1dSLionel Sambuc
67*0a6a1f1dSLionel Sambuc// rdar://18799145
68*0a6a1f1dSLionel Sambucint Test18799145() { return ^(){return 0;}(); }
69