annotate clang/test/SemaTemplate/address_space-dependent.cpp @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -x c++ -std=c++14 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 template <int I, int J, int K>
anatofuz
parents:
diff changeset
4 void car() {
anatofuz
parents:
diff changeset
5 int __attribute__((address_space(I))) __attribute__((address_space(J))) * Y; // expected-error {{multiple address spaces specified for type}}
anatofuz
parents:
diff changeset
6 int *__attribute__((address_space(I))) __attribute__((address_space(J))) * Z; // expected-error {{multiple address spaces specified for type}}
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 __attribute__((address_space(I))) int local; // expected-error {{automatic variable qualified with an address space}}
anatofuz
parents:
diff changeset
9 __attribute__((address_space(J))) int array[5]; // expected-error {{automatic variable qualified with an address space}}
anatofuz
parents:
diff changeset
10 __attribute__((address_space(I))) int arrarr[5][5]; // expected-error {{automatic variable qualified with an address space}}
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 __attribute__((address_space(J))) * x; // expected-error {{C++ requires a type specifier for all declarations}}
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 __attribute__((address_space(I))) float *B;
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 typedef __attribute__((address_space(J))) int AS2Int;
anatofuz
parents:
diff changeset
17 struct HasASFields {
anatofuz
parents:
diff changeset
18 AS2Int typedef_as_field; // expected-error {{field may not be qualified with an address space}}
anatofuz
parents:
diff changeset
19 };
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 struct _st {
anatofuz
parents:
diff changeset
22 int x, y;
anatofuz
parents:
diff changeset
23 } s __attribute((address_space(I))) = {1, 1};
anatofuz
parents:
diff changeset
24 }
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 template <int I>
anatofuz
parents:
diff changeset
27 struct HasASTemplateFields {
anatofuz
parents:
diff changeset
28 __attribute__((address_space(I))) int as_field; // expected-error {{field may not be qualified with an address space}}
anatofuz
parents:
diff changeset
29 };
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 template <int I, int J>
anatofuz
parents:
diff changeset
32 void foo(__attribute__((address_space(I))) float *a, // expected-note {{candidate template ignored: substitution failure [with I = 1, J = 2]: parameter may not be qualified with an address space}}
anatofuz
parents:
diff changeset
33 __attribute__((address_space(J))) float b) {
anatofuz
parents:
diff changeset
34 *a = 5.0f + b;
anatofuz
parents:
diff changeset
35 }
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 template void foo<1, 2>(float *, float); // expected-error {{explicit instantiation of 'foo' does not refer to a function template, variable template, member function, member class, or static data member}}
anatofuz
parents:
diff changeset
38
anatofuz
parents:
diff changeset
39 template <int I>
anatofuz
parents:
diff changeset
40 void neg() {
anatofuz
parents:
diff changeset
41 __attribute__((address_space(I))) int *bounds; // expected-error {{address space is negative}}
anatofuz
parents:
diff changeset
42 }
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 template <long int I>
anatofuz
parents:
diff changeset
45 void tooBig() {
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
46 __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388588)}}
150
anatofuz
parents:
diff changeset
47 }
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 template <long int I>
anatofuz
parents:
diff changeset
50 void correct() {
anatofuz
parents:
diff changeset
51 __attribute__((address_space(I))) int *bounds;
anatofuz
parents:
diff changeset
52 }
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 template <int I, int J>
anatofuz
parents:
diff changeset
55 char *cmp(__attribute__((address_space(I))) char *x, __attribute__((address_space(J))) char *y) {
anatofuz
parents:
diff changeset
56 return x < y ? x : y; // expected-error {{comparison of distinct pointer types ('__attribute__((address_space(1))) char *' and '__attribute__((address_space(2))) char *')}}
anatofuz
parents:
diff changeset
57 }
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 typedef void ft(void);
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 template <int I>
anatofuz
parents:
diff changeset
62 struct fooFunction {
anatofuz
parents:
diff changeset
63 __attribute__((address_space(I))) void **const base = 0;
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 void *get_0(void) {
anatofuz
parents:
diff changeset
66 return base[0]; // expected-error {{cannot initialize return object of type 'void *' with an lvalue of type '__attribute__((address_space(1))) void *}}
anatofuz
parents:
diff changeset
67 }
anatofuz
parents:
diff changeset
68
anatofuz
parents:
diff changeset
69 __attribute__((address_space(I))) ft qf; // expected-error {{function type may not be qualified with an address space}}
anatofuz
parents:
diff changeset
70 __attribute__((address_space(I))) char *test3_val;
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 void test3(void) {
anatofuz
parents:
diff changeset
73 extern void test3_helper(char *p); // expected-note {{passing argument to parameter 'p' here}}
anatofuz
parents:
diff changeset
74 test3_helper(test3_val); // expected-error {{cannot initialize a parameter of type 'char *' with an lvalue of type '__attribute__((address_space(1))) char *'}}
anatofuz
parents:
diff changeset
75 }
anatofuz
parents:
diff changeset
76 };
anatofuz
parents:
diff changeset
77
anatofuz
parents:
diff changeset
78 template <typename T, int N>
anatofuz
parents:
diff changeset
79 int GetAddressSpaceValue(T __attribute__((address_space(N))) * p) {
anatofuz
parents:
diff changeset
80 return N;
anatofuz
parents:
diff changeset
81 }
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 template <unsigned A> int __attribute__((address_space(A))) *same_template();
anatofuz
parents:
diff changeset
84 template <unsigned B> int __attribute__((address_space(B))) *same_template();
anatofuz
parents:
diff changeset
85 void test_same_template() { (void) same_template<0>(); }
anatofuz
parents:
diff changeset
86
anatofuz
parents:
diff changeset
87 template <unsigned A> int __attribute__((address_space(A))) *different_template(); // expected-note {{candidate function [with A = 0]}}
anatofuz
parents:
diff changeset
88 template <unsigned B> int __attribute__((address_space(B+1))) *different_template(); // expected-note {{candidate function [with B = 0]}}
anatofuz
parents:
diff changeset
89 void test_different_template() { (void) different_template<0>(); } // expected-error {{call to 'different_template' is ambiguous}}
anatofuz
parents:
diff changeset
90
anatofuz
parents:
diff changeset
91 template <typename T> struct partial_spec_deduce_as;
anatofuz
parents:
diff changeset
92 template <typename T, unsigned AS>
anatofuz
parents:
diff changeset
93 struct partial_spec_deduce_as <__attribute__((address_space(AS))) T *> {
anatofuz
parents:
diff changeset
94 static const unsigned value = AS;
anatofuz
parents:
diff changeset
95 };
anatofuz
parents:
diff changeset
96
anatofuz
parents:
diff changeset
97 int main() {
anatofuz
parents:
diff changeset
98 int __attribute__((address_space(1))) * p1;
anatofuz
parents:
diff changeset
99 int p = GetAddressSpaceValue(p1);
anatofuz
parents:
diff changeset
100
anatofuz
parents:
diff changeset
101 car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
anatofuz
parents:
diff changeset
102 HasASTemplateFields<1> HASTF;
anatofuz
parents:
diff changeset
103 neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
104 correct<0x7FFFEB>();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
105 tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650L>' requested here}}
150
anatofuz
parents:
diff changeset
106
anatofuz
parents:
diff changeset
107 __attribute__((address_space(1))) char *x;
anatofuz
parents:
diff changeset
108 __attribute__((address_space(2))) char *y;
anatofuz
parents:
diff changeset
109 cmp<1, 2>(x, y); // expected-note {{in instantiation of function template specialization 'cmp<1, 2>' requested here}}
anatofuz
parents:
diff changeset
110
anatofuz
parents:
diff changeset
111 fooFunction<1> ff;
anatofuz
parents:
diff changeset
112 ff.get_0(); // expected-note {{in instantiation of member function 'fooFunction<1>::get_0' requested here}}
anatofuz
parents:
diff changeset
113 ff.qf();
anatofuz
parents:
diff changeset
114 ff.test3(); // expected-note {{in instantiation of member function 'fooFunction<1>::test3' requested here}}
anatofuz
parents:
diff changeset
115
anatofuz
parents:
diff changeset
116 static_assert(partial_spec_deduce_as<int __attribute__((address_space(3))) *>::value == 3, "address space value has been incorrectly deduced");
anatofuz
parents:
diff changeset
117
anatofuz
parents:
diff changeset
118 return 0;
anatofuz
parents:
diff changeset
119 }