blob: 6ab02a916e8b91459841dce45d94bca03a804dc0 [file] [log] [blame]
Rafael Espindolaa3f55b02013-09-04 04:12:25 +00001// RUN: %clang_cc1 -fblocks -fobjc-arc -fobjc-runtime-has-weak -triple i386-apple-darwin -print-ivar-layout -emit-llvm -o /dev/null %s > %t-32.layout
Fariborz Jahanian90a2d392013-01-17 00:25:06 +00002// RUN: FileCheck --input-file=%t-32.layout %s
3// rdar://12184410
4// rdar://12752901
Fariborz Jahanianff685c52012-12-04 17:20:57 +00005
6@class NSString;
7extern void NSLog(NSString *format, ...);
8extern int printf(const char *, ...);
9
10int main() {
11 NSString *strong;
12 unsigned long long eightByte = 0x8001800181818181ull;
13 // Test1
Fariborz Jahanian90a2d392013-01-17 00:25:06 +000014// CHECK: block variable layout: BL_NON_OBJECT_WORD:3, BL_STRONG:1, BL_OPERATOR:0
Fariborz Jahanianff685c52012-12-04 17:20:57 +000015 void (^block1)() = ^{ printf("%#llx", eightByte); NSLog(@"%@", strong); };
Fariborz Jahanianff685c52012-12-04 17:20:57 +000016
17 // Test2
18 int i = 1;
Fariborz Jahanian90a2d392013-01-17 00:25:06 +000019// CHECK: block variable layout: BL_NON_OBJECT_WORD:3, BL_STRONG:1, BL_OPERATOR:0
Fariborz Jahanianff685c52012-12-04 17:20:57 +000020 void (^block2)() = ^{ printf("%#llx, %d", eightByte, i); NSLog(@"%@", strong); };
Fariborz Jahanianff685c52012-12-04 17:20:57 +000021
22 // Test3
23 char ch = 'a';
Fariborz Jahanian90a2d392013-01-17 00:25:06 +000024// CHECK: block variable layout: BL_NON_OBJECT_WORD:3, BL_STRONG:1, BL_OPERATOR:0
Fariborz Jahanianff685c52012-12-04 17:20:57 +000025 void (^block3)() = ^{ printf("%c %#llx", ch, eightByte); NSLog(@"%@", strong); };
Fariborz Jahanianff685c52012-12-04 17:20:57 +000026
27 // Test4
28 unsigned long fourByte = 0x8001ul;
Fariborz Jahanianff685c52012-12-04 17:20:57 +000029// block variable layout: BL_NON_OBJECT_WORD:1, BL_STRONG:1, BL_OPERATOR:0
Fariborz Jahanian90a2d392013-01-17 00:25:06 +000030// CHECK: Inline instruction for block variable layout: 0x0100
31 void (^block4)() = ^{ printf("%c %#lx", ch, fourByte); NSLog(@"%@", strong); };
Fariborz Jahanianff685c52012-12-04 17:20:57 +000032
33 // Test5
Fariborz Jahanian90a2d392013-01-17 00:25:06 +000034// CHECK: block variable layout: BL_NON_OBJECT_WORD:3, BL_STRONG:1, BL_OPERATOR:0
Fariborz Jahanianff685c52012-12-04 17:20:57 +000035 void (^block5)() = ^{ NSLog(@"%@", strong); printf("%c %#llx", ch, eightByte); };
Fariborz Jahanianff685c52012-12-04 17:20:57 +000036
37 // Test6
Fariborz Jahanian90a2d392013-01-17 00:25:06 +000038// CHECK: block variable layout: BL_OPERATOR:0
Fariborz Jahanianff685c52012-12-04 17:20:57 +000039 void (^block6)() = ^{ printf("%#llx", eightByte); };
Fariborz Jahanianff685c52012-12-04 17:20:57 +000040}
41
42/**
43struct __block_literal_generic { // 32bytes (64bit) and 20 bytes (32bit).
440 void *__isa;
454 int __flags;
468 int __reserved;
4712 void (*__invoke)(void *);
4816 struct __block_descriptor *__descriptor;
49};
50*/