1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc template<typename T, typename U> 4*f4a2713aSLionel Sambuc struct is_same { 5*f4a2713aSLionel Sambuc static const bool value = false; 6*f4a2713aSLionel Sambuc }; 7*f4a2713aSLionel Sambuc 8*f4a2713aSLionel Sambuc template<typename T> 9*f4a2713aSLionel Sambuc struct is_same<T, T> { 10*f4a2713aSLionel Sambuc static const bool value = true; 11*f4a2713aSLionel Sambuc }; 12*f4a2713aSLionel Sambuc 13*f4a2713aSLionel Sambuc typedef int __attribute__((address_space(1))) int_1;; 14*f4a2713aSLionel Sambuc typedef int __attribute__((address_space(2))) int_2;; 15*f4a2713aSLionel Sambuc typedef int __attribute__((address_space(1))) *int_1_ptr; 16*f4a2713aSLionel Sambuc typedef int_2 *int_2_ptr; 17*f4a2713aSLionel Sambuc 18*f4a2713aSLionel Sambuc // Check that we maintain address spaces through template argument 19*f4a2713aSLionel Sambuc // deduction from a type. 20*f4a2713aSLionel Sambuc template<typename T> 21*f4a2713aSLionel Sambuc struct remove_pointer { 22*f4a2713aSLionel Sambuc typedef T type; 23*f4a2713aSLionel Sambuc }; 24*f4a2713aSLionel Sambuc 25*f4a2713aSLionel Sambuc template<typename T> 26*f4a2713aSLionel Sambuc struct remove_pointer<T *> { 27*f4a2713aSLionel Sambuc typedef T type; 28*f4a2713aSLionel Sambuc }; 29*f4a2713aSLionel Sambuc 30*f4a2713aSLionel Sambuc int check_remove0[is_same<remove_pointer<int_1_ptr>::type, int_1>::value? 1 : -1]; 31*f4a2713aSLionel Sambuc int check_remove1[is_same<remove_pointer<int_2_ptr>::type, int_2>::value? 1 : -1]; 32*f4a2713aSLionel Sambuc int check_remove2[is_same<remove_pointer<int_2_ptr>::type, int>::value? -1 : 1]; 33*f4a2713aSLionel Sambuc int check_remove3[is_same<remove_pointer<int_2_ptr>::type, int_1>::value? -1 : 1]; 34*f4a2713aSLionel Sambuc 35*f4a2713aSLionel Sambuc template<typename T> 36*f4a2713aSLionel Sambuc struct is_pointer_in_address_space_1 { 37*f4a2713aSLionel Sambuc static const bool value = false; 38*f4a2713aSLionel Sambuc }; 39*f4a2713aSLionel Sambuc 40*f4a2713aSLionel Sambuc template<typename T> 41*f4a2713aSLionel Sambuc struct is_pointer_in_address_space_1<T __attribute__((address_space(1))) *> { 42*f4a2713aSLionel Sambuc static const bool value = true; 43*f4a2713aSLionel Sambuc }; 44*f4a2713aSLionel Sambuc 45*f4a2713aSLionel Sambuc int check_ptr_in_as1[is_pointer_in_address_space_1<int_1_ptr>::value? 1 : -1]; 46*f4a2713aSLionel Sambuc int check_ptr_in_as2[is_pointer_in_address_space_1<int_2_ptr>::value? -1 : 1]; 47*f4a2713aSLionel Sambuc int check_ptr_in_as3[is_pointer_in_address_space_1<int*>::value? -1 : 1]; 48*f4a2713aSLionel Sambuc 49*f4a2713aSLionel Sambuc // Check that we maintain address spaces through template argument 50*f4a2713aSLionel Sambuc // deduction for a call. 51*f4a2713aSLionel Sambuc template<typename T> accept_any_pointer(T *)52*f4a2713aSLionel Sambucvoid accept_any_pointer(T*) { 53*f4a2713aSLionel Sambuc T *x = 1; // expected-error{{cannot initialize a variable of type '__attribute__((address_space(1))) int *' with an rvalue of type 'int'}} \ 54*f4a2713aSLionel Sambuc // expected-error{{cannot initialize a variable of type '__attribute__((address_space(3))) int *' with an rvalue of type 'int'}} 55*f4a2713aSLionel Sambuc } 56*f4a2713aSLionel Sambuc test_accept_any_pointer(int_1_ptr ip1,int_2_ptr ip2)57*f4a2713aSLionel Sambucvoid test_accept_any_pointer(int_1_ptr ip1, int_2_ptr ip2) { 58*f4a2713aSLionel Sambuc static __attribute__((address_space(3))) int array[17]; 59*f4a2713aSLionel Sambuc accept_any_pointer(ip1); // expected-note{{in instantiation of}} 60*f4a2713aSLionel Sambuc accept_any_pointer(array); // expected-note{{in instantiation of}} 61*f4a2713aSLionel Sambuc } 62*f4a2713aSLionel Sambuc 63*f4a2713aSLionel Sambuc template<typename T> struct identity {}; 64*f4a2713aSLionel Sambuc 65*f4a2713aSLionel Sambuc template<typename T> 66*f4a2713aSLionel Sambuc identity<T> accept_arg_in_address_space_1(__attribute__((address_space(1))) T &ir1); 67*f4a2713aSLionel Sambuc 68*f4a2713aSLionel Sambuc template<typename T> 69*f4a2713aSLionel Sambuc identity<T> accept_any_arg(T &ir1); 70*f4a2713aSLionel Sambuc test_arg_in_address_space_1()71*f4a2713aSLionel Sambucvoid test_arg_in_address_space_1() { 72*f4a2713aSLionel Sambuc static int __attribute__((address_space(1))) int_1; 73*f4a2713aSLionel Sambuc identity<int> ii = accept_arg_in_address_space_1(int_1); 74*f4a2713aSLionel Sambuc identity<int __attribute__((address_space(1)))> ii2 = accept_any_arg(int_1); 75*f4a2713aSLionel Sambuc } 76*f4a2713aSLionel Sambuc 77*f4a2713aSLionel Sambuc // Partial ordering 78*f4a2713aSLionel Sambuc template<typename T> int &order1(__attribute__((address_space(1))) T&); 79*f4a2713aSLionel Sambuc template<typename T> float &order1(T&); 80*f4a2713aSLionel Sambuc test_order1()81*f4a2713aSLionel Sambucvoid test_order1() { 82*f4a2713aSLionel Sambuc static __attribute__((address_space(1))) int i1; 83*f4a2713aSLionel Sambuc int i; 84*f4a2713aSLionel Sambuc int &ir = order1(i1); 85*f4a2713aSLionel Sambuc float &fr = order1(i); 86*f4a2713aSLionel Sambuc } 87