blob: eda03dbac2bda62aad2c463ca9e8e190a767fcb5 [file] [log] [blame]
Douglas Gregora459cc22011-04-27 23:34:22 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3template<typename T, typename U>
4struct is_same {
5 static const bool value = false;
6};
7
8template<typename T>
9struct is_same<T, T> {
10 static const bool value = true;
11};
12
13typedef int __attribute__((address_space(1))) int_1;;
14typedef int __attribute__((address_space(2))) int_2;;
15typedef int __attribute__((address_space(1))) *int_1_ptr;
16typedef int_2 *int_2_ptr;
17
18// Check that we maintain address spaces through template argument
19// deduction from a type.
20template<typename T>
21struct remove_pointer {
22 typedef T type;
23};
24
25template<typename T>
26struct remove_pointer<T *> {
27 typedef T type;
28};
29
30int check_remove0[is_same<remove_pointer<int_1_ptr>::type, int_1>::value? 1 : -1];
31int check_remove1[is_same<remove_pointer<int_2_ptr>::type, int_2>::value? 1 : -1];
32int check_remove2[is_same<remove_pointer<int_2_ptr>::type, int>::value? -1 : 1];
33int check_remove3[is_same<remove_pointer<int_2_ptr>::type, int_1>::value? -1 : 1];
Douglas Gregor61d0b6b2011-04-28 00:56:09 +000034
35template<typename T>
36struct is_pointer_in_address_space_1 {
37 static const bool value = false;
38};
39
40template<typename T>
41struct is_pointer_in_address_space_1<T __attribute__((address_space(1))) *> {
42 static const bool value = true;
43};
Douglas Gregora459cc22011-04-27 23:34:22 +000044
Douglas Gregor61d0b6b2011-04-28 00:56:09 +000045int check_ptr_in_as1[is_pointer_in_address_space_1<int_1_ptr>::value? 1 : -1];
46int check_ptr_in_as2[is_pointer_in_address_space_1<int_2_ptr>::value? -1 : 1];
47int check_ptr_in_as3[is_pointer_in_address_space_1<int*>::value? -1 : 1];
48
Douglas Gregora459cc22011-04-27 23:34:22 +000049// Check that we maintain address spaces through template argument
50// deduction for a call.
51template<typename T>
52void 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
57void 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
Douglas Gregor61d0b6b2011-04-28 00:56:09 +000063template<typename T> struct identity {};
64
65template<typename T>
66identity<T> accept_arg_in_address_space_1(__attribute__((address_space(1))) T &ir1);
67
68template<typename T>
69identity<T> accept_any_arg(T &ir1);
70
71void 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}
Douglas Gregor769d0cc2011-04-30 17:07:52 +000076
77// Partial ordering
78template<typename T> int &order1(__attribute__((address_space(1))) T&);
79template<typename T> float &order1(T&);
80
81void test_order1() {
82 static __attribute__((address_space(1))) int i1;
83 int i;
84 int &ir = order1(i1);
85 float &fr = order1(i);
86}