Add more reference-binding examples from the C++0x working paper, all of which seem...
[clang.git] / test / CodeGenObjC / block-var-layout.m
blobfa131f63bee5cb52782aea29fcc7b37ec66c32e4
1 // RUN: %clang_cc1 -fblocks -fobjc-gc -triple x86_64-apple-darwin -O0 -S %s -o %t-64.s
2 // RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s
4 struct S {
5     int i1;
6     id o1;
7     struct V {
8      int i2;
9      id o2;
10     } v1;
11     int i3;
12     id o3;
15 __weak id wid;
16 void x(id y) {}
17 void y(int a) {}
19 void f() {
20     __block int byref_int = 0;
21     char ch = 'a';
22     char ch1 = 'b';
23     char ch2 = 'c';
24     short sh = 2;
25     const id bar = (id)0;
26     id baz = 0;
27     __strong void *strong_void_sta;
28     __block id byref_bab = (id)0;
29     __block void *bl_var1;
30     int i; double dob;
32     void (^b)() = ^{
33         byref_int = sh + ch+ch1+ch2 ;
34         x(bar);
35         x(baz);
36         x((id)strong_void_sta);
37         x(byref_bab);
38     };    
39     b();
41 // Test 2
42     void (^c)() = ^{
43         byref_int = sh + ch+ch1+ch2 ;
44         x(bar);
45         x(baz);
46         x((id)strong_void_sta);
47         x(wid);
48         bl_var1 = 0;
49         x(byref_bab);
50     };    
51     c();
53 // Test 3
54 void (^d)() = ^{
55         byref_int = sh + ch+ch1+ch2 ;
56         x(bar);
57         x(baz);
58         x(wid);
59         bl_var1 = 0; 
60         y(i + dob);
61         x(byref_bab);
62     };    
63     d();
65 // Test4
66     struct S s2;
67     void (^e)() = ^{
68         x(s2.o1);
69     };    
70     e();
73 // Test 5 (unions/structs and their nesting):
74 void Test5() {
75 struct S5 {
76     int i1;
77     id o1;
78     struct V {
79      int i2;
80      id o2;
81     } v1;
82     int i3;
83     union UI {
84         void * i1;
85         id o1;
86         int i3;
87         id o3;
88     }ui;
91 union U {
92         void * i1;
93         id o1;
94         int i3;
95         id o3;
96 }ui;
98 struct S5 s2;
99 union U u2;
100 void (^c)() = ^{
101     x(s2.ui.o1);
102     x(u2.o1);
104 c();
108 // rdar: //8417746
109 void CFRelease(id);
110 void notifyBlock(id dependentBlock) {
111  id singleObservationToken;
112  id token;
113  void (^b)();
114  void (^wrapperBlock)() = ^() {
115      CFRelease(singleObservationToken);
116      CFRelease(singleObservationToken);
117      CFRelease(token);
118      CFRelease(singleObservationToken);
119      b();
120     };
121  wrapperBlock();
124 void test_empty_block() {
125  void (^wrapperBlock)() = ^() {
126     };
127  wrapperBlock();
130 // CHECK-LP64: L_OBJC_CLASS_NAME_:
131 // CHECK-LP64-NEXT: .asciz      "\0011\024"
133 // CHECK-LP64: L_OBJC_CLASS_NAME_1:
134 // CHECK-LP64-NEXT: .asciz   "\0011\025"
136 // CHECK-LP64: L_OBJC_CLASS_NAME_6:
137 // CHECK-LP64-NEXT: .asciz   "\0011\023!"
139 // CHECK-LP64: L_OBJC_CLASS_NAME_11:
140 // CHECK-LP64-NEXT: .asciz   "\001A\021\021"
142 // CHECK-LP64: L_OBJC_CLASS_NAME_14:
143 // CHECK-LP64-NEXT: .asciz   "\001A\021\022p"
145 // CHECK-LP64: L_OBJC_CLASS_NAME_16:
146 // CHECK-LP64-NEXT: .asciz   "\0013"
148 // CHECK-LP64: L_OBJC_CLASS_NAME_20:
149 // CHECK-LP64-NEXT: .asciz   "\001"