John McCall | e68b984 | 2010-12-04 03:11:00 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s |
| 2 | |
| 3 | // TODO: actually test most of this instead of just emitting it |
Daniel Dunbar | b21d6af | 2008-09-04 04:36:23 +0000 | [diff] [blame] | 4 | |
Daniel Dunbar | 23afaad | 2009-11-17 08:57:36 +0000 | [diff] [blame] | 5 | int printf(const char *, ...); |
Daniel Dunbar | b21d6af | 2008-09-04 04:36:23 +0000 | [diff] [blame] | 6 | |
| 7 | @interface Root |
| 8 | -(id) alloc; |
| 9 | -(id) init; |
| 10 | @end |
| 11 | |
| 12 | @interface A : Root { |
| 13 | int x; |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 14 | int y, ro, z; |
Daniel Dunbar | 739a36b | 2008-09-24 18:00:13 +0000 | [diff] [blame] | 15 | id ob0, ob1, ob2, ob3, ob4; |
Daniel Dunbar | b21d6af | 2008-09-04 04:36:23 +0000 | [diff] [blame] | 16 | } |
| 17 | @property int x; |
| 18 | @property int y; |
| 19 | @property int z; |
| 20 | @property(readonly) int ro; |
Daniel Dunbar | 739a36b | 2008-09-24 18:00:13 +0000 | [diff] [blame] | 21 | @property(assign) id ob0; |
| 22 | @property(retain) id ob1; |
| 23 | @property(copy) id ob2; |
| 24 | @property(retain, nonatomic) id ob3; |
| 25 | @property(copy, nonatomic) id ob4; |
Daniel Dunbar | b21d6af | 2008-09-04 04:36:23 +0000 | [diff] [blame] | 26 | @end |
| 27 | |
| 28 | @implementation A |
| 29 | @dynamic x; |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 30 | @synthesize y; |
| 31 | @synthesize z = z; |
| 32 | @synthesize ro; |
Daniel Dunbar | 739a36b | 2008-09-24 18:00:13 +0000 | [diff] [blame] | 33 | @synthesize ob0; |
| 34 | @synthesize ob1; |
| 35 | @synthesize ob2; |
| 36 | @synthesize ob3; |
| 37 | @synthesize ob4; |
Daniel Dunbar | b21d6af | 2008-09-04 04:36:23 +0000 | [diff] [blame] | 38 | -(int) y { |
| 39 | return x + 1; |
| 40 | } |
| 41 | -(void) setZ: (int) arg { |
| 42 | x = arg - 1; |
| 43 | } |
| 44 | @end |
| 45 | |
| 46 | @interface A (Cat) |
| 47 | @property int dyn; |
| 48 | @end |
| 49 | |
| 50 | @implementation A (Cat) |
| 51 | -(int) dyn { |
| 52 | return 10; |
| 53 | } |
| 54 | @end |
John McCall | e68b984 | 2010-12-04 03:11:00 +0000 | [diff] [blame] | 55 | |
| 56 | // Test that compound operations only compute the base once. |
| 57 | // CHECK: define void @test2 |
| 58 | A *test2_helper(void); |
| 59 | void test2() { |
| 60 | // CHECK: [[BASE:%.*]] = call [[A:%.*]]* @test2_helper() |
| 61 | // CHECK-NEXT: [[SEL:%.*]] = load i8** |
| 62 | // CHECK-NEXT: [[BASETMP:%.*]] = bitcast [[A]]* [[BASE]] to i8* |
| 63 | // CHECK-NEXT: [[LD:%.*]] = call i32 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i32 (i8*, i8*)*)(i8* [[BASETMP]], i8* [[SEL]]) |
| 64 | // CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[LD]], 1 |
| 65 | // CHECK-NEXT: [[SEL:%.*]] = load i8** |
| 66 | // CHECK-NEXT: [[BASETMP:%.*]] = bitcast [[A]]* [[BASE]] to i8* |
| 67 | // CHECK-NEXT: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i32)*)(i8* [[BASETMP]], i8* [[SEL]], i32 [[ADD]]) |
| 68 | test2_helper().dyn++; |
| 69 | |
| 70 | // CHECK: [[BASE:%.*]] = call [[A]]* @test2_helper() |
| 71 | // CHECK-NEXT: [[SEL:%.*]] = load i8** |
| 72 | // CHECK-NEXT: [[BASETMP:%.*]] = bitcast [[A]]* [[BASE]] to i8* |
| 73 | // CHECK-NEXT: [[LD:%.*]] = call i32 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i32 (i8*, i8*)*)(i8* [[BASETMP]], i8* [[SEL]]) |
| 74 | // CHECK-NEXT: [[ADD:%.*]] = mul nsw i32 [[LD]], 10 |
| 75 | // CHECK-NEXT: [[SEL:%.*]] = load i8** |
| 76 | // CHECK-NEXT: [[BASETMP:%.*]] = bitcast [[A]]* [[BASE]] to i8* |
| 77 | // CHECK-NEXT: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i32)*)(i8* [[BASETMP]], i8* [[SEL]], i32 [[ADD]]) |
| 78 | test2_helper().dyn *= 10; |
| 79 | } |
John McCall | 74e40b7 | 2010-12-04 09:03:57 +0000 | [diff] [blame] | 80 | |
| 81 | // Test aggregate initialization from property reads. |
| 82 | // Not crashing is good enough for the property-specific test. |
| 83 | struct test3_struct { int x,y,z; }; |
| 84 | struct test3_nested { struct test3_struct t; }; |
| 85 | @interface test3_object |
| 86 | @property struct test3_struct s; |
| 87 | @end |
| 88 | void test3(test3_object *p) { |
| 89 | struct test3_struct array[1] = { p.s }; |
| 90 | struct test3_nested agg = { p.s }; |
| 91 | } |