xref: /llvm-project/clang/test/CodeGenObjC/mrr-captured-block-var-inlined-layout.m (revision 0f1c1be1968076d6f96f8a7bcc4a15cf195ecd97)
1// RUN: %clang_cc1 -fblocks -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin -print-ivar-layout -emit-llvm -o /dev/null %s > %t-64.layout
2// RUN: FileCheck --input-file=%t-64.layout %s
3// RUN: %clang_cc1 -fblocks -fobjc-runtime-has-weak -fobjc-arc -triple i386-apple-darwin -print-ivar-layout -emit-llvm -o /dev/null %s > %t-32.layout
4// RUN: FileCheck --input-file=%t-32.layout %s
5
6void x(id y) {}
7void y(int a) {}
8
9extern id opaque_id(void);
10__weak id wid;
11
12void f(void) {
13    __block int byref_int = 0;
14    const id bar = (id) opaque_id();
15    id baz = 0;
16    __strong id strong_void_sta;
17    __block id byref_bab = (id)0;
18    __block id bl_var1;
19
20// block variable layout: BL_STRONG:1, BL_OPERATOR:0
21// CHECK: Inline block variable layout: 0x0100, BL_STRONG:1, BL_OPERATOR:0
22    void (^b)(void) = ^{
23        x(bar);
24    };
25
26// block variable layout: BL_STRONG:2, BL_BYREF:1, BL_OPERATOR:0
27// CHECK: Inline block variable layout: 0x0210, BL_STRONG:2, BL_BYREF:1, BL_OPERATOR:0
28    void (^c)(void) = ^{
29        x(bar);
30        x(baz);
31        byref_int = 1;
32    };
33
34// block variable layout: BL_STRONG:2, BL_BYREF:3, BL_OPERATOR:0
35// CHECK: Inline block variable layout: 0x0230, BL_STRONG:2, BL_BYREF:3, BL_OPERATOR:0
36    void (^d)(void) = ^{
37        x(bar);
38        x(baz);
39        byref_int = 1;
40        bl_var1 = 0;
41        byref_bab = 0;
42    };
43
44// block variable layout: BL_STRONG:2, BL_BYREF:3, BL_OPERATOR:0
45// CHECK: Inline block variable layout: 0x0230, BL_STRONG:2, BL_BYREF:3, BL_OPERATOR:0
46    id (^e)(void) = ^{
47        x(bar);
48        x(baz);
49        byref_int = 1;
50        bl_var1 = 0;
51        byref_bab = 0;
52        return wid;
53    };
54
55// CHECK: Inline block variable layout: 0x020, BL_BYREF:2, BL_OPERATOR:0
56    void (^ii)(void) = ^{
57       byref_int = 1;
58       byref_bab = 0;
59    };
60}
61