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