| 1 |
// RUN: %clang_cc1 %s -pedantic -verify -fsyntax-only -triple spir-unknown-unknown |
| 2 |
// RUN: %clang_cc1 %s -pedantic -verify -fsyntax-only -triple spir-unknown-unknown -DUNSAFEKERNELPARAMETER |
| 3 |
|
| 4 |
#ifdef UNSAFEKERNELPARAMETER |
| 5 |
#pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : enable |
| 6 |
#endif |
| 7 |
|
| 8 |
struct C { |
| 9 |
kernel void m(); //expected-error{{kernel functions cannot be class members}} |
| 10 |
}; |
| 11 |
|
| 12 |
template <typename T> |
| 13 |
//expected-error@+1{{'T' cannot be used as the type of a kernel parameter}} |
| 14 |
kernel void templ(T par) { //expected-error{{kernel functions cannot be used in a template declaration, instantiation or specialization}} |
| 15 |
} |
| 16 |
|
| 17 |
template <int> |
| 18 |
kernel void bar(int par) { //expected-error{{kernel functions cannot be used in a template declaration, instantiation or specialization}} |
| 19 |
} |
| 20 |
|
| 21 |
kernel void foo(int); //expected-note{{previous declaration is here}} |
| 22 |
|
| 23 |
kernel void foo(float); //expected-error{{conflicting types for 'foo'}} |
| 24 |
|
| 25 |
kernel void int_v(int in); |
| 26 |
kernel void int_p(__global int *in); |
| 27 |
kernel void int_r(__global int &in); |
| 28 |
kernel void int_p_p(__global int *__global *in); |
| 29 |
kernel void int_p_r(__global int *__global &in); |
| 30 |
kernel void int_p_p_r(__global int *__global *__global &in); |
| 31 |
|
| 32 |
kernel void k_atomic_v(atomic_int in); |
| 33 |
#ifndef UNSAFEKERNELPARAMETER |
| 34 |
// expected-error@-2{{'__private atomic_int' (aka '__private _Atomic(int)') cannot be used as the type of a kernel parameter}} |
| 35 |
#endif |
| 36 |
kernel void k_atomic_p(__global atomic_int *in); |
| 37 |
kernel void k_atomic_r(__global atomic_int &in); |
| 38 |
|
| 39 |
kernel void k_pipe(read_only pipe int in, write_only pipe int out); |
| 40 |
kernel void k_sampler(sampler_t in); |
| 41 |
kernel void k_void(__global void *in); |
| 42 |
|
| 43 |
typedef int int4 __attribute__((ext_vector_type(4))); |
| 44 |
|
| 45 |
kernel void int4_v(int4 in); |
| 46 |
kernel void int4_p(__global int4 *in); |
| 47 |
kernel void int4_p_p(__global int4 *__global *in); |
| 48 |
kernel void int4_r(__global int4 &in); |
| 49 |
|
| 50 |
struct POD { |
| 51 |
int a; |
| 52 |
int b; |
| 53 |
}; |
| 54 |
|
| 55 |
kernel void pod_v(POD in) {} |
| 56 |
kernel void pod_p(__global POD *in) {} |
| 57 |
kernel void pod_p_p(__global POD *__global *in) {} |
| 58 |
kernel void pod_r(__global POD &in) {} |
| 59 |
|
| 60 |
struct StandardLayout { |
| 61 |
int a; |
| 62 |
int b; |
| 63 |
StandardLayout(int a, int b) : a(a), b(b) {} |
| 64 |
}; |
| 65 |
|
| 66 |
kernel void standard_v(StandardLayout in) {} |
| 67 |
#ifndef UNSAFEKERNELPARAMETER |
| 68 |
//expected-error@-2{{'__private StandardLayout' cannot be used as the type of a kernel parameter}} |
| 69 |
#endif |
| 70 |
kernel void standard_p(__global StandardLayout *in) {} |
| 71 |
kernel void standard_p_p(__global StandardLayout *__global *in) {} |
| 72 |
kernel void standard_r(__global StandardLayout &in) {} |
| 73 |
|
| 74 |
struct Trivial { |
| 75 |
int a; |
| 76 |
private: |
| 77 |
int b; |
| 78 |
}; |
| 79 |
|
| 80 |
kernel void trivial_v(Trivial in) {} |
| 81 |
#ifndef UNSAFEKERNELPARAMETER |
| 82 |
//expected-error@-2{{'__private Trivial' cannot be used as the type of a kernel parameter}} |
| 83 |
#endif |
| 84 |
kernel void trivial_p(__global Trivial *in) {} |
| 85 |
#ifndef UNSAFEKERNELPARAMETER |
| 86 |
//expected-error@-2{{'__global Trivial *__private' cannot be used as the type of a kernel parameter}} |
| 87 |
#endif |
| 88 |
kernel void trivial_p_p(__global Trivial *__global *in) {} |
| 89 |
#ifndef UNSAFEKERNELPARAMETER |
| 90 |
//expected-error@-2{{'__global Trivial *__global *__private' cannot be used as the type of a kernel parameter}} |
| 91 |
#endif |
| 92 |
kernel void trivial_r(__global Trivial &in) {} |
| 93 |
#ifndef UNSAFEKERNELPARAMETER |
| 94 |
//expected-error@-2{{'__global Trivial &__private' cannot be used as the type of a kernel parameter}} |
| 95 |
#endif |
| 96 |
|
| 97 |
// Nested types and templates |
| 98 |
struct Outer { |
| 99 |
struct Inner{ |
| 100 |
int i; |
| 101 |
}; |
| 102 |
}; |
| 103 |
template<class T> |
| 104 |
struct OuterTempl { |
| 105 |
struct Inner{ |
| 106 |
int i; |
| 107 |
}; |
| 108 |
}; |
| 109 |
// FIXME: (PR58590) Use of template parameter dependent types doesn't |
| 110 |
// work yet due to lazy instantiation of reference types. |
| 111 |
//template<class T> |
| 112 |
//struct Templ { |
| 113 |
//T i; |
| 114 |
//}; |
| 115 |
|
| 116 |
extern kernel void nested(constant Outer::Inner& r1, constant OuterTempl<int>::Inner& r2/*, constant Templ<int>& r3*/); |