Debian Codegraph @

clang/test/SemaOpenCLCXX/address-space-deduction.clcpp

raw
1 //RUN: %clang_cc1 %s -pedantic -ast-dump -verify | FileCheck %s
2
3 //expected-no-diagnostics
4
5 //CHECK: |-VarDecl {{.*}} foo 'const __global int'
6 constexpr int foo = 0;
7
8 //CHECK: |-VarDecl {{.*}} foo1 'T' cinit
9 //CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global long' implicit_instantiation cinit
10 template <typename T>
11 T foo1 = 0;
12
13 class c {
14 public:
15 //CHECK: `-VarDecl {{.*}} foo2 'const __global int'
16 static constexpr int foo2 = 0;
17 };
18
19 struct c1 {};
20
21 // We only deduce addr space in type alias in pointer types.
22 //CHECK: TypeAliasDecl {{.*}} alias_c1 'c1'
23 using alias_c1 = c1;
24 //CHECK: TypeAliasDecl {{.*}} alias_c1_ptr '__generic c1 *'
25 using alias_c1_ptr = c1 *;
26
27 struct c2 {
28 alias_c1 y;
29 alias_c1_ptr ptr = &y;
30 };
31
32
33 // Addr spaces for pointee of dependent types are not deduced
34 // during parsing but during template instantiation instead.
35
36 template <class T>
37 struct x1 {
38 //CHECK: -CXXMethodDecl {{.*}} operator= 'x1<T> &(const x1<T> &){{( __attribute__.*)?}} __generic'
39 //CHECK: -CXXMethodDecl {{.*}} operator= '__generic x1<int> &(const __generic x1<int> &__private){{( __attribute__.*)?}} __generic'
40 x1<T>& operator=(const x1<T>& xx) {
41 y = xx.y;
42 return *this;
43 }
44 int y;
45 };
46
47 template <class T>
48 struct x2 {
49 //CHECK: -CXXMethodDecl {{.*}} foo 'void (x1<T> *){{( __attribute__.*)?}} __generic'
50 //CHECK: -CXXMethodDecl {{.*}} foo 'void (__generic x1<int> *__private){{( __attribute__.*)?}} __generic'
51 void foo(x1<T>* xx) {
52 m[0] = *xx;
53 }
54 //CHECK: -FieldDecl {{.*}} m 'x1<int>[2]'
55 x1<T> m[2];
56 };
57
58 void bar(__global x1<int> *xx, __global x2<int> *bar) {
59 bar->foo(xx);
60 }
61
62 template <typename T>
63 class x3 : public T {
64 public:
65 //CHECK: -CXXConstructorDecl {{.*}} x3<T> 'void (const x3<T> &){{( __attribute__.*)?}} __generic'
66 x3(const x3 &t);
67 };
68 //CHECK: -CXXConstructorDecl {{.*}} x3<T> 'void (const x3<T> &){{( __attribute__.*)?}} __generic'
69 template <typename T>
70 x3<T>::x3(const x3<T> &t) {}
71
72 template <class T>
73 T xxx(T *in1, T in2) {
74 // This pointer can't be deduced to generic because addr space
75 // will be taken from the template argument.
76 //CHECK: `-VarDecl {{.*}} 'T *' cinit
77 //CHECK: `-VarDecl {{.*}} i '__private int *__private' cinit
78 T *i = in1;
79 T ii;
80 __private T *ptr = &ii;
81 ptr = &in2;
82 return *i;
83 }
84
85 __kernel void test() {
86 int foo[10];
87 xxx<__private int>(&foo[0], foo[0]);
88 // FIXME: Template param deduction fails here because
89 // temporaries are not in the __private address space.
90 // It is probably reasonable to put them in __private
91 // considering that stack and function params are
92 // implicitly in __private.
93 // However, if temporaries are left in default addr
94 // space we should at least pretty print the __private
95 // addr space. Otherwise diagnostic apprears to be
96 // confusing.
97 //xxx(&foo[0], foo[0]);
98 }
99
100 // Addr space for pointer/reference to an array
101 //CHECK: FunctionDecl {{.*}} t1 'void (const float (__generic &__private)[2])'
102 void t1(const float (&fYZ)[2]);
103 //CHECK: FunctionDecl {{.*}} t2 'void (const float (__generic *__private)[2])'
104 void t2(const float (*fYZ)[2]);
105 //CHECK: FunctionDecl {{.*}} t3 'void (float (((__generic *__private)))[2])'
106 void t3(float(((*fYZ)))[2]);
107 //CHECK: FunctionDecl {{.*}} t4 'void (float (((__generic *__generic *__private)))[2])'
108 void t4(float(((**fYZ)))[2]);
109 //CHECK: FunctionDecl {{.*}} t5 'void (float (__generic *(__generic *__private))[2])'
110 void t5(float (*(*fYZ))[2]);
111
112 __kernel void k() {
113 __local float x[2];
114 float(*p)[2];
115 t1(x);
116 t2(&x);
117 t3(&x);
118 t4(&p);
119 t5(&p);
120 long f1 = foo1<long>;
121 }