1 // RUN: %clang_cc1 -triple i386-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-exceptions -fobjc-runtime=macosx-fragile-10.10 -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -triple i386-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-exceptions -fobjc-runtime=macosx-fragile-10.10 -o - %s | FileCheck %s -check-prefix=GLOBALS
17 // GLOBALS-LABEL: @OBJC_METACLASS_A
18 // Strong layout: scan the first word.
19 // GLOBALS: @OBJC_CLASS_NAME_{{.*}} = private unnamed_addr constant [2 x i8] c"\01\00"
20 // Weak layout: skip the first word, scan the second word.
21 // GLOBALS: @OBJC_CLASS_NAME_{{.*}} = private unnamed_addr constant [2 x i8] c"\11\00"
24 // ^ is compiled by ARC (controls interpretation of layouts)
25 // ^ has C++ structors (no distinction for zero-initializable)
26 // ^ factory (always set on non-metaclasses)
27 // GLOBALS: @OBJC_CLASS_A = private global {{.*}} i32 67117057
30 // CHECK-LABEL: define internal void @"\01-[A testStrong]"
31 // CHECK: [[SELFVAR:%.*]] = alloca ptr, align 4
33 // CHECK: [[X:%x]] = alloca ptr, align 4
34 // CHECK: [[SELF:%.*]] = load ptr, ptr [[SELFVAR]]
35 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8, ptr [[SELF]], i32 4
36 // CHECK-NEXT: [[T0:%.*]] = load ptr, ptr [[T1]]
37 // CHECK-NEXT: [[T2:%.*]] = call ptr @llvm.objc.retain(ptr [[T0]])
38 // CHECK-NEXT: store ptr [[T2]], ptr [[X]]
40 // CHECK-NEXT: [[VALUE:%.*]] = load ptr, ptr [[X]]
41 // CHECK-NEXT: [[SELF:%.*]] = load ptr, ptr [[SELFVAR]]
42 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8, ptr [[SELF]], i32 4
43 // CHECK-NEXT: call void @llvm.objc.storeStrong(ptr [[T1]], ptr [[VALUE]])
45 // CHECK-NEXT: call void @llvm.objc.storeStrong(ptr [[X]], ptr null)
46 // CHECK-NEXT: ret void
49 // CHECK-LABEL: define internal void @"\01-[A testWeak]"
50 // CHECK: [[SELFVAR:%.*]] = alloca ptr, align 4
52 // CHECK: [[X:%x]] = alloca ptr, align 4
53 // CHECK: [[SELF:%.*]] = load ptr, ptr [[SELFVAR]]
54 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8, ptr [[SELF]], i32 8
55 // CHECK-NEXT: [[T2:%.*]] = call ptr @llvm.objc.loadWeakRetained(ptr [[T1]])
56 // CHECK-NEXT: store ptr [[T2]], ptr [[X]]
58 // CHECK-NEXT: [[VALUE:%.*]] = load ptr, ptr [[X]]
59 // CHECK-NEXT: [[SELF:%.*]] = load ptr, ptr [[SELFVAR]]
60 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8, ptr [[SELF]], i32 8
61 // CHECK-NEXT: call ptr @llvm.objc.storeWeak(ptr [[T1]], ptr [[VALUE]])
63 // CHECK-NEXT: call void @llvm.objc.storeStrong(ptr [[X]], ptr null)
64 // CHECK-NEXT: ret void
67 // CHECK-LABEL: define internal void @"\01-[A .cxx_destruct]"
68 // CHECK: [[SELFVAR:%.*]] = alloca ptr, align 4
69 // CHECK: [[SELF:%.*]] = load ptr, ptr [[SELFVAR]]
70 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8, ptr [[SELF]], i32 8
71 // CHECK-NEXT: call void @llvm.objc.destroyWeak(ptr [[T1]])
72 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8, ptr [[SELF]], i32 4
73 // CHECK-NEXT: call void @llvm.objc.storeStrong(ptr [[T1]], ptr null)
74 // CHECK-NEXT: ret void
77 // Test case for corner case of ivar layout.
85 __unsafe_unretained id c_unsafe[5];
91 @implementation C @end
93 // Note that these layouts implicitly start at the end of the previous
94 // class rounded up to pointer alignment.
95 // GLOBALS-LABEL: @OBJC_METACLASS_C
96 // Strong layout: skip five, scan four, skip three, scan seven
97 // 'T' == 0x54, '7' == 0x37
98 // GLOBALS: @OBJC_CLASS_NAME_{{.*}} = private unnamed_addr constant [3 x i8] c"T7\00"
99 // Weak layout: skip nine, scan three
100 // GLOBALS: @OBJC_CLASS_NAME_{{.*}} = private unnamed_addr constant [2 x i8] c"\93\00"
102 extern void useBlock(void (^block)(void));
104 // 256 == 0x100 == starts with 1 strong
105 // GLOBALS: @"__block_descriptor{{.*}} = linkonce_odr hidden {{.*}}, i32 256 }
106 void testBlockLayoutStrong(id x) {
107 useBlock(^{ (void) x; });
110 // 1 == 0x001 == starts with 1 weak
111 // GLOBALS: @"__block_descriptor{{.*}} = linkonce_odr hidden {{.*}}, i32 1 }
112 void testBlockLayoutWeak(__weak id x) {
113 useBlock(^{ (void) x; });
116 // CHECK-LABEL: define{{.*}} void @testCatch()
117 // CHECK: [[X:%.*]] = alloca ptr, align 4
118 // CHECK: [[Y:%.*]] = alloca ptr, align 4
119 // CHECK: call void @objc_exception_try_enter
121 // CHECK: call void @checkpoint(i32 noundef 0)
122 // CHECK: call void @objc_exception_try_exit
124 // CHECK: call void @checkpoint(i32 noundef 3)
125 // CHECK: [[EXN:%.*]] = call ptr @objc_exception_extract
126 // CHECK: call i32 @objc_exception_match(
128 // CHECK: [[T2:%.*]] = call ptr @llvm.objc.retain(ptr [[EXN]])
129 // CHECK: store ptr [[T2]], ptr [[X]]
130 // CHECK: call void @checkpoint(i32 noundef 1)
131 // CHECK: call void @llvm.objc.storeStrong(ptr [[X]], ptr null)
133 // CHECK: [[T0:%.*]] = call ptr @llvm.objc.retain(ptr [[EXN]])
134 // CHECK: store ptr [[T0]], ptr [[Y]]
135 // CHECK: call void @checkpoint(i32 noundef 2)
136 // CHECK: call void @llvm.objc.storeStrong(ptr [[Y]], ptr null)
137 extern void checkpoint(int n);
138 void testCatch(void) {