• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// 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
3
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.*# ...#' | \
10  sed -e 's#_[0-9]*"#_NNN#' | \
11  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
32@interface C : A
33@property int p3;
34@end
35
36// 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"
39
40
41@implementation C
42@synthesize p3 = _p3;
43@end
44
45@interface A()
46@property int p0;
47@property (assign) __strong id p1;
48@property (assign) __weak id p2;
49@end
50
51// 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"
54
55@implementation A
56@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
65// 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"
68
69@implementation D
70@synthesize p3 = _p3;
71@end
72
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
92// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"NSFileLocationComponent\00"
93// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"\01\14\00"
94
95@implementation NSFileLocationComponent @end
96
97@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
111// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"Foo\00"
112// CHECK: @OBJC_CLASS_NAME_{{.*}} = private global {{.*}} c"\02\10\00"
113
114@implementation Foo @end
115
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
162