aboutsummaryrefslogtreecommitdiff
path: root/test/CodeGenObjC
diff options
context:
space:
mode:
Diffstat (limited to 'test/CodeGenObjC')
-rw-r--r--test/CodeGenObjC/2008-10-23-invalid-icmp.m7
-rw-r--r--test/CodeGenObjC/attr-strong.c9
-rw-r--r--test/CodeGenObjC/bitfield-1.m81
-rw-r--r--test/CodeGenObjC/bitfield-ivar-metadata.m15
-rw-r--r--test/CodeGenObjC/bitfield-ivar-offsets.m26
-rw-r--r--test/CodeGenObjC/blocks-1.m33
-rw-r--r--test/CodeGenObjC/blocks-2.m11
-rw-r--r--test/CodeGenObjC/blocks.m36
-rw-r--r--test/CodeGenObjC/category-super-class-meth.m19
-rw-r--r--test/CodeGenObjC/class-getter-dotsyntax.m21
-rw-r--r--test/CodeGenObjC/class-obj-hidden-visibility.m6
-rw-r--r--test/CodeGenObjC/class-type.m36
-rw-r--r--test/CodeGenObjC/compatibility-alias.m8
-rw-r--r--test/CodeGenObjC/constant-strings.m4
-rw-r--r--test/CodeGenObjC/continuation-class.m35
-rw-r--r--test/CodeGenObjC/debug-info.m18
-rw-r--r--test/CodeGenObjC/dot-syntax-1.m264
-rw-r--r--test/CodeGenObjC/dot-syntax.m98
-rw-r--r--test/CodeGenObjC/encode-test-1.m36
-rw-r--r--test/CodeGenObjC/encode-test-2.m29
-rw-r--r--test/CodeGenObjC/encode-test-3.m21
-rw-r--r--test/CodeGenObjC/encode-test-4.m5
-rw-r--r--test/CodeGenObjC/encode-test-5.m16
-rw-r--r--test/CodeGenObjC/encode-test.m94
-rw-r--r--test/CodeGenObjC/forward-class-impl-metadata.m41
-rw-r--r--test/CodeGenObjC/hidden-synthesized-ivar.m13
-rw-r--r--test/CodeGenObjC/hidden.m19
-rw-r--r--test/CodeGenObjC/image-info.m2
-rw-r--r--test/CodeGenObjC/implicit-objc_msgSend.m7
-rw-r--r--test/CodeGenObjC/implicit-property.m16
-rw-r--r--test/CodeGenObjC/interface-layout-64.m124
-rw-r--r--test/CodeGenObjC/interface.m34
-rw-r--r--test/CodeGenObjC/ivar-layout-64.m89
-rw-r--r--test/CodeGenObjC/ivars.m14
-rw-r--r--test/CodeGenObjC/link-errors.m39
-rw-r--r--test/CodeGenObjC/message-arrays.m15
-rw-r--r--test/CodeGenObjC/messages-2.m139
-rw-r--r--test/CodeGenObjC/messages.m27
-rw-r--r--test/CodeGenObjC/metadata-symbols-32.m88
-rw-r--r--test/CodeGenObjC/metadata-symbols-64.m130
-rw-r--r--test/CodeGenObjC/metadata_symbols.m61
-rw-r--r--test/CodeGenObjC/newproperty-nested-synthesis-1.m78
-rw-r--r--test/CodeGenObjC/no-category-class.m8
-rw-r--r--test/CodeGenObjC/non-lazy-classes.m33
-rw-r--r--test/CodeGenObjC/objc-align.m47
-rw-r--r--test/CodeGenObjC/objc2-assign-global.m8
-rw-r--r--test/CodeGenObjC/objc2-no-strong-cast.m22
-rw-r--r--test/CodeGenObjC/objc2-no-write-barrier.m18
-rw-r--r--test/CodeGenObjC/objc2-property-encode.m13
-rw-r--r--test/CodeGenObjC/objc2-protocol-enc.m43
-rw-r--r--test/CodeGenObjC/objc2-retain-codegen.m12
-rw-r--r--test/CodeGenObjC/objc2-strong-cast-1.m23
-rw-r--r--test/CodeGenObjC/objc2-strong-cast-2.m27
-rw-r--r--test/CodeGenObjC/objc2-strong-cast.m17
-rw-r--r--test/CodeGenObjC/objc2-weak-compare.m24
-rw-r--r--test/CodeGenObjC/objc2-weak-ivar.m10
-rw-r--r--test/CodeGenObjC/overloadable.m10
-rw-r--r--test/CodeGenObjC/predefined-expr-in-method.m17
-rw-r--r--test/CodeGenObjC/property-aggr-type.m50
-rw-r--r--test/CodeGenObjC/property-agrr-getter.m17
-rw-r--r--test/CodeGenObjC/property-getter-dot-syntax.m11
-rw-r--r--test/CodeGenObjC/property-incr-decr-1.m29
-rw-r--r--test/CodeGenObjC/property-setter-attr.m10
-rw-r--r--test/CodeGenObjC/property.m52
-rw-r--r--test/CodeGenObjC/protocol-definition-hidden-visibility.m19
-rw-r--r--test/CodeGenObjC/protocol-property-synth.m33
-rw-r--r--test/CodeGenObjC/protocols-lazy.m48
-rw-r--r--test/CodeGenObjC/runtime-fns.m33
-rw-r--r--test/CodeGenObjC/super-classmethod-category.m13
-rw-r--r--test/CodeGenObjC/super-dotsyntax-property.m41
-rw-r--r--test/CodeGenObjC/synchronized.m41
-rw-r--r--test/CodeGenObjC/synthesize_ivar-cont-class.m18
-rw-r--r--test/CodeGenObjC/synthesize_ivar.m27
-rw-r--r--test/CodeGenObjC/try.m9
-rw-r--r--test/CodeGenObjC/unname-bf-metadata.m14
75 files changed, 2661 insertions, 0 deletions
diff --git a/test/CodeGenObjC/2008-10-23-invalid-icmp.m b/test/CodeGenObjC/2008-10-23-invalid-icmp.m
new file mode 100644
index 000000000000..2c58b9217675
--- /dev/null
+++ b/test/CodeGenObjC/2008-10-23-invalid-icmp.m
@@ -0,0 +1,7 @@
+// RUN: clang-cc -emit-llvm -o %t %s
+
+@protocol P @end
+
+int f0(id<P> d) {
+ return (d != ((void*) 0));
+}
diff --git a/test/CodeGenObjC/attr-strong.c b/test/CodeGenObjC/attr-strong.c
new file mode 100644
index 000000000000..ca8333449435
--- /dev/null
+++ b/test/CodeGenObjC/attr-strong.c
@@ -0,0 +1,9 @@
+// RUN: clang -emit-llvm -S -o %t %s
+
+struct s0 {
+ void *a;
+};
+struct s0 * __attribute__((objc_gc(strong))) g0;
+void f0(void) {
+ g0->a = 0;
+}
diff --git a/test/CodeGenObjC/bitfield-1.m b/test/CodeGenObjC/bitfield-1.m
new file mode 100644
index 000000000000..06ea91132ef3
--- /dev/null
+++ b/test/CodeGenObjC/bitfield-1.m
@@ -0,0 +1,81 @@
+// RUN: clang-cc -triple x86_64-apple-darwin9 -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: clang-cc -triple i386-apple-darwin9 -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: clang-cc -triple i386-pc-linux-gnu -emit-llvm -o %t %s
+
+@interface Object
+- (id) alloc;
+- (id) init;
+@end
+
+extern void abort(void);
+
+#define CHECK_IF(expr) if(!(expr)) abort();
+
+@interface Base: Object
+{
+ int full;
+ int full2: 32;
+ int _refs: 8;
+ int field2: 3;
+ unsigned f3: 8;
+ short cc;
+ unsigned g: 16;
+ int r2: 8;
+ int r3: 8;
+ int r4: 2;
+ int r5: 8;
+ char c;
+}
+- (void)setValues;
+@end
+
+@interface Derived: Base
+{
+ char d;
+ int _field3: 6;
+}
+- (void)checkValues;
+@end
+
+@implementation Base
+-(void)setValues {
+ full = 1;
+ full2 = 2;
+ _refs = 3;
+ field2 = 1;
+ f3 = 6;
+ cc = 7;
+ g = 8;
+ r2 = 9;
+ r3 = 10;
+ r4 = 1;
+ r5 = 12;
+ c = 13;
+}
+@end
+
+@implementation Derived
+-(void)checkValues {
+ CHECK_IF(full == 1);
+ CHECK_IF(full2 == 2);
+ CHECK_IF(_refs == 3);
+ CHECK_IF(field2 == 1);
+ CHECK_IF(f3 == 6);
+ CHECK_IF(cc == 7);
+ CHECK_IF(g == 8);
+ CHECK_IF(r2 == 9);
+ CHECK_IF(r3 == 10);
+ CHECK_IF(r4 == 1);
+ CHECK_IF(r5 == 12);
+ CHECK_IF(c == 13);
+}
+@end
+
+int main(void) {
+ Derived *obj = [[Derived alloc] init];
+
+ [obj setValues];
+ [obj checkValues];
+
+ return 0;
+}
diff --git a/test/CodeGenObjC/bitfield-ivar-metadata.m b/test/CodeGenObjC/bitfield-ivar-metadata.m
new file mode 100644
index 000000000000..542a2424caa1
--- /dev/null
+++ b/test/CodeGenObjC/bitfield-ivar-metadata.m
@@ -0,0 +1,15 @@
+// RUN: clang-cc -fnext-runtime -emit-llvm -o %t %s
+
+@interface INTF
+{
+ unsigned ivar1;
+ unsigned ivar2;
+ unsigned char BDIVAR3:1;
+ unsigned char BDIVAR4:1;
+}
+@end
+
+@implementation INTF
+@end
+
+
diff --git a/test/CodeGenObjC/bitfield-ivar-offsets.m b/test/CodeGenObjC/bitfield-ivar-offsets.m
new file mode 100644
index 000000000000..23a09a3a15b8
--- /dev/null
+++ b/test/CodeGenObjC/bitfield-ivar-offsets.m
@@ -0,0 +1,26 @@
+// RUNX: llvm-gcc -m64 -emit-llvm -S -o %t %s &&
+// RUN: clang-cc -triple x86_64-apple-darwin10 -emit-llvm -o %t %s &&
+// RUN: grep -F '@"OBJC_IVAR_$_I0._b0" = global i64 0, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep -F '@"OBJC_IVAR_$_I0._b1" = global i64 0, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep -F '@"OBJC_IVAR_$_I0._b2" = global i64 1, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep -F '@"OBJC_IVAR_$_I0._x" = global i64 2, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep -F '@"OBJC_IVAR_$_I0._b3" = global i64 4, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep -F '@"OBJC_IVAR_$_I0._y" = global i64 6, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep -F '@"OBJC_IVAR_$_I0._b4" = global i64 7, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep -F '@"OBJC_IVAR_$_I0." = global' %t | count 0 &&
+// RUN: true
+
+@interface I0 {
+ unsigned _b0:4;
+ unsigned _b1:5;
+ unsigned _b2:5;
+ char _x;
+ unsigned _b3:9;
+ char _y;
+ char _b4:3;
+ char : 0;
+}
+@end
+
+@implementation I0
+@end
diff --git a/test/CodeGenObjC/blocks-1.m b/test/CodeGenObjC/blocks-1.m
new file mode 100644
index 000000000000..2b4f8faeb82e
--- /dev/null
+++ b/test/CodeGenObjC/blocks-1.m
@@ -0,0 +1,33 @@
+// RUN: clang-cc %s -emit-llvm -o %t -fobjc-gc -fblocks -triple i386-apple-darwin10 &&
+// RUN: grep "_Block_object_dispose" %t | count 6 &&
+// RUN: grep "__copy_helper_block_" %t | count 4 &&
+// RUN: grep "__destroy_helper_block_" %t | count 4 &&
+// RUN: grep "__Block_byref_id_object_copy_" %t | count 2 &&
+// RUN: grep "__Block_byref_id_object_dispose_" %t | count 2 &&
+// RUN: grep "i32 135)" %t | count 0 &&
+// RUN: grep "_Block_object_assign" %t | count 4 &&
+// RUN: grep "objc_read_weak" %t | count 2 &&
+// RUN: grep "objc_assign_weak" %t | count 3
+
+@interface NSDictionary @end
+
+void test1(NSDictionary * dict) {
+ ^{ (void)dict; }();
+}
+
+@interface D
+@end
+
+void foo() {
+ __block __weak D *weakSelf;
+ D *l;
+ l = weakSelf;
+ weakSelf = l;
+}
+
+void (^__weak b)(void);
+
+void test2() {
+ __block int i = 0;
+ b = ^ { ++i; };
+}
diff --git a/test/CodeGenObjC/blocks-2.m b/test/CodeGenObjC/blocks-2.m
new file mode 100644
index 000000000000..a4d8bfa6b7fc
--- /dev/null
+++ b/test/CodeGenObjC/blocks-2.m
@@ -0,0 +1,11 @@
+// RUN: clang-cc %s -emit-llvm -o %t -fobjc-gc -fblocks -triple i386-apple-darwin10 &&
+// RUN: grep "objc_assign_strongCast" %t | count 2 &&
+// RUN: true
+
+// This should generate a strong cast.
+
+id test3(id x) {
+ __block id result;
+ ^{ result = x; }();
+ return result;
+}
diff --git a/test/CodeGenObjC/blocks.m b/test/CodeGenObjC/blocks.m
new file mode 100644
index 000000000000..18c455ad9ebe
--- /dev/null
+++ b/test/CodeGenObjC/blocks.m
@@ -0,0 +1,36 @@
+// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm -fblocks -o %t %s &&
+// rdar://6676764
+
+struct S {
+ void (^F)(struct S*);
+} P;
+
+
+@interface T
+
+ - (int)foo: (T (^)(T*)) x;
+@end
+
+void foo(T *P) {
+ [P foo: 0];
+}
+
+@interface A
+-(void) im0;
+@end
+
+// RUN: grep 'define internal i32 @"__-\[A im0\]_block_invoke_"' %t &&
+@implementation A
+-(void) im0 {
+ (void) ^{ return 1; }();
+}
+@end
+
+@interface B : A @end
+@implementation B
+-(void) im1 {
+ ^(void) { [super im0]; }();
+}
+@end
+
+// RUN: true
diff --git a/test/CodeGenObjC/category-super-class-meth.m b/test/CodeGenObjC/category-super-class-meth.m
new file mode 100644
index 000000000000..95d8b3103c9f
--- /dev/null
+++ b/test/CodeGenObjC/category-super-class-meth.m
@@ -0,0 +1,19 @@
+// RUN: clang-cc -fnext-runtime -emit-llvm -o %t %s
+
+@interface BASE
++ (int) BaseMeth;
+@end
+
+@interface Child: BASE
+@end
+
+@interface Child (Categ)
++ (int) flushCache2;
+@end
+
+@implementation Child @end
+
+@implementation Child (Categ)
++ (int) flushCache2 { [super BaseMeth]; }
+@end
+
diff --git a/test/CodeGenObjC/class-getter-dotsyntax.m b/test/CodeGenObjC/class-getter-dotsyntax.m
new file mode 100644
index 000000000000..3c82f78d08b5
--- /dev/null
+++ b/test/CodeGenObjC/class-getter-dotsyntax.m
@@ -0,0 +1,21 @@
+// RUN: clang-cc -fnext-runtime -emit-llvm -o %t %s
+
+@interface Test { }
++ (Test *)crash;
++ (void)setCrash: (int)value;
+@end
+
+@implementation Test
+static int _value;
+- (void)cachesPath
+{
+ static Test *cachesPath;
+
+ if (!cachesPath) {
+ Test *crash = Test.crash;
+ }
+}
++ (Test *)crash{ return 0; }
++ (void)setCrash: (int)value{ _value = value; }
+@end
+
diff --git a/test/CodeGenObjC/class-obj-hidden-visibility.m b/test/CodeGenObjC/class-obj-hidden-visibility.m
new file mode 100644
index 000000000000..fc4ac12b1836
--- /dev/null
+++ b/test/CodeGenObjC/class-obj-hidden-visibility.m
@@ -0,0 +1,6 @@
+// RUN: clang-cc -fvisibility=hidden -triple x86_64-apple-darwin10 -S -o - %s | grep -e "private_extern _OBJC_" | count 2
+
+@interface INTF @end
+
+@implementation INTF @end
+
diff --git a/test/CodeGenObjC/class-type.m b/test/CodeGenObjC/class-type.m
new file mode 100644
index 000000000000..794d9a355794
--- /dev/null
+++ b/test/CodeGenObjC/class-type.m
@@ -0,0 +1,36 @@
+// RUN: clang-cc -triple x86_64-unknown-unknown -emit-llvm -o - %s &&
+// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm -o - %s &&
+// RUN: clang-cc -triple x86_64-apple-darwin9 -emit-llvm -o - %s
+
+
+@interface I0 {
+ struct { int a; } a;
+}
+@end
+
+@class I2;
+
+@interface I1 {
+ I2 *_imageBrowser;
+}
+@end
+
+@implementation I1
+@end
+
+@interface I2 : I0
+@end
+
+@implementation I2
+@end
+
+
+// Implementations without interface declarations.
+// rdar://6804402
+@class foo;
+@implementation foo
+@end
+
+@implementation bar
+@end
+
diff --git a/test/CodeGenObjC/compatibility-alias.m b/test/CodeGenObjC/compatibility-alias.m
new file mode 100644
index 000000000000..11e5a27ab713
--- /dev/null
+++ b/test/CodeGenObjC/compatibility-alias.m
@@ -0,0 +1,8 @@
+// RUN: clang-cc -emit-llvm -o %t %s
+
+@interface Int1 @end
+
+typedef Int1 Int1Typedef;
+@compatibility_alias Int1Alias Int1Typedef;
+
+@implementation Int1Alias @end
diff --git a/test/CodeGenObjC/constant-strings.m b/test/CodeGenObjC/constant-strings.m
new file mode 100644
index 000000000000..d4fefd903653
--- /dev/null
+++ b/test/CodeGenObjC/constant-strings.m
@@ -0,0 +1,4 @@
+// RUN: clang-cc -fnext-runtime -emit-llvm -o %t %s
+
+id a = @"Hello World!";
+
diff --git a/test/CodeGenObjC/continuation-class.m b/test/CodeGenObjC/continuation-class.m
new file mode 100644
index 000000000000..925f3cd0c50d
--- /dev/null
+++ b/test/CodeGenObjC/continuation-class.m
@@ -0,0 +1,35 @@
+// RUN: clang-cc -fnext-runtime --emit-llvm -o %t %s
+
+@interface Object
+- (id)new;
+@end
+
+@interface ReadOnly : Object
+{
+ int _object;
+ int _Anotherobject;
+}
+@property(readonly) int object;
+@property(readonly) int Anotherobject;
+@end
+
+@interface ReadOnly ()
+@property(readwrite) int object;
+@property(readwrite, setter = myAnotherobjectSetter:) int Anotherobject;
+@end
+
+@implementation ReadOnly
+@synthesize object = _object;
+@synthesize Anotherobject = _Anotherobject;
+- (void) myAnotherobjectSetter : (int)val {
+ _Anotherobject = val;
+}
+@end
+
+int main(int argc, char **argv) {
+ ReadOnly *test = [ReadOnly new];
+ test.object = 12345;
+ test.Anotherobject = 200;
+ return test.object - 12345 + test.Anotherobject - 200;
+}
+
diff --git a/test/CodeGenObjC/debug-info.m b/test/CodeGenObjC/debug-info.m
new file mode 100644
index 000000000000..9c461ba68fb4
--- /dev/null
+++ b/test/CodeGenObjC/debug-info.m
@@ -0,0 +1,18 @@
+// RUN: clang-cc -triple i386-apple-darwin9 -g -emit-llvm -o %t %s &&
+// RUN: grep '@.str3 = internal constant \[8 x i8\] c"-\[A m0\]\\00"' %t &&
+// RUN: grep '@.str4 = internal constant \[9 x i8\] c"\\01-\[A m0\]\\00"' %t &&
+// RUN: grep '@llvm.dbg.subprogram = .* @.str3, .* @.str3, .* @.str4,' %t &&
+// RUN: grep '@llvm.dbg.composite.* = .* i32 15, i64 0, i64 8, .* i32 16' %t &&
+// RUN: true
+
+
+
+
+
+
+
+
+@interface A @end
+@implementation A // Line 15
+-(void) m0 {}
+@end
diff --git a/test/CodeGenObjC/dot-syntax-1.m b/test/CodeGenObjC/dot-syntax-1.m
new file mode 100644
index 000000000000..6c4dcbbef0dc
--- /dev/null
+++ b/test/CodeGenObjC/dot-syntax-1.m
@@ -0,0 +1,264 @@
+// RUN: clang-cc -fnext-runtime --emit-llvm -o %t %s
+
+#include <stdio.h>
+
+@interface Root
+-(id) alloc;
+-(id) init;
+@end
+
+// Property above methods...
+
+@interface Top0 : Root
+@property(getter=_getX,setter=_setX:) int x;
+@end
+
+@interface Bot0 : Top0
+-(int) x;
+-(void) setX: (int) arg;
+@end
+
+@implementation Top0
+-(int) _getX {
+ printf("-[ Top0 _getX ]\n");
+ return 0;
+}
+-(void) _setX: (int) arg {
+ printf("-[ Top0 _setX: %d ]\n", arg);
+}
+@end
+
+@implementation Bot0
+-(int) x {
+ printf("-[ Bot0 _getX ]\n");
+ return 0;
+}
+-(void) setX: (int) arg {
+ printf("-[ Bot0 _setX: %d ]\n", arg);
+}
+@end
+
+// Methods above property...
+
+@interface Top1 : Root
+-(int) x;
+-(void) setX: (int) arg;
+@end
+
+@interface Bot1 : Top1
+@property(getter=_getX,setter=_setX:) int x;
+@end
+
+@implementation Top1
+-(int) x {
+ printf("-[ Top1 x ]\n");
+ return 0;
+}
+-(void) setX: (int) arg {
+ printf("-[ Top1 setX: %d ]\n", arg);
+}
+@end
+
+@implementation Bot1
+-(int) _getX {
+ printf("-[ Bot1 _getX ]\n");
+ return 0;
+}
+-(void) _setX: (int) arg {
+ printf("-[ Bot1 _setX: %d ]\n", arg);
+}
+@end
+
+// Mixed setter & getter (variant 1)
+
+@interface Top2 : Root
+-(int) x;
+-(void) _setX: (int) arg;
+@end
+
+@interface Bot2 : Top2
+@property(getter=_getX,setter=_setX:) int x;
+@end
+
+@implementation Top2
+-(int) x {
+ printf("-[ Top2 x ]\n");
+ return 0;
+}
+-(void) _setX: (int) arg {
+ printf("-[ Top2 _setX: %d ]\n", arg);
+}
+@end
+
+@implementation Bot2
+-(int) _getX {
+ printf("-[ Bot2 _getX ]\n");
+ return 0;
+}
+-(void) setX: (int) arg {
+ printf("-[ Bot2 setX: %d ]\n", arg);
+}
+@end
+
+// Mixed setter & getter (variant 2)
+
+@interface Top3 : Root
+-(int) _getX;
+-(void) setX: (int) arg;
+@end
+
+@interface Bot3 : Top3
+@property(getter=_getX,setter=_setX:) int x;
+@end
+
+@implementation Top3
+-(int) _getX {
+ printf("-[ Top3 _getX ]\n");
+ return 0;
+}
+-(void) setX: (int) arg {
+ printf("-[ Top3 setX: %d ]\n", arg);
+}
+@end
+
+@implementation Bot3
+-(int) x {
+ printf("-[ Bot3 x ]\n");
+ return 0;
+}
+-(void) _setX: (int) arg {
+ printf("-[ Bot3 _setX: %d ]\n", arg);
+}
+@end
+
+// Mixed setter & getter (variant 3)
+
+@interface Top4 : Root
+@property(getter=_getX,setter=_setX:) int x;
+@end
+
+@interface Bot4 : Top4
+-(int) _getX;
+-(void) setX: (int) arg;
+@end
+
+@implementation Top4
+-(int) x {
+ printf("-[ Top4 x ]\n");
+ return 0;
+}
+-(void) _setX: (int) arg {
+ printf("-[ Top4 _setX: %d ]\n", arg);
+}
+@end
+
+@implementation Bot4
+-(int) _getX {
+ printf("-[ Bot4 _getX ]\n");
+ return 0;
+}
+-(void) setX: (int) arg {
+ printf("-[ Bot4 setX: %d ]\n", arg);
+}
+@end
+
+// Mixed setter & getter (variant 4)
+
+@interface Top5 : Root
+@property(getter=_getX,setter=_setX:) int x;
+@end
+
+@interface Bot5 : Top5
+-(int) x;
+-(void) _setX: (int) arg;
+@end
+
+@implementation Top5
+-(int) _getX {
+ printf("-[ Top5 _getX ]\n");
+ return 0;
+}
+-(void) setX: (int) arg {
+ printf("-[ Top5 setX: %d ]\n", arg);
+}
+@end
+
+@implementation Bot5
+-(int) x {
+ printf("-[ Bot5 x ]\n");
+ return 0;
+}
+-(void) _setX: (int) arg {
+ printf("-[ Bot5 _setX: %d ]\n", arg);
+}
+@end
+
+// Mixed level calls (variant 1)
+
+@interface Top6 : Root
+-(int) x;
+@end
+
+@interface Bot6 : Top6
+-(void) setX: (int) arg;
+@end
+
+@implementation Top6
+-(int) x {
+ printf("-[ Top6 x ]\n");
+ return 0;
+}
+@end
+
+@implementation Bot6
+-(void) setX: (int) arg {
+ printf("-[ Bot5 setX: %d ]\n", arg);
+}
+@end
+
+// Mixed level calls (variant 1)
+
+@interface Top7 : Root
+-(void) setX: (int) arg;
+@end
+
+@interface Bot7 : Top7
+-(int) x;
+@end
+
+@implementation Top7
+-(void) setX: (int) arg {
+ printf("-[ Top7 setX: %d ]\n", arg);
+}
+@end
+
+@implementation Bot7
+-(int) x {
+ printf("-[ Bot7 x ]\n");
+ return 0;
+}
+@end
+
+//
+
+// FIXME: Two more (thats it?) interesting cases. Method access on
+// getter w/o setter and method access on setter w/o getter.
+
+int main() {
+#define test(N) { \
+ Bot##N *ob = [[Bot##N alloc] init]; \
+ int x = ob.x; \
+ ob.x = 10; }
+
+ test(0);
+ test(1);
+ test(2);
+ test(3);
+ test(4);
+ test(5);
+ // test(6);
+ // test(7);
+
+ return 0;
+}
+
diff --git a/test/CodeGenObjC/dot-syntax.m b/test/CodeGenObjC/dot-syntax.m
new file mode 100644
index 000000000000..68c8ad0b7580
--- /dev/null
+++ b/test/CodeGenObjC/dot-syntax.m
@@ -0,0 +1,98 @@
+// RUN: clang-cc -fnext-runtime --emit-llvm -o %t %s
+
+#include <stdio.h>
+
+@interface Root
+-(id) alloc;
+-(id) init;
+@end
+
+typedef struct {
+ float x, y, z[2];
+} S;
+
+@interface A : Root {
+ int myX;
+ // __complex myY;
+ S myZ;
+}
+
+@property int x;
+//@property __complex int y;
+@property S z;
+@end
+
+@implementation A
+-(int) x {
+ printf("-[A x] = %d\n", myX);
+ return myX;
+}
+-(void) setX: (int) arg {
+ myX = arg;
+ printf("-[A setX: %d]\n", myX);
+}
+
+// FIXME: Add back
+#if 0
+-(__complex int) y {
+ printf("-[A y] = (%d, %d)\n", __real myY, __imag myY);
+ return myY;
+}
+-(void) setY: (__complex int) arg {
+ myY = arg;
+ printf("-[A setY: (%d, %d)]\n", __real myY, __imag myY);
+}
+#endif
+
+-(S) z {
+ printf("-[A z] = { %f, %f, { %f, %f } }\n",
+ myZ.x, myZ.y, myZ.z[0], myZ.z[1]);
+ return myZ;
+}
+-(void) setZ: (S) arg {
+ myZ = arg;
+ printf("-[A setZ: { %f, %f, { %f, %f } } ]\n",
+ myZ.x, myZ.y, myZ.z[0], myZ.z[1]);
+}
+
+@end
+
+int main() {
+#define SWAP(T,a,b) { T a_tmp = a; a = b; b = a_tmp; }
+ A *a = [[A alloc] init];
+ A *b = [[A alloc] init];
+ int a0 = 23;
+ // __complex a1 = 25 + 10i;
+ S a2 = { 246, 458, {275, 12} };
+ int b0 = 42673;
+ // __complex b1 = 15 + 13i;
+ S b2 = { 26, 2, {367, 13} };
+
+ a.x = a0;
+ // a.y = a1;
+ a.z = a2;
+
+ a.x += a0;
+ // a.y += a1;
+ // Yay, no compound assign of structures. A GCC extension in the
+ // works, perhaps?
+
+ b.x = b0;
+ // b.y = b1;
+ b.z = b2;
+
+ int x0 = (b.x = b0);
+ printf("(b.x = b0): %d\n", x0);
+
+ // int x1 = __real (b.y = b1);
+ // printf("__real (b.y = b1) = %d\n", x1);
+
+ float x2 = (b.z = b2).x;
+ printf("(b.z = b2).x: %f\n", x2);
+
+ SWAP(int, a.x, b.x);
+ // SWAP(__complex int, a.y, b.y);
+ SWAP(S, a.z, b.z);
+
+ return 0;
+}
diff --git a/test/CodeGenObjC/encode-test-1.m b/test/CodeGenObjC/encode-test-1.m
new file mode 100644
index 000000000000..b4f3b0f9c33d
--- /dev/null
+++ b/test/CodeGenObjC/encode-test-1.m
@@ -0,0 +1,36 @@
+// RUN: clang-cc -triple=i686-apple-darwin9 -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: grep -e "{Base=b2b3b4b5}" %t | count 1 &&
+// RUN: grep -e "{Derived=b2b3b4b5b5b4b3}" %t | count 1
+
+enum Enum { one, two, three, four };
+
+@interface Base {
+ unsigned a: 2;
+ int b: 3;
+ enum Enum c: 4;
+ unsigned d: 5;
+}
+@end
+
+@interface Derived: Base {
+ signed e: 5;
+ int f: 4;
+ enum Enum g: 3;
+}
+@end
+
+@implementation Base @end
+
+@implementation Derived @end
+
+int main(void)
+{
+
+ const char *en = @encode(Base);
+// printf ("%s\n", en);
+
+ const char *ed = @encode(Derived);
+ // printf ("%s\n", ed);
+
+ return 0;
+}
diff --git a/test/CodeGenObjC/encode-test-2.m b/test/CodeGenObjC/encode-test-2.m
new file mode 100644
index 000000000000..6901168b1d09
--- /dev/null
+++ b/test/CodeGenObjC/encode-test-2.m
@@ -0,0 +1,29 @@
+// RUN: clang-cc -triple=i686-apple-darwin9 -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: grep -e "@\\\22<X>\\\22" %t &&
+// RUN: grep -e "@\\\22<X><Y>\\\22" %t &&
+// RUN: grep -e "@\\\22<X><Y><Z>\\\22" %t &&
+// RUN: grep -e "@\\\22Foo<X><Y><Z>\\\22" %t &&
+// RUN: grep -e "{Intf=@@@@}" %t
+
+@protocol X, Y, Z;
+@class Foo;
+
+@protocol Proto
+@end
+
+@interface Intf <Proto>
+{
+id <X> IVAR_x;
+id <X, Y> IVAR_xy;
+id <X, Y, Z> IVAR_xyz;
+Foo <X, Y, Z> *IVAR_Fooxyz;
+}
+@end
+
+@implementation Intf
+@end
+
+int main()
+{
+ const char * en = @encode(Intf);
+}
diff --git a/test/CodeGenObjC/encode-test-3.m b/test/CodeGenObjC/encode-test-3.m
new file mode 100644
index 000000000000..116e825e32a0
--- /dev/null
+++ b/test/CodeGenObjC/encode-test-3.m
@@ -0,0 +1,21 @@
+// RUN: clang-cc -triple=i686-apple-darwin9 -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: grep -e "\^i" %t | count 1 &&
+// RUN: grep -e "\[0i\]" %t | count 1
+
+int main() {
+ int n;
+
+ const char * inc = @encode(int[]);
+ const char * vla = @encode(int[n]);
+}
+
+// PR3648
+int a[sizeof(@encode(int)) == 2 ? 1 : -1]; // Type is char[2]
+const char *B = @encode(int);
+char (*c)[2] = &@encode(int); // @encode is an lvalue
+
+char d[] = @encode(int); // infer size.
+char e[1] = @encode(int); // truncate
+char f[2] = @encode(int); // fits
+char g[3] = @encode(int); // zero fill
+
diff --git a/test/CodeGenObjC/encode-test-4.m b/test/CodeGenObjC/encode-test-4.m
new file mode 100644
index 000000000000..90b300200a06
--- /dev/null
+++ b/test/CodeGenObjC/encode-test-4.m
@@ -0,0 +1,5 @@
+// RUN: clang-cc -emit-llvm -o - %s -O2 | grep "ret i32 1"
+
+int a() {
+ return @encode(int) == @encode(int);
+}
diff --git a/test/CodeGenObjC/encode-test-5.m b/test/CodeGenObjC/encode-test-5.m
new file mode 100644
index 000000000000..a76b071e7fed
--- /dev/null
+++ b/test/CodeGenObjC/encode-test-5.m
@@ -0,0 +1,16 @@
+// RUN: clang-cc -triple=x86_64-apple-darwin9 -fnext-runtime -emit-llvm -o %t %s &&
+
+// RUN: grep ji %t | count 1 &&
+char *a = @encode(_Complex int);
+
+// RUN: grep jf %t | count 1 &&
+char *b = @encode(_Complex float);
+
+// RUN: grep jd %t | count 1 &&
+char *c = @encode(_Complex double);
+
+// RUN: grep "t.00" %t | count 1 &&
+char *e = @encode(__int128_t);
+
+// RUN: grep "T.00" %t | count 1
+char *f = @encode(__uint128_t);
diff --git a/test/CodeGenObjC/encode-test.m b/test/CodeGenObjC/encode-test.m
new file mode 100644
index 000000000000..ca54a51c3b1c
--- /dev/null
+++ b/test/CodeGenObjC/encode-test.m
@@ -0,0 +1,94 @@
+// RUN: clang-cc -triple=i686-apple-darwin9 -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: grep -e "\^{Innermost=CC}" %t | count 1 &&
+// RUN: grep -e "{Derived=#ib32b8b3b8sb16b8b8b2b8ccb6}" %t | count 1 &&
+// RUN: grep -e "{B1=#@c}" %t | count 1 &&
+// RUN: grep -e "v12@0:4\[3\[4@]]8" %t | count 1 &&
+// RUN: grep -e "r\^{S=i}" %t | count 1 &&
+// RUN: grep -e "\^{Object=#}" %t | count 1
+
+@class Int1;
+
+struct Innermost {
+ unsigned char a, b;
+};
+
+@interface Int1 {
+ signed char a, b;
+ struct Innermost *innermost;
+}
+@end
+
+@implementation Int1
+@end
+
+@interface Base
+{
+ struct objc_class *isa;
+ int full;
+ int full2: 32;
+ int _refs: 8;
+ int field2: 3;
+ unsigned f3: 8;
+ short cc;
+ unsigned g: 16;
+ int r2: 8;
+ int r3: 8;
+ int r4: 2;
+ int r5: 8;
+ char c;
+}
+@end
+
+@interface Derived: Base
+{
+ char d;
+ int _field3: 6;
+}
+@end
+
+@implementation Base
+@end
+
+@implementation Derived
+@end
+
+@interface B1
+{
+ struct objc_class *isa;
+ Int1 *sBase;
+ char c;
+}
+@end
+
+@implementation B1
+@end
+
+@interface Test
+{
+ int ivar;
+}
+-(void) test3: (Test* [3] [4])b ;
+@end
+
+@implementation Test
+-(void) test3: (Test* [3] [4])b {}
+@end
+
+struct S { int iS; };
+
+@interface Object
+{
+ Class isa;
+}
+@end
+typedef Object MyObj;
+
+int main()
+{
+ const char *en = @encode(Derived);
+ const char *eb = @encode(B1);
+ const char *es = @encode(const struct S *);
+ const char *ec = @encode(const struct S);
+ const char *ee = @encode(MyObj *const);
+}
+
diff --git a/test/CodeGenObjC/forward-class-impl-metadata.m b/test/CodeGenObjC/forward-class-impl-metadata.m
new file mode 100644
index 000000000000..b8ce10aaa510
--- /dev/null
+++ b/test/CodeGenObjC/forward-class-impl-metadata.m
@@ -0,0 +1,41 @@
+// RUN: clang-cc -triple x86_64-apple-darwin10 -emit-llvm -o %t %s
+
+@interface BASE {
+@private
+ void* _reserved;
+}
+@end
+
+@class PVR;
+
+@interface PVRHandldler
+{
+ PVR *_imageBrowser;
+}
+@end
+
+@implementation PVRHandldler @end
+
+
+@interface PVR : BASE
+@end
+
+@implementation PVR
+@end
+
+// Reopen of an interface after use.
+
+@interface A {
+@public
+ int x;
+}
+@property int p0;
+@end
+
+int f0(A *a) {
+ return a.p0;
+}
+
+@implementation A
+@synthesize p0 = _p0;
+@end
diff --git a/test/CodeGenObjC/hidden-synthesized-ivar.m b/test/CodeGenObjC/hidden-synthesized-ivar.m
new file mode 100644
index 000000000000..50a87cb2f453
--- /dev/null
+++ b/test/CodeGenObjC/hidden-synthesized-ivar.m
@@ -0,0 +1,13 @@
+// RUN: clang-cc -fvisibility=hidden -triple x86_64-apple-darwin10 -S -o - %s | grep -e "private_extern _OBJC_IVAR_"
+@interface I
+{
+ int P;
+}
+
+@property int P;
+@end
+
+@implementation I
+@synthesize P;
+@end
+
diff --git a/test/CodeGenObjC/hidden.m b/test/CodeGenObjC/hidden.m
new file mode 100644
index 000000000000..6b86ca0581cc
--- /dev/null
+++ b/test/CodeGenObjC/hidden.m
@@ -0,0 +1,19 @@
+// RUN: clang-cc -fnext-runtime --emit-llvm -o %t %s
+
+__attribute__((visibility("hidden")))
+@interface Hidden
++(void) bar;
+@end
+
+@implementation Hidden
++(void) bar {}
+@end
+
+__attribute__((visibility("default")))
+@interface Default
++(void) bar;
+@end
+
+@implementation Default
++(void) bar {}
+@end
diff --git a/test/CodeGenObjC/image-info.m b/test/CodeGenObjC/image-info.m
new file mode 100644
index 000000000000..e8650129e3f7
--- /dev/null
+++ b/test/CodeGenObjC/image-info.m
@@ -0,0 +1,2 @@
+// RUN: clang-cc -triple x86_64-apple-darwin-10 -emit-llvm -o %t %s &&
+// RUN: grep -F '@"\01L_OBJC_IMAGE_INFO" = internal constant [2 x i32] [i32 0, i32 16], section "__OBJC, __image_info,regular"' %t
diff --git a/test/CodeGenObjC/implicit-objc_msgSend.m b/test/CodeGenObjC/implicit-objc_msgSend.m
new file mode 100644
index 000000000000..4511cca338b2
--- /dev/null
+++ b/test/CodeGenObjC/implicit-objc_msgSend.m
@@ -0,0 +1,7 @@
+// RUN: clang-cc -triple x86_64-apple-darwin9 -emit-llvm -o %t %s &&
+// RUN: grep -F 'declare i8* @objc_msgSend(...)' %t
+
+typedef struct objc_selector *SEL;
+id f0(id x, SEL s) {
+ return objc_msgSend(x, s);
+}
diff --git a/test/CodeGenObjC/implicit-property.m b/test/CodeGenObjC/implicit-property.m
new file mode 100644
index 000000000000..206d496252d8
--- /dev/null
+++ b/test/CodeGenObjC/implicit-property.m
@@ -0,0 +1,16 @@
+// RUN: clang-cc -emit-llvm -triple=i686-apple-darwin8 -o %t %s
+// RUNX: clang-cc -emit-llvm -o %t %s
+
+@interface A
+ -(void) setOk:(int)arg;
+ -(int) ok;
+
+ -(void) setX:(int)arg;
+ -(int) x;
+@end
+
+void f0(A *a) {
+ a.x = 1;
+ a.ok = a.x;
+}
+
diff --git a/test/CodeGenObjC/interface-layout-64.m b/test/CodeGenObjC/interface-layout-64.m
new file mode 100644
index 000000000000..13d6a8770f65
--- /dev/null
+++ b/test/CodeGenObjC/interface-layout-64.m
@@ -0,0 +1,124 @@
+// RUN: clang-cc -triple x86_64-apple-darwin9 -emit-llvm -o %t %s &&
+// RUNX: llvm-gcc -m64 -emit-llvm -S -o %t %s &&
+
+// RUN: grep '@"OBJC_IVAR_$_I3._iv2" = global i64 8, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"OBJC_IVAR_$_I3._iv3" = global i64 12, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"OBJC_IVAR_$_I4._iv4" = global i64 13, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"OBJC_IVAR_$_I5._iv5" = global i64 14, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"OBJC_IVAR_$_I5._iv6_synth" = global i64 16, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"OBJC_IVAR_$_I5._iv7_synth" = global i64 20, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"OBJC_IVAR_$_I6.iv0" = global i64 0, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"OBJC_IVAR_$_I8.b" = global i64 8, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"OBJC_IVAR_$_I9.iv0" = global i64 0, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"OBJC_IVAR_$_I10.iv1" = global i64 4, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"OBJC_IVAR_$_I12.iv2" = global i64 8, section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '_OBJC_CLASS_RO_$_I3" = internal global .* { i32 0, i32 8, i32 13, .*' %t &&
+// RUN: grep '_OBJC_CLASS_RO_$_I4" = internal global .* { i32 0, i32 13, i32 14, .*' %t &&
+// RUN: grep '_OBJC_CLASS_RO_$_I5" = internal global .* { i32 0, i32 14, i32 24, .*' %t &&
+// RUN: grep '_OBJC_CLASS_RO_$_I6" = internal global .* { i32 2, i32 0, i32 1, .*' %t &&
+// RUN: grep '_OBJC_CLASS_RO_$_I8" = internal global .* { i32 0, i32 8, i32 16, .*' %t &&
+// RUN: grep '_OBJC_CLASS_RO_$_I9" = internal global .* { i32 2, i32 0, i32 4, .*' %t &&
+// RUN: grep '_OBJC_CLASS_RO_$_I10" = internal global .* { i32 0, i32 4, i32 5, .*' %t &&
+// RUN: grep '_OBJC_CLASS_RO_$_I11" = internal global .* { i32 0, i32 5, i32 5, .*' %t &&
+// RUN: grep '_OBJC_CLASS_RO_$_I12" = internal global .* { i32 0, i32 8, i32 12, .*' %t &&
+
+// RUN: true
+
+/*
+ Compare to:
+ gcc -m64 -S -o - interface-layout-64.m | grep '^_OBJC_IVAR_$_*.*' -A 1
+ and
+ gcc -m64 -S -o - interface-layout-64.m | grep '^l.*_CLASS_RO_$_I[0-9]*' -A 3
+ */
+
+struct s0 {
+ double x;
+};
+
+@interface I2 {
+ struct s0 _iv1;
+}
+@end
+
+@interface I3 : I2 {
+ unsigned int _iv2 :1;
+ unsigned : 0;
+ unsigned int _iv3 : 3;
+}
+@end
+
+@interface I4 : I3 {
+ char _iv4;
+}
+@end
+
+@interface I5 : I4 {
+ char _iv5;
+}
+
+@property int prop0;
+@end
+
+@implementation I3
+@end
+
+@implementation I4
+@end
+
+@interface I5 ()
+@property int prop1;
+@property char prop2;
+@end
+
+@implementation I5
+@synthesize prop0 = _iv6_synth;
+@synthesize prop1 = _iv7_synth;
+@synthesize prop2 = _iv5;
+@end
+
+// The size rounds up to the next available byte.
+@interface I6 {
+ unsigned iv0 : 2;
+}
+@end
+@implementation I6
+@end
+
+// The start of the subclass includes padding for its own alignment.
+@interface I7 {
+ char a;
+}
+@end
+@interface I8 : I7 {
+ double b;
+}
+@end
+@implementation I8
+@end
+
+// Padding bit-fields
+@interface I9 {
+ unsigned iv0 : 2;
+ unsigned : 0;
+}
+@end
+@implementation I9
+@end
+@interface I10 : I9 {
+ unsigned iv1 : 2;
+}
+@end
+@implementation I10
+@end
+
+// Empty structures
+@interface I11 : I10
+@end
+@implementation I11
+@end
+@interface I12 : I11 {
+ unsigned iv2;
+}
+@end
+@implementation I12
+@end
diff --git a/test/CodeGenObjC/interface.m b/test/CodeGenObjC/interface.m
new file mode 100644
index 000000000000..d506e88ee7c9
--- /dev/null
+++ b/test/CodeGenObjC/interface.m
@@ -0,0 +1,34 @@
+// RUN: clang-cc -triple i386-apple-darwin9 -O3 -emit-llvm -o %t %s &&
+// RUN: grep 'ret i32 385' %t
+
+void *alloca();
+
+@interface I0 {
+@public
+ int iv0;
+ int iv1;
+ int iv2;
+}
+@end
+
+static int f0(I0 *a0) {
+ return (*(a0 + 2)).iv0;
+}
+
+static int f1(I0 *a0) {
+ return a0[2].iv1;
+}
+
+static int f2(I0 *a0) {
+ return (*(a0 - 1)).iv2;
+}
+
+int g0(void) {
+ I0 *a = alloca(sizeof(*a) * 4);
+ a[2].iv0 = 5;
+ a[2].iv1 = 7;
+ a[2].iv2 = 11;
+ return f0(a) * f1(a) * f2(&a[3]);
+}
+
+
diff --git a/test/CodeGenObjC/ivar-layout-64.m b/test/CodeGenObjC/ivar-layout-64.m
new file mode 100644
index 000000000000..7301e168218e
--- /dev/null
+++ b/test/CodeGenObjC/ivar-layout-64.m
@@ -0,0 +1,89 @@
+// RUNX: llvm-gcc -m64 -fobjc-gc -emit-llvm -S -o %t %s &&
+// RUN: clang-cc -triple x86_64-apple-darwin9 -fobjc-gc -emit-llvm -o %t %s &&
+// RUN: grep '@"\\01L_OBJC_CLASS_NAME_.*" = internal global .* c"A\\00"' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASS_NAME_.*" = internal global .* c"\\11q\\10\\00"' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASS_NAME_.*" = internal global .* c"!q\\00"' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASS_NAME_.*" = internal global .* c"\\01\\14\\00"' %t &&
+// RUN: true
+
+/*
+
+Here is a handy command for looking at llvm-gcc's output:
+llvm-gcc -m64 -fobjc-gc -emit-llvm -S -o - ivar-layout-64.m | \
+ grep 'OBJC_CLASS_NAME.* =.*global' | \
+ sed -e 's#, section.*# ...#' | \
+ sed -e 's#_[0-9]*"#_NNN#' | \
+ sort
+
+*/
+
+@interface B @end
+
+@interface A {
+ struct s0 {
+ int f0;
+ int f1;
+ } f0;
+ id f1;
+__weak B *f2;
+ int f3 : 5;
+ struct s1 {
+ int *f0;
+ int *f1;
+ } f4[2][1];
+}
+@end
+
+@interface C : A
+@property int p3;
+@end
+
+@implementation C
+@synthesize p3 = _p3;
+@end
+
+@interface A()
+@property int p0;
+@property (assign) __strong id p1;
+@property (assign) __weak id p2;
+@end
+
+// FIXME: Check layout for this class, once it is clear what the right
+// answer is.
+@implementation A
+@synthesize p0 = _p0;
+@synthesize p1 = _p1;
+@synthesize p2 = _p2;
+@end
+
+@interface D : A
+@property int p3;
+@end
+
+// FIXME: Check layout for this class, once it is clear what the right
+// answer is.
+@implementation D
+@synthesize p3 = _p3;
+@end
+
+typedef unsigned short UInt16;
+
+
+typedef signed char BOOL;
+typedef unsigned int FSCatalogInfoBitmap;
+
+@interface NSFileLocationComponent {
+ @private
+
+ id _specifierOrStandardizedPath;
+ BOOL _carbonCatalogInfoAndNameAreValid;
+ FSCatalogInfoBitmap _carbonCatalogInfoMask;
+ id _name;
+ id _containerComponent;
+ id _presentableName;
+ id _iconAsAttributedString;
+}
+@end
+
+@implementation NSFileLocationComponent @end
+
diff --git a/test/CodeGenObjC/ivars.m b/test/CodeGenObjC/ivars.m
new file mode 100644
index 000000000000..327b628532e1
--- /dev/null
+++ b/test/CodeGenObjC/ivars.m
@@ -0,0 +1,14 @@
+// RUN: clang-cc -triple x86_64-apple-darwin9 -emit-llvm -o - %s &&
+// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm -o - %s
+
+// rdar://6800926
+@interface ITF {
+@public
+ unsigned field :1 ;
+ _Bool boolfield :1 ;
+}
+@end
+
+void foo(ITF *P) {
+ P->boolfield = 1;
+}
diff --git a/test/CodeGenObjC/link-errors.m b/test/CodeGenObjC/link-errors.m
new file mode 100644
index 000000000000..b50d93993fc8
--- /dev/null
+++ b/test/CodeGenObjC/link-errors.m
@@ -0,0 +1,39 @@
+// RUN: clang-cc -triple i386-apple-darwin9 -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: grep '.lazy_reference .objc_class_name_A' %t | count 1 &&
+// RUN: grep '.lazy_reference .objc_class_name_Unknown' %t | count 1 &&
+// RUN: grep '.lazy_reference .objc_class_name_Protocol' %t | count 1 &&
+// RUN: clang-cc -triple i386-apple-darwin9 -DWITH_IMPL -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: grep '.lazy_reference .objc_class_name_Root' %t | count 1
+
+@interface Root
+-(id) alloc;
+-(id) init;
+@end
+
+@protocol P;
+
+@interface A : Root
+@end
+
+@interface A (Category)
++(void) foo;
+@end
+
+#ifdef WITH_IMPL
+@implementation A
+@end
+#endif
+
+@interface Unknown
++test;
+@end
+
+
+int main() {
+ id x = @protocol(P);
+ [ A alloc ];
+ [ A foo ];
+ [ Unknown test ];
+ return 0;
+}
+
diff --git a/test/CodeGenObjC/message-arrays.m b/test/CodeGenObjC/message-arrays.m
new file mode 100644
index 000000000000..c618672feab2
--- /dev/null
+++ b/test/CodeGenObjC/message-arrays.m
@@ -0,0 +1,15 @@
+// RUN: clang-cc -fnext-runtime -emit-llvm -o %t %s
+
+void f0(id a) {
+ // This should have an implicit cast
+ [ a print: "hello" ];
+}
+
+@interface A
+-(void) m: (int) arg0, ...;
+@end
+
+int f1(A *a) {
+ // This should also get an implicit cast (for the vararg)
+ [a m: 1, "test"];
+}
diff --git a/test/CodeGenObjC/messages-2.m b/test/CodeGenObjC/messages-2.m
new file mode 100644
index 000000000000..ca0eb9493387
--- /dev/null
+++ b/test/CodeGenObjC/messages-2.m
@@ -0,0 +1,139 @@
+// RUN: clang-cc -fnext-runtime --emit-llvm -o %t %s
+
+#include <stdio.h>
+
+@interface Root
+@end
+
+typedef struct {
+ int x, y, z[10];
+} MyPoint;
+typedef struct {
+ float width, height;
+} MySize;
+
+@interface A : Root
++(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3;
++(float) returnAFloat;
++(double) returnADouble;
++(MyPoint) returnAPoint;
++(void) printThisSize: (MySize) arg0;
++(MySize) returnASize;
+
+-(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3;
+-(float) returnAFloat;
+-(double) returnADouble;
+-(MyPoint) returnAPoint;
+-(void) printThisSize: (MySize) arg0;
+-(MySize) returnASize;
+@end
+@interface B : A
+@end
+
+@implementation A
++(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3 {
+ printf("(CLASS) theInt: %d, theFloat: %f, theDouble: %f, thePoint: { %d, %d }\n",
+ arg0, arg1, arg2, arg3.x, arg3.y);
+}
++(float) returnAFloat {
+ return 15.;
+}
++(double) returnADouble {
+ return 25.;
+}
++(MyPoint) returnAPoint {
+ MyPoint x = { 35, 45 };
+ return x;
+}
++(void) printThisSize: (MySize) arg0 {
+ printf("(CLASS) theSize: { %f, %f }\n",
+ arg0.width, arg0.height);
+}
++(MySize) returnASize {
+ MySize x = { 32, 44 };
+ return x;
+}
+
+-(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3 {
+ printf("theInt: %d, theFloat: %f, theDouble: %f, thePoint: { %d, %d }\n",
+ arg0, arg1, arg2, arg3.x, arg3.y);
+}
+-(float) returnAFloat {
+ return 10.;
+}
+-(double) returnADouble {
+ return 20.;
+}
+-(MyPoint) returnAPoint {
+ MyPoint x = { 30, 40 };
+ return x;
+}
+-(void) printThisSize: (MySize) arg0 {
+ printf("theSize: { %f, %f }\n",
+ arg0.width, arg0.height);
+}
+-(MySize) returnASize {
+ MySize x = { 22, 34 };
+ return x;
+}
+@end
+
+@implementation B
++(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3 {
+ arg3.x *= 2;
+ arg3.y *= 2;
+ [ super printThisInt: arg0*2 andThatFloat: arg1*2 andADouble: arg2*2 andAPoint: arg3 ];
+}
++(void) printThisSize: (MySize) arg0 {
+ arg0.width *= 2;
+ arg0.height *= 2;
+ [ super printThisSize: arg0 ];
+}
++(float) returnAFloat {
+ return [ super returnAFloat ]*2;
+}
++(double) returnADouble {
+ return [ super returnADouble ]*2;
+}
++(MyPoint) returnAPoint {
+ MyPoint x = [ super returnAPoint ];
+ x.x *= 2;
+ x.y *= 2;
+ return x;
+}
++(MySize) returnASize {
+ MySize x = [ super returnASize ];
+ x.width *= 2;
+ x.height *= 2;
+ return x;
+}
+
+-(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3 {
+ arg3.x *= 2;
+ arg3.y *= 2;
+ [ super printThisInt: arg0*2 andThatFloat: arg1*2 andADouble: arg2*2 andAPoint: arg3 ];
+}
+-(void) printThisSize: (MySize) arg0 {
+ arg0.width *= 2;
+ arg0.height *= 2;
+ [ super printThisSize: arg0 ];
+}
+-(float) returnAFloat {
+ return [ super returnAFloat ]*2;
+}
+-(double) returnADouble {
+ return [ super returnADouble ]*2;
+}
+-(MyPoint) returnAPoint {
+ MyPoint x = [ super returnAPoint ];
+ x.x *= 2;
+ x.y *= 2;
+ return x;
+}
+-(MySize) returnASize {
+ MySize x = [ super returnASize ];
+ x.width *= 2;
+ x.height *= 2;
+ return x;
+}
+@end
diff --git a/test/CodeGenObjC/messages.m b/test/CodeGenObjC/messages.m
new file mode 100644
index 000000000000..f9b9be6e11a3
--- /dev/null
+++ b/test/CodeGenObjC/messages.m
@@ -0,0 +1,27 @@
+// RUN: clang-cc -fnext-runtime --emit-llvm -o %t %s &&
+// RUN: grep "objc_msgSend" %t | count 6 &&
+// RUN: clang-cc -fgnu-runtime --emit-llvm -o %t %s &&
+// RUN: grep "objc_msg_lookup" %t | count 6 &&
+// RUN: clang-cc -fgnu-runtime -fobjc-sender-dependent-dispatch --emit-llvm -o %t %s &&
+// RUN: grep "objc_msg_lookup_sender" %t | count 6
+// RUN: true
+
+typedef struct {
+ int x;
+ int y;
+ int z[10];
+} MyPoint;
+
+void f0(id a) {
+ int i;
+ MyPoint pt = { 1, 2};
+
+ [a print0];
+ [a print1: 10];
+ [a print2: 10 and: "hello" and: 2.2];
+ [a takeStruct: pt ];
+
+ void *s = @selector(print0);
+ for (i=0; i<2; ++i)
+ [a performSelector:s];
+}
diff --git a/test/CodeGenObjC/metadata-symbols-32.m b/test/CodeGenObjC/metadata-symbols-32.m
new file mode 100644
index 000000000000..8cebe4976e23
--- /dev/null
+++ b/test/CodeGenObjC/metadata-symbols-32.m
@@ -0,0 +1,88 @@
+// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm -o %t %s &&
+// RUNX: llvm-gcc -m32 -emit-llvm -S -o %t %s &&
+
+// RUN: grep '@"\\01L_OBJC_CATEGORY_A_Cat" = internal global .*section "__OBJC,__category,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_CATEGORY_CLASS_METHODS_A_Cat" = internal global .*section "__OBJC,__cat_cls_meth,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_CATEGORY_INSTANCE_METHODS_A_Cat" = internal global .*section "__OBJC,__cat_inst_meth,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASSEXT_A" = internal global .*section "__OBJC,__class_ext,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASS_A" = internal global .*section "__OBJC,__class,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASS_METHODS_A" = internal global .*section "__OBJC,__cls_meth,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASS_NAME_[0-9]*" = internal global .*section "__TEXT,__cstring,cstring_literals", align 1' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASS_PROTOCOLS_A" = internal global .*section "__OBJC,__cat_cls_meth,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASS_REFERENCES_[0-9]*" = internal global .*section "__OBJC,__cls_refs,literal_pointers,no_dead_strip", align 4' %t &&
+
+// Clang's Obj-C 32-bit doesn't emit ivars for the root class.
+// RUNX: grep '@"\\01L_OBJC_CLASS_VARIABLES_A" = internal global .*section "__OBJC,__class_vars,regular,no_dead_strip", align 4' %t &&
+
+// RUN: grep '@"\\01L_OBJC_INSTANCE_METHODS_A" = internal global .*section "__OBJC,__inst_meth,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_INSTANCE_VARIABLES_A" = internal global .*section "__OBJC,__instance_vars,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_METACLASS_A" = internal global .*section "__OBJC,__meta_class,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_METH_VAR_NAME_[0-9]*" = internal global .*section "__TEXT,__cstring,cstring_literals", align 1' %t &&
+// RUN: grep '@"\\01L_OBJC_METH_VAR_TYPE_[0-9]*" = internal global .*section "__TEXT,__cstring,cstring_literals", align 1' %t &&
+// RUN: grep '@"\\01L_OBJC_MODULES" = internal global .*section "__OBJC,__module_info,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_PROP_NAME_ATTR_[0-9]*" = internal global .*section "__TEXT,__cstring,cstring_literals", align 1' %t &&
+// RUN: grep '@"\\01L_OBJC_PROTOCOL_CLASS_METHODS_P" = internal global .*section "__OBJC,__cat_cls_meth,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_PROTOCOL_INSTANCE_METHODS_P" = internal global .*section "__OBJC,__cat_inst_meth,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_PROTOCOL_P" = internal global .*section "__OBJC,__protocol,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_SELECTOR_REFERENCES_[0-9]*" = internal global .*section "__OBJC,__message_refs,literal_pointers,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_SYMBOLS" = internal global .*section "__OBJC,__symbols,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01l_OBJC_$_PROP_LIST_A" = internal global .*section "__OBJC,__property,regular,no_dead_strip", align 4' %t &&
+// RUN: grep "\.lazy_reference \.objc_class_name_J0" %t &&
+
+// RUN: true
+
+/*
+
+Here is a handy command for looking at llvm-gcc's output:
+llvm-gcc -m32 -emit-llvm -S -o - metadata-symbols-32.m | \
+ grep '=.*global' | \
+ sed -e 's#global.*, section#global ... section#' | \
+ sort
+
+*/
+
+@interface B
+@end
+@interface C
+@end
+
+@protocol P
++(void) fm0;
+-(void) im0;
+@end
+
+@interface A<P> {
+ int _ivar;
+}
+
+@property (assign) int ivar;
+
++(void) fm0;
+-(void) im0;
+@end
+
+@implementation A
+@synthesize ivar = _ivar;
++(void) fm0 {
+}
+-(void) im0 {
+}
+@end
+
+@implementation A (Cat)
++(void) fm1 {
+}
+-(void) im1 {
+}
+@end
+
+@interface J0
+@end
+
+@implementation J0(Category) @end
+
+void *f0() {
+ [B im0];
+ [C im1];
+}
+
diff --git a/test/CodeGenObjC/metadata-symbols-64.m b/test/CodeGenObjC/metadata-symbols-64.m
new file mode 100644
index 000000000000..bfc4ae9e7546
--- /dev/null
+++ b/test/CodeGenObjC/metadata-symbols-64.m
@@ -0,0 +1,130 @@
+// RUN: clang-cc -triple x86_64-apple-darwin9 -emit-llvm -o %t %s &&
+// RUNX: llvm-gcc -m64 -emit-llvm -S -o %t %s &&
+
+// RUN: grep '@"OBJC_CLASS_$_A" = global' %t &&
+// RUN: grep '@"OBJC_CLASS_$_B" = external global' %t &&
+// RUN: grep '@"OBJC_IVAR_$_A._ivar" = global .* section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"OBJC_METACLASS_$_A" = global .* section "__DATA, __objc_data", align 8' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASSLIST_REFERENCES_$_[0-9]*" = internal global .* section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASSLIST_SUP_REFS_$_[0-9]*" = internal global .* section "__DATA, __objc_superrefs, regular, no_dead_strip", align 8' %t | count 2 &&
+// RUN: grep '@"\\01L_OBJC_CLASS_NAME_[0-9]*" = internal global .* section "__TEXT,__cstring,cstring_literals", align 1' %t &&
+// RUN: grep '@"\\01L_OBJC_LABEL_CATEGORY_$" = internal global .* section "__DATA, __objc_catlist, regular, no_dead_strip", align 8' %t &&
+// RUN: grep '@"\\01L_OBJC_LABEL_CLASS_$" = internal global .* section "__DATA, __objc_classlist, regular, no_dead_strip", align 8' %t &&
+// RUN: grep '@"\\01L_OBJC_METH_VAR_NAME_[0-9]*" = internal global .* section "__TEXT,__cstring,cstring_literals", align 1' %t &&
+// RUN: grep '@"\\01L_OBJC_METH_VAR_TYPE_[0-9]*" = internal global .* section "__TEXT,__cstring,cstring_literals", align 1' %t &&
+// RUN: grep '@"\\01L_OBJC_PROP_NAME_ATTR_[0-9]*" = internal global .* section "__TEXT,__cstring,cstring_literals", align 1' %t &&
+// RUN: grep '@"\\01L_OBJC_SELECTOR_REFERENCES_*" = internal global .* section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"' %t &&
+// RUN: grep '@"\\01l_OBJC_$_CATEGORY_A_$_Cat" = internal global .* section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"\\01l_OBJC_$_CATEGORY_CLASS_METHODS_A_$_Cat" = internal global .* section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"\\01l_OBJC_$_CATEGORY_INSTANCE_METHODS_A_$_Cat" = internal global .* section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"\\01l_OBJC_$_CLASS_METHODS_A" = internal global .* section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"\\01l_OBJC_$_INSTANCE_METHODS_A" = internal global .* section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"\\01l_OBJC_$_INSTANCE_VARIABLES_A" = internal global .* section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"\\01l_OBJC_$_PROP_LIST_A" = internal global .* section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"\\01l_OBJC_$_PROTOCOL_CLASS_METHODS_P" = internal global .* section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"\\01l_OBJC_$_PROTOCOL_INSTANCE_METHODS_P" = internal global .* section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"\\01l_OBJC_CLASS_PROTOCOLS_$_A" = internal global .* section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"\\01l_OBJC_CLASS_RO_$_A" = internal global .* section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"\\01l_OBJC_LABEL_PROTOCOL_$_P" = weak hidden global .* section "__DATA, __objc_protolist, coalesced, no_dead_strip", align 8' %t &&
+// RUN: grep '@"\\01l_OBJC_METACLASS_RO_$_A" = internal global .* section "__DATA, __objc_const", align 8' %t &&
+// RUN: grep '@"\\01l_OBJC_PROTOCOL_$_P" = weak hidden global .* section "__DATA,__datacoal_nt,coalesced", align 8' %t &&
+// RUN: grep '@"\\01l_objc_msgSend_fixup_alloc" = weak hidden global .* section "__DATA, __objc_msgrefs, coalesced", align 16' %t &&
+// RUN: grep '@_objc_empty_cache = external global' %t &&
+// RUN: grep '@_objc_empty_vtable = external global' %t &&
+// RUN: grep '@objc_msgSend_fixup(' %t &&
+// RUN: grep '@objc_msgSend_fpret(' %t &&
+
+// RUN: true
+
+/*
+
+Here is a handy command for looking at llvm-gcc's output:
+llvm-gcc -m64 -emit-llvm -S -o - metadata-symbols-64.m | \
+ grep '=.*global' | \
+ sed -e 's#global.*, section#global ... section#' | \
+ sort
+
+*/
+
+@interface B
+@end
+@interface C
+@end
+
+@protocol P
++(void) fm0;
+-(void) im0;
+@end
+
+@interface A<P> {
+ int _ivar;
+}
+
+@property (assign) int ivar;
+
++(void) fm0;
+-(void) im0;
+@end
+
+@implementation A
+@synthesize ivar = _ivar;
++(void) fm0 {
+}
+-(void) im0 {
+}
+@end
+
+@implementation A (Cat)
++(void) fm1 {
+}
+-(void) im1 {
+}
+@end
+
+@interface D : A
+@end
+
+@implementation D
++(void) fm2 {
+ [super fm1];
+}
+-(void) im2 {
+ [super im1];
+}
+@end
+
+// Test for FP dispatch method APIs
+@interface Example
+@end
+
+float FLOAT;
+double DOUBLE;
+long double LONGDOUBLE;
+id ID;
+
+@implementation Example
+ - (double) RET_DOUBLE
+ {
+ return DOUBLE;
+ }
+ - (float) RET_FLOAT
+ {
+ return FLOAT;
+ }
+ - (long double) RET_LONGDOUBLE
+ {
+ return LONGDOUBLE;
+ }
+@end
+
+void *f0(id x) {
+ Example* pe;
+ double dd = [pe RET_DOUBLE];
+ dd = [pe RET_FLOAT];
+ dd = [pe RET_LONGDOUBLE];
+
+ [B im0];
+ [C im1];
+ [D alloc];
+}
+
diff --git a/test/CodeGenObjC/metadata_symbols.m b/test/CodeGenObjC/metadata_symbols.m
new file mode 100644
index 000000000000..1a1d1e1d9810
--- /dev/null
+++ b/test/CodeGenObjC/metadata_symbols.m
@@ -0,0 +1,61 @@
+// RUN: clang-cc -triple x86_64-apple-darwin9 -emit-llvm -o %t %s &&
+
+// RUN: grep '@"OBJC_METACLASS_$_A" = global .*section "__DATA, __objc_data", align 8' %t &&
+// RUN: grep '@"OBJC_CLASS_$_A" = global .*section "__DATA, __objc_data", align 8' %t &&
+// RUN: grep '@"OBJC_EHTYPE_$_EH1" = weak global .*section "__DATA,__datacoal_nt,coalesced", align 8' %t &&
+// RUN: grep '@"OBJC_EHTYPE_$_EH2" = external global' %t &&
+// RUN: grep '@"OBJC_EHTYPE_$_EH3" = global .*section "__DATA,__objc_const", align 8' %t &&
+// RUN: grep '@"OBJC_EHTYPE_$_EH3"' %t | count 3 &&
+// RUN: grep '@"\\01L_OBJC_CLASS_NAME_" =.*section "__TEXT,__cstring,cstring_literals", align 1' %t | count 1 &&
+// RUN: grep -F 'define internal void @"\01-[A im0]"' %t &&
+// RUN: grep -F 'define internal void @"\01-[A(Cat) im1]"' %t &&
+
+// RUN: clang-cc -fvisibility=hidden -triple x86_64-apple-darwin9 -emit-llvm -o %t %s &&
+
+// RUN: grep '@"OBJC_METACLASS_$_A" = hidden global .*section "__DATA, __objc_data", align 8' %t &&
+// RUN: grep '@"OBJC_CLASS_$_A" = hidden global .*section "__DATA, __objc_data", align 8' %t &&
+// RUN: grep '@"OBJC_EHTYPE_$_EH1" = weak hidden global .*section "__DATA,__datacoal_nt,coalesced"' %t &&
+// RUN: grep '@"OBJC_EHTYPE_$_EH2" = external global' %t &&
+// RUN: grep '@"OBJC_EHTYPE_$_EH3" = hidden global .*section "__DATA,__objc_const", align 8' %t &&
+// RUN: grep -F 'define internal void @"\01-[A im0]"' %t &&
+// RUN: grep -F 'define internal void @"\01-[A(Cat) im1]"' %t &&
+
+// RUN: true
+
+@interface A
+@end
+
+@implementation A
+-(void) im0 {
+}
+@end
+
+@implementation A (Cat)
+-(void) im1 {
+}
+@end
+
+@interface EH1
+@end
+
+__attribute__((__objc_exception__))
+@interface EH2
+@end
+
+__attribute__((__objc_exception__))
+@interface EH3
+@end
+
+void f1();
+
+void f0(id x) {
+ @try {
+ f1();
+ } @catch (EH1 *x) {
+ } @catch (EH2 *x) {
+ } @catch (EH3 *x) {
+ }
+}
+
+@implementation EH3
+@end
diff --git a/test/CodeGenObjC/newproperty-nested-synthesis-1.m b/test/CodeGenObjC/newproperty-nested-synthesis-1.m
new file mode 100644
index 000000000000..5196b8244dbb
--- /dev/null
+++ b/test/CodeGenObjC/newproperty-nested-synthesis-1.m
@@ -0,0 +1,78 @@
+// RUN: clang-cc -fnext-runtime --emit-llvm -o %t %s
+
+@interface Object
+- (id) new;
+@end
+
+@interface Tester : Object
+@property char PropertyAtomic_char;
+@property short PropertyAtomic_short;
+@property int PropertyAtomic_int;
+@property long PropertyAtomic_long;
+@property long long PropertyAtomic_longlong;
+@property float PropertyAtomic_float;
+@property double PropertyAtomic_double;
+@property(assign) id PropertyAtomic_id;
+@property(retain) id PropertyAtomicRetained_id;
+@property(copy) id PropertyAtomicRetainedCopied_id;
+@property(retain) id PropertyAtomicRetainedGCOnly_id;
+@property(copy) id PropertyAtomicRetainedCopiedGCOnly_id;
+@end
+
+@implementation Tester
+@dynamic PropertyAtomic_char;
+@dynamic PropertyAtomic_short;
+@dynamic PropertyAtomic_int;
+@dynamic PropertyAtomic_long;
+@dynamic PropertyAtomic_longlong;
+@dynamic PropertyAtomic_float;
+@dynamic PropertyAtomic_double;
+@dynamic PropertyAtomic_id;
+@dynamic PropertyAtomicRetained_id;
+@dynamic PropertyAtomicRetainedCopied_id;
+@dynamic PropertyAtomicRetainedGCOnly_id;
+@dynamic PropertyAtomicRetainedCopiedGCOnly_id;
+@end
+
+@interface SubClass : Tester
+{
+ char PropertyAtomic_char;
+ short PropertyAtomic_short;
+ int PropertyAtomic_int;
+ long PropertyAtomic_long;
+ long long PropertyAtomic_longlong;
+ float PropertyAtomic_float;
+ double PropertyAtomic_double;
+ id PropertyAtomic_id;
+ id PropertyAtomicRetained_id;
+ id PropertyAtomicRetainedCopied_id;
+ id PropertyAtomicRetainedGCOnly_id;
+ id PropertyAtomicRetainedCopiedGCOnly_id;
+}
+@end
+
+@implementation SubClass
+@synthesize PropertyAtomic_char;
+@synthesize PropertyAtomic_short;
+@synthesize PropertyAtomic_int;
+@synthesize PropertyAtomic_long;
+@synthesize PropertyAtomic_longlong;
+@synthesize PropertyAtomic_float;
+@synthesize PropertyAtomic_double;
+@synthesize PropertyAtomic_id;
+@synthesize PropertyAtomicRetained_id;
+@synthesize PropertyAtomicRetainedCopied_id;
+@synthesize PropertyAtomicRetainedGCOnly_id;
+@synthesize PropertyAtomicRetainedCopiedGCOnly_id;
+@end
+
+int main()
+{
+ SubClass *f = [SubClass new];
+ f.PropertyAtomic_int = 1;
+
+ f.PropertyAtomic_int += 3;
+
+ f.PropertyAtomic_int -= 4;
+ return f.PropertyAtomic_int;
+}
diff --git a/test/CodeGenObjC/no-category-class.m b/test/CodeGenObjC/no-category-class.m
new file mode 100644
index 000000000000..34bf603da57d
--- /dev/null
+++ b/test/CodeGenObjC/no-category-class.m
@@ -0,0 +1,8 @@
+// RUN: clang-cc -triple x86_64-unknown-unknown -emit-llvm -o %t %s
+
+@interface NSObject
+@end
+
+@implementation NSObject(IBXLIFFIntegration)
+@end
+
diff --git a/test/CodeGenObjC/non-lazy-classes.m b/test/CodeGenObjC/non-lazy-classes.m
new file mode 100644
index 000000000000..079cc40886f9
--- /dev/null
+++ b/test/CodeGenObjC/non-lazy-classes.m
@@ -0,0 +1,33 @@
+// RUNX: llvm-gcc -m64 -emit-llvm -S -o %t %s &&
+// RUN: clang-cc -triple x86_64-apple-darwin10 -emit-llvm -o %t %s &&
+// RUN: grep '@".01L_OBJC_LABEL_NONLAZY_CLASS_$" = internal global \[1 x .*\] .*@"OBJC_CLASS_$_A".*, section "__DATA, __objc_nlclslist, regular, no_dead_strip", align 8' %t &&
+// RUN: grep '@".01L_OBJC_LABEL_NONLAZY_CATEGORY_$" = internal global \[1 x .*\] .*@".01l_OBJC_$_CATEGORY_A_$_Cat".*, section "__DATA, __objc_nlcatlist, regular, no_dead_strip", align 8' %t &&
+// RUN: true
+
+@interface A @end
+@implementation A
++(void) load {
+}
+@end
+
+@interface A (Cat) @end
+@implementation A (Cat)
++(void) load {
+}
+@end
+
+@interface B @end
+@implementation B
+-(void) load {
+}
+@end
+
+@interface B (Cat) @end
+@implementation B (Cat)
+-(void) load {
+}
+@end
+
+@interface C : A @end
+@implementation C
+@end
diff --git a/test/CodeGenObjC/objc-align.m b/test/CodeGenObjC/objc-align.m
new file mode 100644
index 000000000000..eca5959a392a
--- /dev/null
+++ b/test/CodeGenObjC/objc-align.m
@@ -0,0 +1,47 @@
+// 32-bit
+
+// RUNX: llvm-gcc -m32 -emit-llvm -S -o %t %s &&
+// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm -o %t %s &&
+// RUN: grep '@"\\01L_OBJC_CATEGORY_A_Cat" = internal global .*, section "__OBJC,__category,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASS_A" = internal global .*, section "__OBJC,__class,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASS_C" = internal global .*, section "__OBJC,__class,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASS_PROTOCOLS_C" = internal global .*, section "__OBJC,__cat_cls_meth,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_IMAGE_INFO" = internal constant .*, section "__OBJC, __image_info,regular"' %t &&
+// RUN: grep '@"\\01L_OBJC_METACLASS_A" = internal global .*, section "__OBJC,__meta_class,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_METACLASS_C" = internal global .*, section "__OBJC,__meta_class,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_MODULES" = internal global .*, section "__OBJC,__module_info,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_PROTOCOL_P" = internal global .*, section "__OBJC,__protocol,regular,no_dead_strip", align 4' %t &&
+
+// 64-bit
+
+// RUNX: clang-cc -triple i386-apple-darwin9 -emit-llvm -o %t %s &&
+// RUNX: grep '@"OBJC_CLASS_$_A" = global' %t &&
+// RUNX: grep '@"OBJC_CLASS_$_C" = global' %t &&
+// RUNX: grep '@"OBJC_METACLASS_$_A" = global' %t &&
+// RUNX: grep '@"OBJC_METACLASS_$_C" = global' %t &&
+// RUNX: grep '@"\\01L_OBJC_CLASSLIST_REFERENCES_$_0" = internal global .*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8' %t &&
+// RUNX: grep '@"\\01L_OBJC_IMAGE_INFO" = internal constant .*, section "__DATA, __objc_imageinfo, regular, no_dead_strip"' %t &&
+// RUNX: grep '@"\\01L_OBJC_LABEL_CATEGORY_$" = internal global .*, section "__DATA, __objc_catlist, regular, no_dead_strip", align 8' %t &&
+// RUNX: grep '@"\\01L_OBJC_LABEL_CLASS_$" = internal global .*, section "__DATA, __objc_classlist, regular, no_dead_strip", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_$_CATEGORY_A_$_Cat" = internal global .*, section "__DATA, __objc_const", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_CLASS_PROTOCOLS_$_C" = internal global .*, section "__DATA, __objc_const", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_CLASS_RO_$_A" = internal global .*, section "__DATA, __objc_const", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_CLASS_RO_$_C" = internal global .*, section "__DATA, __objc_const", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_LABEL_PROTOCOL_$_P" = weak hidden global .*, section "__DATA, __objc_protolist, coalesced, no_dead_strip", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_METACLASS_RO_$_A" = internal global .*, section "__DATA, __objc_const", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_METACLASS_RO_$_C" = internal global .*, section "__DATA, __objc_const", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_PROTOCOL_$_P" = weak hidden global .*, section "__DATA,__datacoal_nt,coalesced", align 8' %t &&
+
+// RUN: true
+
+@interface A @end
+@implementation A
+@end
+@implementation A (Cat)
+@end
+@protocol P
+@end
+@interface C <P>
+@end
+@implementation C
+@end
diff --git a/test/CodeGenObjC/objc2-assign-global.m b/test/CodeGenObjC/objc2-assign-global.m
new file mode 100644
index 000000000000..ae407619093e
--- /dev/null
+++ b/test/CodeGenObjC/objc2-assign-global.m
@@ -0,0 +1,8 @@
+// RUN: clang-cc -fnext-runtime -fobjc-gc -emit-llvm -o %t %s &&
+// RUN: grep -F '@objc_assign_global' %t | count 2 &&
+// RUN: true
+id a;
+int main() {
+ a = 0;
+}
+
diff --git a/test/CodeGenObjC/objc2-no-strong-cast.m b/test/CodeGenObjC/objc2-no-strong-cast.m
new file mode 100644
index 000000000000..bce50cd4544c
--- /dev/null
+++ b/test/CodeGenObjC/objc2-no-strong-cast.m
@@ -0,0 +1,22 @@
+// RUN: clang-cc -emit-llvm -o %t %s
+
+@interface PDFViewPrivateVars
+{
+@public
+ __attribute__((objc_gc(strong))) char *addedTooltips;
+}
+@end
+
+@interface PDFView
+{
+ PDFViewPrivateVars *_pdfPriv;
+}
+@end
+
+@implementation PDFView
+- (void) addTooltipsForPage
+{
+ _pdfPriv->addedTooltips[4] = 1;
+}
+@end
+
diff --git a/test/CodeGenObjC/objc2-no-write-barrier.m b/test/CodeGenObjC/objc2-no-write-barrier.m
new file mode 100644
index 000000000000..2c5350969416
--- /dev/null
+++ b/test/CodeGenObjC/objc2-no-write-barrier.m
@@ -0,0 +1,18 @@
+// RUN: clang-cc -triple x86_64-apple-darwin9 -fobjc-gc -emit-llvm -o %t %s &&
+// RUN: grep 'objc_assign' %t | count 0
+
+typedef struct {
+ int ival;
+ id submenu;
+} XCBinderContextMenuItem;
+
+id actionMenuForDataNode(void) {
+ XCBinderContextMenuItem menusToCreate[] = {
+ {1, 0}
+ };
+ return 0;
+}
+
+XCBinderContextMenuItem GmenusToCreate[] = {
+ {1, 0}
+};
diff --git a/test/CodeGenObjC/objc2-property-encode.m b/test/CodeGenObjC/objc2-property-encode.m
new file mode 100644
index 000000000000..2bff2fc1a4ed
--- /dev/null
+++ b/test/CodeGenObjC/objc2-property-encode.m
@@ -0,0 +1,13 @@
+// RUN: clang-cc -triple=i686-apple-darwin9 -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: grep -e "T@\\\\22NSString\\\\22" %t
+@interface NSString @end
+
+typedef NSString StoreVersionID ;
+
+@interface Parent
+ @property(retain) StoreVersionID* foo;
+@end
+
+@implementation Parent
+@dynamic foo;
+@end
diff --git a/test/CodeGenObjC/objc2-protocol-enc.m b/test/CodeGenObjC/objc2-protocol-enc.m
new file mode 100644
index 000000000000..559b0b8c76a0
--- /dev/null
+++ b/test/CodeGenObjC/objc2-protocol-enc.m
@@ -0,0 +1,43 @@
+// RUN: clang-cc -triple=i686-apple-darwin9 -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: grep -e "T@\\\22<X>\\\22" %t &&
+// RUN: grep -e "T@\\\22<X><Y>\\\22" %t &&
+// RUN: grep -e "T@\\\22<X><Y><Z>\\\22" %t &&
+// RUN: grep -e "T@\\\22Foo<X><Y><Z>\\\22" %t
+
+@protocol X, Y, Z;
+@class Foo;
+
+@protocol Proto
+@property (copy) id <X> x;
+@property (copy) id <X, Y> xy;
+@property (copy) id <X, Y, Z> xyz;
+@property(copy) Foo <X, Y, Z> *fooxyz;
+@end
+
+@interface Intf <Proto>
+{
+id <X> IVAR_x;
+id <X, Y> IVAR_xy;
+id <X, Y, Z> IVAR_xyz;
+Foo <X, Y, Z> *IVAR_Fooxyz;
+}
+@end
+
+@implementation Intf
+@dynamic x, xy, xyz, fooxyz;
+@end
+
+/**
+This protocol should generate the following metadata:
+struct objc_property_list __Protocol_Test_metadata = {
+ sizeof(struct objc_property), 4,
+ {
+ { "x", "T@\"<X>\"" },
+ { "xy", "T@\"<X><Y>\"" },
+ { "xyz", "T@\"<X><Y><Z>\"" },
+ { "fooxyz", "T@\"Foo<X><Y><Z>\"" }
+ }
+};
+
+"T@\"<X><Y><Z>\",D
+*/
diff --git a/test/CodeGenObjC/objc2-retain-codegen.m b/test/CodeGenObjC/objc2-retain-codegen.m
new file mode 100644
index 000000000000..d78bc366d398
--- /dev/null
+++ b/test/CodeGenObjC/objc2-retain-codegen.m
@@ -0,0 +1,12 @@
+// RUN: clang-cc -triple x86_64-unknown-unknown -fobjc-gc-only -emit-llvm -o %t %s
+
+@interface I0 {
+ I0 *_f0;
+}
+@property (retain) id p0;
+@end
+
+@implementation I0
+ @synthesize p0 = _f0;
+@end
+
diff --git a/test/CodeGenObjC/objc2-strong-cast-1.m b/test/CodeGenObjC/objc2-strong-cast-1.m
new file mode 100644
index 000000000000..8cad08c88a60
--- /dev/null
+++ b/test/CodeGenObjC/objc2-strong-cast-1.m
@@ -0,0 +1,23 @@
+// RUN: clang-cc -triple x86_64-unknown-unknown -fobjc-gc -emit-llvm -o %t %s
+
+@interface I {
+ __attribute__((objc_gc(strong))) int *i_IdocumentIDs;
+ __attribute__((objc_gc(strong))) long *l_IdocumentIDs;
+ __attribute__((objc_gc(strong))) long long *ll_IdocumentIDs;
+ __attribute__((objc_gc(strong))) float *IdocumentIDs;
+ __attribute__((objc_gc(strong))) double *d_IdocumentIDs;
+}
+- (void) _getResultsOfMatches;
+@end
+
+@implementation I
+-(void) _getResultsOfMatches {
+ IdocumentIDs[2] = IdocumentIDs[3];
+ d_IdocumentIDs[2] = d_IdocumentIDs[3];
+ l_IdocumentIDs[2] = l_IdocumentIDs[3];
+ ll_IdocumentIDs[2] = ll_IdocumentIDs[3];
+ i_IdocumentIDs[2] = i_IdocumentIDs[3];
+}
+
+@end
+
diff --git a/test/CodeGenObjC/objc2-strong-cast-2.m b/test/CodeGenObjC/objc2-strong-cast-2.m
new file mode 100644
index 000000000000..b617c9fee4ea
--- /dev/null
+++ b/test/CodeGenObjC/objc2-strong-cast-2.m
@@ -0,0 +1,27 @@
+// RUN: clang-cc -triple x86_64-darwin-10 -fobjc-gc -emit-llvm -o %t %s &&
+// RUN: grep objc_assign_strongCast %t | count 4 &&
+// RUN: true
+
+@interface A
+@end
+
+typedef struct s0 {
+ A *a[4];
+} T;
+
+T g0;
+
+void f0(id x) {
+ g0.a[0] = x;
+}
+
+void f1(id x) {
+ ((T*) &g0)->a[0] = x;
+}
+
+void f2(unsigned idx)
+{
+ id *keys;
+ keys[idx] = 0;
+}
+
diff --git a/test/CodeGenObjC/objc2-strong-cast.m b/test/CodeGenObjC/objc2-strong-cast.m
new file mode 100644
index 000000000000..d0fcb6ced928
--- /dev/null
+++ b/test/CodeGenObjC/objc2-strong-cast.m
@@ -0,0 +1,17 @@
+// RUN: clang-cc -fnext-runtime -fobjc-gc -emit-llvm -o %t %s
+
+@interface I {
+ __attribute__((objc_gc(strong))) signed long *_documentIDs;
+ __attribute__((objc_gc(strong))) id *IdocumentIDs;
+}
+- (void) _getResultsOfMatches;
+@end
+
+@implementation I
+-(void) _getResultsOfMatches {
+ _documentIDs[2] = _documentIDs[3];
+ IdocumentIDs[2] = IdocumentIDs[3];
+}
+
+@end
+
diff --git a/test/CodeGenObjC/objc2-weak-compare.m b/test/CodeGenObjC/objc2-weak-compare.m
new file mode 100644
index 000000000000..be769899a17d
--- /dev/null
+++ b/test/CodeGenObjC/objc2-weak-compare.m
@@ -0,0 +1,24 @@
+// RUN: clang-cc -triple i386-apple-darwin9 -fnext-runtime -fobjc-gc -emit-llvm -o %t %s
+
+@interface PBXTarget
+{
+
+PBXTarget * __weak _lastKnownTarget;
+PBXTarget * __weak _KnownTarget;
+PBXTarget * result;
+}
+- Meth;
+@end
+
+@implementation PBXTarget
+- Meth {
+ if (_lastKnownTarget != result)
+ foo();
+ if (result != _lastKnownTarget)
+ foo();
+
+ if (_lastKnownTarget != _KnownTarget)
+ foo();
+}
+
+@end
diff --git a/test/CodeGenObjC/objc2-weak-ivar.m b/test/CodeGenObjC/objc2-weak-ivar.m
new file mode 100644
index 000000000000..592c1f05474b
--- /dev/null
+++ b/test/CodeGenObjC/objc2-weak-ivar.m
@@ -0,0 +1,10 @@
+// RUN: clang-cc -triple x86_64-apple-darwin9 -fobjc-gc -emit-llvm -o %t %s
+@class NSObject;
+
+@interface Foo {
+@public
+ __weak NSObject *nsobject;
+}
+@end
+
+@implementation Foo @end
diff --git a/test/CodeGenObjC/overloadable.m b/test/CodeGenObjC/overloadable.m
new file mode 100644
index 000000000000..972dc4ed5895
--- /dev/null
+++ b/test/CodeGenObjC/overloadable.m
@@ -0,0 +1,10 @@
+// rdar://6657613
+// RUN: clang-cc -emit-llvm %s -o %t &&
+
+@class C;
+
+// RUN: grep _Z1fP11objc_object %t | count 1 &&
+void __attribute__((overloadable)) f(C *c) { }
+
+// RUN: grep _Z1fP1C %t | count 1
+void __attribute__((overloadable)) f(id c) { }
diff --git a/test/CodeGenObjC/predefined-expr-in-method.m b/test/CodeGenObjC/predefined-expr-in-method.m
new file mode 100644
index 000000000000..812ef97252dc
--- /dev/null
+++ b/test/CodeGenObjC/predefined-expr-in-method.m
@@ -0,0 +1,17 @@
+// RUN: clang-cc -fnext-runtime --emit-llvm -o %t %s
+
+@interface A
+@end
+@implementation A
++(void) foo {
+ printf("__func__: %s\n", __func__);
+ printf("__FUNCTION__: %s\n", __FUNCTION__);
+ printf("__PRETTY_FUNCTION__: %s\n", __PRETTY_FUNCTION__);
+ return 0;
+}
+@end
+
+int main() {
+ [A foo];
+ return 0;
+}
diff --git a/test/CodeGenObjC/property-aggr-type.m b/test/CodeGenObjC/property-aggr-type.m
new file mode 100644
index 000000000000..0cb7a5e2f40a
--- /dev/null
+++ b/test/CodeGenObjC/property-aggr-type.m
@@ -0,0 +1,50 @@
+// RUN: clang-cc -fnext-runtime -emit-llvm -o %t %s
+
+@interface Object
+- (id) new;
+@end
+
+typedef struct {int x, y, w, h;} st1;
+typedef struct {int x, y, w, h;} st2;
+
+@interface bar : Object
+- (void)setFrame:(st1)frameRect;
+@end
+
+@interface bar1 : Object
+- (void)setFrame:(int)frameRect;
+@end
+
+@interface foo : Object
+{
+ st2 ivar;
+}
+@property (assign) st2 frame;
+@end
+
+@implementation foo
+@synthesize frame = ivar;
+@end
+
+extern void abort();
+
+static st2 r = {1,2,3,4};
+st2 test (void)
+{
+ foo *obj = [foo new];
+ id objid = [foo new];;
+
+ obj.frame = r;
+
+ ((foo*)objid).frame = obj.frame;
+
+ return ((foo*)objid).frame;
+}
+
+int main ()
+{
+ st2 res = test ();
+ if (res.x != 1 || res.h != 4)
+ abort();
+ return 0;
+}
diff --git a/test/CodeGenObjC/property-agrr-getter.m b/test/CodeGenObjC/property-agrr-getter.m
new file mode 100644
index 000000000000..0a1df123bffe
--- /dev/null
+++ b/test/CodeGenObjC/property-agrr-getter.m
@@ -0,0 +1,17 @@
+// RUN: clang-cc -fnext-runtime -emit-llvm -o %t %s
+
+typedef struct {
+ unsigned f0;
+} s0;
+
+@interface A
+- (s0) f0;
+@end
+
+@implementation A
+-(s0) f0{}
+- (unsigned) bar {
+ return self.f0.f0;
+}
+@end
+
diff --git a/test/CodeGenObjC/property-getter-dot-syntax.m b/test/CodeGenObjC/property-getter-dot-syntax.m
new file mode 100644
index 000000000000..d98e9bab6da9
--- /dev/null
+++ b/test/CodeGenObjC/property-getter-dot-syntax.m
@@ -0,0 +1,11 @@
+// RUN: clang-cc -fnext-runtime --emit-llvm -o %t %s
+
+@protocol NSObject
+- (void *)description;
+@end
+
+int main()
+{
+ id<NSObject> eggs;
+ void *eggsText= eggs.description;
+}
diff --git a/test/CodeGenObjC/property-incr-decr-1.m b/test/CodeGenObjC/property-incr-decr-1.m
new file mode 100644
index 000000000000..772e872a214f
--- /dev/null
+++ b/test/CodeGenObjC/property-incr-decr-1.m
@@ -0,0 +1,29 @@
+// RUN: clang-cc -fnext-runtime -emit-llvm -o %t %s
+
+@interface Object
+- (id) new;
+@end
+
+@interface SomeClass : Object
+{
+ int _myValue;
+}
+@property int myValue;
+@end
+
+@implementation SomeClass
+@synthesize myValue=_myValue;
+@end
+
+int main()
+{
+ int val;
+ SomeClass *o = [SomeClass new];
+ o.myValue = -1;
+ val = o.myValue++; /* val -1, o.myValue 0 */
+ val += o.myValue--; /* val -1. o.myValue -1 */
+ val += ++o.myValue; /* val -1, o.myValue 0 */
+ val += --o.myValue; /* val -2, o.myValue -1 */
+ return ++o.myValue + (val+2);
+}
+
diff --git a/test/CodeGenObjC/property-setter-attr.m b/test/CodeGenObjC/property-setter-attr.m
new file mode 100644
index 000000000000..390392415d73
--- /dev/null
+++ b/test/CodeGenObjC/property-setter-attr.m
@@ -0,0 +1,10 @@
+// RUN: clang-cc -emit-llvm -triple=i686-apple-darwin8 -o %t %s
+// RUN: grep -e "SiSetOtherThings:" %t
+
+@interface A
+@property(setter=iSetOtherThings:) int otherThings;
+@end
+
+@implementation A
+@dynamic otherThings;
+@end
diff --git a/test/CodeGenObjC/property.m b/test/CodeGenObjC/property.m
new file mode 100644
index 000000000000..264adf1106e2
--- /dev/null
+++ b/test/CodeGenObjC/property.m
@@ -0,0 +1,52 @@
+// RUN: clang-cc -fnext-runtime --emit-llvm -o %t %s
+
+#include <stdio.h>
+
+@interface Root
+-(id) alloc;
+-(id) init;
+@end
+
+@interface A : Root {
+ int x;
+ int y, ro, z;
+ id ob0, ob1, ob2, ob3, ob4;
+}
+@property int x;
+@property int y;
+@property int z;
+@property(readonly) int ro;
+@property(assign) id ob0;
+@property(retain) id ob1;
+@property(copy) id ob2;
+@property(retain, nonatomic) id ob3;
+@property(copy, nonatomic) id ob4;
+@end
+
+@implementation A
+@dynamic x;
+@synthesize y;
+@synthesize z = z;
+@synthesize ro;
+@synthesize ob0;
+@synthesize ob1;
+@synthesize ob2;
+@synthesize ob3;
+@synthesize ob4;
+-(int) y {
+ return x + 1;
+}
+-(void) setZ: (int) arg {
+ x = arg - 1;
+}
+@end
+
+@interface A (Cat)
+@property int dyn;
+@end
+
+@implementation A (Cat)
+-(int) dyn {
+ return 10;
+}
+@end
diff --git a/test/CodeGenObjC/protocol-definition-hidden-visibility.m b/test/CodeGenObjC/protocol-definition-hidden-visibility.m
new file mode 100644
index 000000000000..31a864b22d55
--- /dev/null
+++ b/test/CodeGenObjC/protocol-definition-hidden-visibility.m
@@ -0,0 +1,19 @@
+// RUN: clang-cc -triple x86_64-apple-darwin10 -S -o - %s | grep -e "private_extern l_OBJC_PROTOCOL_" | count 2
+
+@interface FOO @end
+
+@interface NSObject @end
+
+@protocol SSHIPCProtocolHandler_BDC;
+
+typedef NSObject<SSHIPCProtocolHandler_BDC> _SSHIPCProtocolHandler_BDC;
+
+@interface SSHIPC_v2_RPFSProxy
+@property(nonatomic,readonly,retain) _SSHIPCProtocolHandler_BDC* protocolHandler_BDC;
+@end
+
+@implementation FOO
+- (_SSHIPCProtocolHandler_BDC*) protocolHandler_BDC {@protocol(SSHIPCProtocolHandler_BDC); }
+@end
+
+
diff --git a/test/CodeGenObjC/protocol-property-synth.m b/test/CodeGenObjC/protocol-property-synth.m
new file mode 100644
index 000000000000..e91f3552310d
--- /dev/null
+++ b/test/CodeGenObjC/protocol-property-synth.m
@@ -0,0 +1,33 @@
+// RUN: clang-cc -triple x86_64-apple-darwin10 -emit-llvm -o %t %s
+
+@interface BaseClass {
+ id _delegate;
+}
+@end
+
+@protocol MyProtocol
+@optional
+@property(assign) id delegate;
+@end
+
+@protocol AnotherProtocol
+@optional
+@property(assign) id myanother;
+@end
+
+@protocol SubProtocol <MyProtocol>
+@property(assign) id another;
+@end
+
+@interface SubClass : BaseClass <SubProtocol, AnotherProtocol> {
+}
+
+@end
+
+@implementation BaseClass @end
+
+@implementation SubClass
+@synthesize delegate = _Subdelegate;
+@synthesize another;
+@synthesize myanother;
+@end
diff --git a/test/CodeGenObjC/protocols-lazy.m b/test/CodeGenObjC/protocols-lazy.m
new file mode 100644
index 000000000000..e91cc0aea836
--- /dev/null
+++ b/test/CodeGenObjC/protocols-lazy.m
@@ -0,0 +1,48 @@
+// RUN: clang-cc -emit-llvm -triple=i686-apple-darwin8 -o %t %s &&
+// RUNX: llvm-gcc -S -emit-llvm -o %t %s &&
+
+// No object generated
+// RUN: grep OBJC_PROTOCOL_P0 %t | count 0 &&
+@protocol P0;
+
+// No object generated
+// RUN: grep OBJC_PROTOCOL_P1 %t | count 0 &&
+@protocol P1 -im1; @end
+
+// Definition triggered by protocol reference.
+// RUN: grep OBJC_PROTOCOL_P2 %t | count 3 &&
+// RUN: grep OBJC_PROTOCOL_INSTANCE_METHODS_P2 %t | count 3 &&
+@protocol P2 -im1; @end
+void f0() { id x = @protocol(P2); }
+
+// Forward definition triggered by protocol reference.
+// RUN: grep OBJC_PROTOCOL_P3 %t | count 3 &&
+// RUN: grep OBJC_PROTOCOL_INSTANCE_METHODS_P3 %t | count 0 &&
+@protocol P3;
+void f1() { id x = @protocol(P3); }
+
+// Definition triggered by class reference.
+// RUN: grep OBJC_PROTOCOL_P4 %t | count 3 &&
+// RUN: grep OBJC_PROTOCOL_INSTANCE_METHODS_P4 %t | count 3 &&
+@protocol P4 -im1; @end
+@interface I0<P4> @end
+@implementation I0 -im1 {}; @end
+
+// Definition following forward reference.
+// RUN: grep OBJC_PROTOCOL_P5 %t | count 3 &&
+// RUN: grep OBJC_PROTOCOL_INSTANCE_METHODS_P5 %t | count 3 &&
+@protocol P5;
+void f2() { id x = @protocol(P5); } // This generates a forward
+ // reference, which has to be
+ // updated on the next line.
+@protocol P5 -im1; @end
+
+// Protocol reference following definition.
+// RUN: grep OBJC_PROTOCOL_P6 %t | count 4 &&
+// RUN: grep OBJC_PROTOCOL_INSTANCE_METHODS_P6 %t | count 3 &&
+@protocol P6 -im1; @end
+@interface I1<P6> @end
+@implementation I1 -im1 {}; @end
+void f3() { id x = @protocol(P6); }
+
+// RUN: true
diff --git a/test/CodeGenObjC/runtime-fns.m b/test/CodeGenObjC/runtime-fns.m
new file mode 100644
index 000000000000..0d8570799902
--- /dev/null
+++ b/test/CodeGenObjC/runtime-fns.m
@@ -0,0 +1,33 @@
+// RUN: clang-cc -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: grep -e "^de.*objc_msgSend[0-9]*(" %t | count 1 &&
+// RUN: clang-cc -DWITHDEF -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: grep -e "^de.*objc_msgSend[0-9]*(" %t | count 1
+
+id objc_msgSend(int x);
+
+@interface A @end
+
+@implementation A
+-(void) f0 {
+ objc_msgSend(12);
+}
+
+-(void) hello {
+}
+@end
+
+void f0(id x) {
+ [x hello];
+}
+
+#ifdef WITHDEF
+// This isn't a very good send function.
+id objc_msgSend(int x) {
+ return 0;
+}
+
+// rdar://6800430
+void objc_assign_weak(id value, id *location) {
+}
+
+#endif
diff --git a/test/CodeGenObjC/super-classmethod-category.m b/test/CodeGenObjC/super-classmethod-category.m
new file mode 100644
index 000000000000..27cdbf6aed41
--- /dev/null
+++ b/test/CodeGenObjC/super-classmethod-category.m
@@ -0,0 +1,13 @@
+// RUN: clang-cc -fnext-runtime -emit-llvm -o %t %s
+
+@interface SUPER
++ (void)Meth;
+@end
+
+@interface CURRENT : SUPER
++ (void)Meth;
+@end
+
+@implementation CURRENT(CAT)
++ (void)Meth { [super Meth]; }
+@end
diff --git a/test/CodeGenObjC/super-dotsyntax-property.m b/test/CodeGenObjC/super-dotsyntax-property.m
new file mode 100644
index 000000000000..6e4f176724c8
--- /dev/null
+++ b/test/CodeGenObjC/super-dotsyntax-property.m
@@ -0,0 +1,41 @@
+// RUN: clang-cc -emit-llvm -o %t %s
+
+@interface B
+{
+ int _parent;
+}
+@property int parent;
+ +(int) classGetter;
+ +(void) setClassGetter:(int) arg;
+
+ -(int) getter;
+ -(void) setGetter:(int)arg;
+@end
+
+@interface A : B
+@end
+
+@implementation A
++(int) classGetter {
+ return 0;
+}
+
++(int) classGetter2 {
+ super.classGetter = 100;
+ return super.classGetter;
+}
+
+-(void) method {
+ super.getter = 200;
+ int x = super.getter;
+}
+-(void) setParent : (int) arg {
+ super.parent = arg + super.parent;
+
+}
+@end
+
+void f0() {
+ int l1 = A.classGetter;
+ int l2 = [A classGetter2];
+}
diff --git a/test/CodeGenObjC/synchronized.m b/test/CodeGenObjC/synchronized.m
new file mode 100644
index 000000000000..b398ca6c0a59
--- /dev/null
+++ b/test/CodeGenObjC/synchronized.m
@@ -0,0 +1,41 @@
+// RUN: clang-cc -emit-llvm -triple=i686-apple-darwin9 -o %t %s -O2 &&
+// RUN: grep 'ret i32' %t | count 1 &&
+// RUN: grep 'ret i32 1' %t | count 1
+
+@interface MyClass
+{
+}
+- (void)method;
+@end
+
+@implementation MyClass
+
+- (void)method
+{
+ @synchronized(self)
+ {
+ }
+}
+
+@end
+
+void foo(id a) {
+ @synchronized(a) {
+ return;
+ }
+}
+
+int f0(id a) {
+ int x = 0;
+ @synchronized((x++, a)) {
+ }
+ return x; // ret i32 1
+}
+
+void f1(id a) {
+ // The trick here is that the return shouldn't go through clean up,
+ // but there isn't a simple way to check this property.
+ @synchronized(({ return; }), a) {
+ return;
+ }
+}
diff --git a/test/CodeGenObjC/synthesize_ivar-cont-class.m b/test/CodeGenObjC/synthesize_ivar-cont-class.m
new file mode 100644
index 000000000000..b1a7d0e68030
--- /dev/null
+++ b/test/CodeGenObjC/synthesize_ivar-cont-class.m
@@ -0,0 +1,18 @@
+// RUN: clang-cc -triple x86_64-apple-darwin10 -emit-llvm -o %t %s &&
+// RUN: grep '@"OBJC_IVAR_$_XCOrganizerDeviceNodeInfo.viewController"' %t
+
+@interface XCOrganizerNodeInfo
+@property (readonly, retain) id viewController;
+@end
+
+@interface XCOrganizerDeviceNodeInfo : XCOrganizerNodeInfo
+@end
+
+@interface XCOrganizerDeviceNodeInfo()
+@property (retain) id viewController;
+@end
+
+@implementation XCOrganizerDeviceNodeInfo
+@synthesize viewController;
+@end
+
diff --git a/test/CodeGenObjC/synthesize_ivar.m b/test/CodeGenObjC/synthesize_ivar.m
new file mode 100644
index 000000000000..7646f707bf76
--- /dev/null
+++ b/test/CodeGenObjC/synthesize_ivar.m
@@ -0,0 +1,27 @@
+// RUN: clang-cc -triple x86_64-apple-darwin10 -emit-llvm -o %t %s
+
+@interface I
+{
+}
+@property int IP;
+@end
+
+@implementation I
+@synthesize IP;
+- (int) Meth {
+ return IP;
+}
+@end
+
+// Test for synthesis of ivar for a property
+// declared in continuation class.
+@interface OrganizerViolatorView
+@end
+
+@interface OrganizerViolatorView()
+@property (retain) id bindingInfo;
+@end
+
+@implementation OrganizerViolatorView
+@synthesize bindingInfo;
+@end
diff --git a/test/CodeGenObjC/try.m b/test/CodeGenObjC/try.m
new file mode 100644
index 000000000000..7701b23e0819
--- /dev/null
+++ b/test/CodeGenObjC/try.m
@@ -0,0 +1,9 @@
+// RUN: clang-cc %s -S -o - -triple=i686-apple-darwin9 &&
+// RUN: clang-cc %s -S -o - -triple=x86_64-apple-darwin9
+
+// rdar://6757213 - Don't crash if the internal proto for
+// __objc_personality_v0 mismatches with an actual one.
+void __objc_personality_v0() { }
+void test1(void) {
+ @try { } @catch (...) { }
+}
diff --git a/test/CodeGenObjC/unname-bf-metadata.m b/test/CodeGenObjC/unname-bf-metadata.m
new file mode 100644
index 000000000000..a7636e4ebc8b
--- /dev/null
+++ b/test/CodeGenObjC/unname-bf-metadata.m
@@ -0,0 +1,14 @@
+// RUN: clang-cc -fnext-runtime -emit-llvm -o %t %s
+// Test that meta-data for ivar lists with unnamed bitfield are generated.
+//
+@interface Foo {
+@private
+ int first;
+ int :1;
+ int third :1;
+ int :1;
+ int fifth :1;
+}
+@end
+@implementation Foo
+@end