Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin -o - %s | FileCheck %s |
| 2 | |
| 3 | typedef 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 | |
| 11 | struct 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 | |
| 21 | int 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 | |
| 32 | template <class T> void test2(NSMutableArray *a) { |
| 33 | a[10] = 0; |
| 34 | } |
| 35 | template void test2<int>(NSMutableArray*); |
Stephen Lin | 4362261 | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 36 | // CHECK-LABEL: define weak_odr void @_Z5test2IiEvP14NSMutableArray |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 37 | // CHECK: @objc_msgSend |
| 38 | // CHECK: ret void |
| 39 | |
| 40 | |
| 41 | template <class T> void test3(NSMutableArray *a) { |
| 42 | a[sizeof(T)] = 0; |
| 43 | } |
| 44 | |
| 45 | template void test3<int>(NSMutableArray*); |
Stephen Lin | 4362261 | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 46 | // CHECK-LABEL: define weak_odr void @_Z5test3IiEvP14NSMutableArray |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 47 | // CHECK: @objc_msgSend |
| 48 | // CHECK: ret void |
| 49 | |
Fangrui Song | 6b33517 | 2020-12-30 20:45:56 -0800 | [diff] [blame] | 50 | // CHECK-LABEL: define{{.*}} void @_Z11static_dataP14NSMutableArray |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 51 | void static_data(NSMutableArray *array) { |
| 52 | // CHECK: call i32 @__cxa_guard_acquire |
hyeongyu kim | fd9b099 | 2021-11-09 02:09:49 +0900 | [diff] [blame] | 53 | // CHECK: {{call i8*.*@objc_msgSend }} |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 54 | // CHECK: call void @__cxa_guard_release |
| 55 | static id x = array[4]; |
| 56 | // CHECK: ret void |
| 57 | } |