brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.2 KiB · 0c604bf Raw
157 lines · plain
1// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o - %s | FileCheck %s2 3// TODO: actually test most of this instead of just emitting it4 5int printf(const char *, ...);6 7@interface Root8-(id) alloc;9-(id) init;10@end11 12@interface A : Root {13  int x;14  int y, ro, z;15  id ob0, ob1, ob2, ob3, ob4;16}17@property int x;18@property int y;19@property int z;20@property(readonly) int ro;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;26@end27 28@implementation A29@dynamic x;30@synthesize y;31@synthesize z = z;32@synthesize ro;33@synthesize ob0;34@synthesize ob1;35@synthesize ob2;36@synthesize ob3;37@synthesize ob4;38-(int) y {39  return x + 1;40}41-(void) setZ: (int) arg {42  x = arg - 1;43}44@end45 46@interface A (Cat)47@property int dyn;48@end49 50@implementation A (Cat)51-(int) dyn {52  return 10;53}54@end55 56// Test that compound operations only compute the base once.57// CHECK-LABEL: define{{.*}} void @test258A *test2_helper(void);59void test2(void) {60  // CHECK:      [[BASE:%.*]] = call ptr @test2_helper()61  // CHECK-NEXT: [[SEL:%.*]] = load ptr, ptr62  // CHECK-NEXT: [[LD:%.*]] = call i32 @objc_msgSend(ptr noundef [[BASE]], ptr noundef [[SEL]])63  // CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[LD]], 164  // CHECK-NEXT: [[SEL:%.*]] = load ptr, ptr65  // CHECK-NEXT: call void @objc_msgSend(ptr noundef [[BASE]], ptr noundef [[SEL]], i32 noundef [[ADD]])66  test2_helper().dyn++;67 68  // CHECK:      [[BASE:%.*]] = call ptr @test2_helper()69  // CHECK-NEXT: [[SEL:%.*]] = load ptr, ptr70  // CHECK-NEXT: [[LD:%.*]] = call i32 @objc_msgSend(ptr noundef [[BASE]], ptr noundef [[SEL]])71  // CHECK-NEXT: [[ADD:%.*]] = mul nsw i32 [[LD]], 1072  // CHECK-NEXT: [[SEL:%.*]] = load ptr, ptr73  // CHECK-NEXT: call void @objc_msgSend(ptr noundef [[BASE]], ptr noundef [[SEL]], i32 noundef [[ADD]])74  test2_helper().dyn *= 10;75}76 77// Test aggregate initialization from property reads.78// Not crashing is good enough for the property-specific test.79struct test3_struct { int x,y,z; };80struct test3_nested { struct test3_struct t; };81@interface test3_object82@property struct test3_struct s;83@end84void test3(test3_object *p) {85  struct test3_struct array[1] = { p.s };86  struct test3_nested agg = { p.s };87}88 89// PR874290@interface Test4  {}91@property float f;92@end93// CHECK-LABEL: define{{.*}} void @test494void test4(Test4 *t) {95  extern int test4_printf(const char *, ...);96  // CHECK: [[TMP:%.*]] = call float @objc_msgSend97  // CHECK-NEXT: [[EXT:%.*]] = fpext float [[TMP]] to double98  // CHECK-NEXT: call i32 (ptr, ...) @test4_printf(ptr {{.*}}, double noundef [[EXT]])99  // CHECK-NEXT: ret void100  test4_printf("%.2f", t.f);101}102 103@interface Test5 {104  unsigned _x : 5;105}106@property unsigned x;107@end108@implementation Test5109@synthesize x = _x;110@end111 112@interface Test6113@property void (*prop)(void);114@end115 116void test6_func(void);117void test6(Test6 *a) {118  a.prop = test6_func;119}120 121@interface Test7122@property unsigned char x;123@end124void test7(Test7 *t) {125  t.x &= 2;126  t.x |= 5;127  t.x ^= 8;128}129// CHECK:    define{{.*}} void @test7(ptr130// CHECK:      [[T:%.*]] = alloca ptr,131// CHECK-NEXT: store132// CHECK-NEXT: [[T0:%.*]] = load ptr, ptr [[T]], align133// CHECK-NEXT: load ptr, ptr @OBJC_SELECTOR_REFERENCES134// CHECK-NEXT: [[T2:%.*]] = call zeroext i8135// CHECK-NEXT: [[T3:%.*]] = zext i8 [[T2]] to i32136// CHECK-NEXT: [[T4:%.*]] = and i32 [[T3]], 2137// CHECK-NEXT: [[T5:%.*]] = trunc i32 [[T4]] to i8138// CHECK-NEXT: load ptr, ptr @OBJC_SELECTOR_REFERENCES139// CHECK-NEXT: call void140// CHECK-NEXT: [[T0:%.*]] = load ptr, ptr [[T]], align141// CHECK-NEXT: load ptr, ptr @OBJC_SELECTOR_REFERENCES142// CHECK-NEXT: [[T2:%.*]] = call zeroext i8143// CHECK-NEXT: [[T3:%.*]] = zext i8 [[T2]] to i32144// CHECK-NEXT: [[T4:%.*]] = or i32 [[T3]], 5145// CHECK-NEXT: [[T5:%.*]] = trunc i32 [[T4]] to i8146// CHECK-NEXT: load ptr, ptr @OBJC_SELECTOR_REFERENCES147// CHECK-NEXT: call void148// CHECK-NEXT: [[T0:%.*]] = load ptr, ptr [[T]], align149// CHECK-NEXT: load ptr, ptr @OBJC_SELECTOR_REFERENCES150// CHECK-NEXT: [[T2:%.*]] = call zeroext i8151// CHECK-NEXT: [[T3:%.*]] = zext i8 [[T2]] to i32152// CHECK-NEXT: [[T4:%.*]] = xor i32 [[T3]], 8153// CHECK-NEXT: [[T5:%.*]] = trunc i32 [[T4]] to i8154// CHECK-NEXT: load ptr, ptr @OBJC_SELECTOR_REFERENCES155// CHECK-NEXT: call void156// CHECK-NEXT: ret void157