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