Home | History | Annotate | Download | only in CodeGenObjC
      1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -emit-llvm %s -o - | FileCheck %s
      2 
      3 // rdar://problem/10290317
      4 @interface Test0
      5 - (void) setValue: (id) x;
      6 @end
      7 void test0(Test0 *t0, id value) {
      8   t0.value = value;
      9 }
     10 // CHECK: define void @test0(
     11 // CHECK: call void @objc_storeStrong
     12 // CHECK: call void @objc_storeStrong
     13 // CHECK: @objc_msgSend
     14 // CHECK: call void @objc_storeStrong(
     15 // CHECK: call void @objc_storeStrong(
     16 
     17 struct S1 { Class isa; };
     18 @interface Test1
     19 @property (nonatomic, strong) __attribute__((NSObject)) struct S1 *pointer;
     20 @end
     21 @implementation Test1
     22 @synthesize pointer;
     23 @end
     24 //   The getter should be a simple load.
     25 // CHECK:    define internal [[S1:%.*]]* @"\01-[Test1 pointer]"(
     26 // CHECK:      [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test1.pointer"
     27 // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST1:%.*]]* {{%.*}} to i8*
     28 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]]
     29 // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[S1]]**
     30 // CHECK-NEXT: [[T3:%.*]] = load [[S1]]** [[T2]], align 8
     31 // CHECK-NEXT: ret [[S1]]* [[T3]]
     32 
     33 //   The setter should be using objc_setProperty.
     34 // CHECK:    define internal void @"\01-[Test1 setPointer:]"(
     35 // CHECK:      [[T0:%.*]] = bitcast [[TEST1]]* {{%.*}} to i8*
     36 // CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test1.pointer"
     37 // CHECK-NEXT: [[T1:%.*]] = load [[S1]]** {{%.*}}
     38 // CHECK-NEXT: [[T2:%.*]] = bitcast [[S1]]* [[T1]] to i8*
     39 // CHECK-NEXT: call void @objc_setProperty(i8* [[T0]], i8* {{%.*}}, i64 [[OFFSET]], i8* [[T2]], i1 zeroext false, i1 zeroext false)
     40 // CHECK-NEXT: ret void
     41 
     42 
     43 // rdar://problem/12039404
     44 @interface Test2 {
     45 @private
     46   Class _theClass;
     47 }
     48 @property (copy) Class theClass;
     49 @end
     50 
     51 static Class theGlobalClass;
     52 @implementation Test2
     53 @synthesize theClass = _theClass;
     54 - (void) test {
     55   _theClass = theGlobalClass;
     56 }
     57 @end
     58 // CHECK:    define internal void @"\01-[Test2 test]"(
     59 // CHECK:      [[T0:%.*]] = load i8** @theGlobalClass, align 8
     60 // CHECK-NEXT: [[T1:%.*]] = load [[TEST2:%.*]]**
     61 // CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test2._theClass"
     62 // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST2]]* [[T1]] to i8*
     63 // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[OFFSET]]
     64 // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
     65 // CHECK-NEXT: call void @objc_storeStrong(i8** [[T4]], i8* [[T0]]) [[NUW:#[0-9]+]]
     66 // CHECK-NEXT: ret void
     67 
     68 // CHECK:    define internal i8* @"\01-[Test2 theClass]"(
     69 // CHECK:      [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test2._theClass"
     70 // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_getProperty(i8* {{.*}}, i8* {{.*}}, i64 [[OFFSET]], i1 zeroext true)
     71 // CHECK-NEXT: ret i8* [[T0]]
     72 
     73 // CHECK:    define internal void @"\01-[Test2 setTheClass:]"(
     74 // CHECK:      [[T0:%.*]] = bitcast [[TEST2]]* {{%.*}} to i8*
     75 // CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test2._theClass"
     76 // CHECK-NEXT: [[T1:%.*]] = load i8** {{%.*}}
     77 // CHECK-NEXT: call void @objc_setProperty(i8* [[T0]], i8* {{%.*}}, i64 [[OFFSET]], i8* [[T1]], i1 zeroext true, i1 zeroext true)
     78 // CHECK-NEXT: ret void
     79 
     80 // CHECK:    define internal void @"\01-[Test2 .cxx_destruct]"(
     81 // CHECK:      [[T0:%.*]] = load [[TEST2]]**
     82 // CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test2._theClass"
     83 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST2]]* [[T0]] to i8*
     84 // CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i8* [[T1]], i64 [[OFFSET]]
     85 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to i8**
     86 // CHECK-NEXT: call void @objc_storeStrong(i8** [[T3]], i8* null) [[NUW]]
     87 // CHECK-NEXT: ret void
     88 
     89 // CHECK: attributes [[NUW]] = { nounwind }
     90