| 1 |
// RUN: %clang_cc1 %s -cl-std=CL1.0 -verify -pedantic -fsyntax-only -triple spir-unknown-unknown |
| 2 |
// RUN: %clang_cc1 %s -cl-std=CL1.0 -verify -pedantic -fsyntax-only -triple spir-unknown-unknown -DFUNCPTREXT |
| 3 |
// RUN: %clang_cc1 %s -cl-std=CL1.0 -verify -pedantic -fsyntax-only -triple spir-unknown-unknown -DVARARGEXT |
| 4 |
|
| 5 |
#ifdef FUNCPTREXT |
| 6 |
#pragma OPENCL EXTENSION __cl_clang_function_pointers : enable |
| 7 |
#endif |
| 8 |
#ifdef VARARGEXT |
| 9 |
#pragma OPENCL EXTENSION __cl_clang_variadic_functions : enable |
| 10 |
#endif |
| 11 |
|
| 12 |
// Variadic functions |
| 13 |
void vararg_f(int, ...); |
| 14 |
#ifndef VARARGEXT |
| 15 |
// expected-error@-2 {{invalid prototype, variadic arguments are not allowed in OpenCL}} |
| 16 |
#endif |
| 17 |
void __vararg_f(int, ...); |
| 18 |
typedef void (*vararg_fptr_t)(int, ...); |
| 19 |
#ifndef VARARGEXT |
| 20 |
// expected-error@-2 {{invalid prototype, variadic arguments are not allowed in OpenCL}} |
| 21 |
#endif |
| 22 |
#ifndef FUNCPTREXT |
| 23 |
// expected-error@-5 {{pointers to functions are not allowed}} |
| 24 |
#endif |
| 25 |
int printf(__constant const char *st, ...); |
| 26 |
#ifndef VARARGEXT |
| 27 |
// expected-error@-2 {{invalid prototype, variadic arguments are not allowed in OpenCL}} |
| 28 |
#endif |
| 29 |
|
| 30 |
// Struct type with function pointer field |
| 31 |
typedef struct s |
| 32 |
{ |
| 33 |
void (*f)(struct s *self, int *i); |
| 34 |
#ifndef FUNCPTREXT |
| 35 |
// expected-error@-2 {{pointers to functions are not allowed}} |
| 36 |
#endif |
| 37 |
} s_t; |
| 38 |
|
| 39 |
//Function pointer |
| 40 |
void foo(void*); |
| 41 |
#ifdef FUNCPTREXT |
| 42 |
//expected-note@-2{{passing argument to parameter here}} |
| 43 |
#endif |
| 44 |
|
| 45 |
// Expect no diagnostics for an empty parameter list. |
| 46 |
void bar(); |
| 47 |
|
| 48 |
void bar() |
| 49 |
{ |
| 50 |
// declaring a function pointer is an error |
| 51 |
void (*fptr)(int); |
| 52 |
#ifndef FUNCPTREXT |
| 53 |
// expected-error@-2 {{pointers to functions are not allowed}} |
| 54 |
#endif |
| 55 |
|
| 56 |
// taking the address of a function is an error |
| 57 |
foo((void*)foo); |
| 58 |
#ifndef FUNCPTREXT |
| 59 |
// expected-error@-2{{taking address of function is not allowed}} |
| 60 |
#else |
| 61 |
// FIXME: Functions should probably be in the address space defined by the |
| 62 |
// implementation. It might make sense to put them into the Default address |
| 63 |
// space that is bind to a physical segment by the target rather than fixing |
| 64 |
// it to any of the concrete OpenCL address spaces during parsing. |
| 65 |
// expected-error@-8{{casting 'void (*)(__private void *__private)' to type '__private void *' changes address space}} |
| 66 |
#endif |
| 67 |
|
| 68 |
foo(&foo); |
| 69 |
#ifndef FUNCPTREXT |
| 70 |
// expected-error@-2{{taking address of function is not allowed}} |
| 71 |
#else |
| 72 |
// expected-error@-4{{passing 'void (*)(__private void *__private)' to parameter of type '__private void *' changes address space of pointer}} |
| 73 |
#endif |
| 74 |
|
| 75 |
// FIXME: If we stop rejecting the line below a bug (PR49315) gets |
| 76 |
// hit due to incorrectly handled pointer conversion. |
| 77 |
#ifndef FUNCPTREXT |
| 78 |
// initializing an array with the address of functions is an error |
| 79 |
void* vptrarr[2] = {foo, &foo}; // expected-error{{taking address of function is not allowed}} expected-error{{taking address of function is not allowed}} |
| 80 |
#endif |
| 81 |
|
| 82 |
// just calling a function is correct |
| 83 |
foo(0); |
| 84 |
} |