blob: 0866704ecf92c5a81947be559bfc0da3846c3c0c [file] [log] [blame]
Eli Friedman1e83d6f2012-11-06 21:10:22 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-gc -emit-llvm -o - %s | FileCheck %s
2// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fobjc-gc -emit-llvm -o - %s | FileCheck %s
Daniel Dunbar36e2a1e2009-05-03 21:05:10 +00003
4/*
5
6Here is a handy command for looking at llvm-gcc's output:
7llvm-gcc -m64 -fobjc-gc -emit-llvm -S -o - ivar-layout-64.m | \
8 grep 'OBJC_CLASS_NAME.* =.*global' | \
9 sed -e 's#, section.*# ...#' | \
Daniel Dunbar98ba9642009-05-04 04:10:48 +000010 sed -e 's#_[0-9]*"#_NNN#' | \
Daniel Dunbar36e2a1e2009-05-03 21:05:10 +000011 sort
12
13*/
14
15@interface B @end
16
17@interface A {
18 struct s0 {
19 int f0;
20 int f1;
21 } f0;
22 id f1;
23__weak B *f2;
24 int f3 : 5;
25 struct s1 {
26 int *f0;
27 int *f1;
28 } f4[2][1];
29}
30@end
31
Daniel Dunbar98ba9642009-05-04 04:10:48 +000032@interface C : A
33@property int p3;
34@end
35
Rafael Espindola8b27bdb2014-11-06 13:30:38 +000036// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"C\00"
37// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"\11p\00"
38// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"!`\00"
Eli Friedman1e83d6f2012-11-06 21:10:22 +000039
40
Daniel Dunbar98ba9642009-05-04 04:10:48 +000041@implementation C
42@synthesize p3 = _p3;
43@end
44
Daniel Dunbar36e2a1e2009-05-03 21:05:10 +000045@interface A()
46@property int p0;
47@property (assign) __strong id p1;
48@property (assign) __weak id p2;
49@end
50
Rafael Espindola8b27bdb2014-11-06 13:30:38 +000051// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"A\00"
52// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"\11q\10\00"
53// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"!q\00"
Eli Friedman1e83d6f2012-11-06 21:10:22 +000054
Daniel Dunbar36e2a1e2009-05-03 21:05:10 +000055@implementation A
Daniel Dunbar98ba9642009-05-04 04:10:48 +000056@synthesize p0 = _p0;
57@synthesize p1 = _p1;
58@synthesize p2 = _p2;
59@end
60
61@interface D : A
62@property int p3;
63@end
64
Rafael Espindola8b27bdb2014-11-06 13:30:38 +000065// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"D\00"
66// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"\11p\00"
67// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"!`\00"
Eli Friedman1e83d6f2012-11-06 21:10:22 +000068
Daniel Dunbar98ba9642009-05-04 04:10:48 +000069@implementation D
70@synthesize p3 = _p3;
Daniel Dunbar36e2a1e2009-05-03 21:05:10 +000071@end
Fariborz Jahanianc46fff02009-05-04 21:46:27 +000072
73typedef unsigned short UInt16;
74
75
76typedef signed char BOOL;
77typedef unsigned int FSCatalogInfoBitmap;
78
79@interface NSFileLocationComponent {
80 @private
81
82 id _specifierOrStandardizedPath;
83 BOOL _carbonCatalogInfoAndNameAreValid;
84 FSCatalogInfoBitmap _carbonCatalogInfoMask;
85 id _name;
86 id _containerComponent;
87 id _presentableName;
88 id _iconAsAttributedString;
89}
90@end
91
Rafael Espindola8b27bdb2014-11-06 13:30:38 +000092// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"NSFileLocationComponent\00"
93// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"\01\14\00"
Eli Friedman1e83d6f2012-11-06 21:10:22 +000094
Fariborz Jahanianc46fff02009-05-04 21:46:27 +000095@implementation NSFileLocationComponent @end
96
Eli Friedman1e83d6f2012-11-06 21:10:22 +000097@interface NSObject {
98 id isa;
99}
100@end
101
102@interface Foo : NSObject {
103 id ivar;
104
105 unsigned long bitfield :31;
106 unsigned long bitfield2 :1;
107 unsigned long bitfield3 :32;
108}
109@end
110
Rafael Espindola8b27bdb2014-11-06 13:30:38 +0000111// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"Foo\00"
112// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"\02\10\00"
Eli Friedman1e83d6f2012-11-06 21:10:22 +0000113
114@implementation Foo @end
John McCall3fd13f062015-10-21 18:06:47 +0000115
116// GC layout strings aren't capable of expressing __strong ivars at
117// non-word alignments.
118struct __attribute__((packed)) PackedStruct {
119 char c;
120 __strong id x;
121};
122@interface Packed : NSObject {
123 struct PackedStruct _packed;
124}
125@end
126@implementation Packed @end
127// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"Packed\00"
128// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"\01 \00"
129// ' ' == 0x20
130
131// Ensure that layout descends into anonymous unions and structs.
132// Hilariously, anonymous unions and structs that appear directly as ivars
133// are completely ignored by layout.
134
135@interface AnonymousUnion : NSObject {
136 struct {
137 union {
138 id _object;
139 void *_ptr;
140 };
141 } a;
142}
143@end
144@implementation AnonymousUnion @end
145// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"AnonymousUnion\00"
146// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"\02\00"
147
148@interface AnonymousStruct : NSObject {
149 struct {
150 struct {
151 id _object;
152 __weak id _weakref;
153 };
154 } a;
155}
156@end
157@implementation AnonymousStruct @end
158// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"AnonymousStruct\00"
159// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"\02\10\00"
160// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"!\00"
161// '!' == 0x21