blob: 8b7d8b53162bd331e2bcf244b3e3b9606dc3d3d7 [file] [log] [blame]
Ted Kremeneke65b0862012-03-06 20:05:56 +00001// RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin -o - %s | FileCheck %s
2
3typedef unsigned int size_t;
4@protocol P @end
5
6@interface NSMutableArray
7- (id)objectAtIndexedSubscript:(size_t)index;
8- (void)setObject:(id)object atIndexedSubscript:(size_t)index;
9@end
10
11struct S {
12 operator unsigned int ();
13 operator id ();
14};
15
16@interface NSMutableDictionary
17- (id)objectForKeyedSubscript:(id)key;
18- (void)setObject:(id)object forKeyedSubscript:(id)key;
19@end
20
21int main() {
22 NSMutableArray<P> * array;
23 S s;
24 id oldObject = array[(int)s];
25
26 NSMutableDictionary<P> *dict;
27 dict[(id)s] = oldObject;
28 oldObject = dict[(id)s];
29
30}
31
32template <class T> void test2(NSMutableArray *a) {
33 a[10] = 0;
34}
35template void test2<int>(NSMutableArray*);
Stephen Lin43622612013-08-15 06:47:53 +000036// CHECK-LABEL: define weak_odr void @_Z5test2IiEvP14NSMutableArray
Ted Kremeneke65b0862012-03-06 20:05:56 +000037// CHECK: @objc_msgSend
38// CHECK: ret void
39
40
41template <class T> void test3(NSMutableArray *a) {
42 a[sizeof(T)] = 0;
43}
44
45template void test3<int>(NSMutableArray*);
Stephen Lin43622612013-08-15 06:47:53 +000046// CHECK-LABEL: define weak_odr void @_Z5test3IiEvP14NSMutableArray
Ted Kremeneke65b0862012-03-06 20:05:56 +000047// CHECK: @objc_msgSend
48// CHECK: ret void
49
Fangrui Song6b335172020-12-30 20:45:56 -080050// CHECK-LABEL: define{{.*}} void @_Z11static_dataP14NSMutableArray
Ted Kremeneke65b0862012-03-06 20:05:56 +000051void static_data(NSMutableArray *array) {
52 // CHECK: call i32 @__cxa_guard_acquire
hyeongyu kimfd9b0992021-11-09 02:09:49 +090053 // CHECK: {{call i8*.*@objc_msgSend }}
Ted Kremeneke65b0862012-03-06 20:05:56 +000054 // CHECK: call void @__cxa_guard_release
55 static id x = array[4];
56 // CHECK: ret void
57}