brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 233e82f Raw
85 lines · plain
1// RUN: %clang_cc1 %s -cl-std=CL1.0 -verify -pedantic -fsyntax-only -triple spir-unknown-unknown2// RUN: %clang_cc1 %s -cl-std=CL1.0 -verify -pedantic -fsyntax-only -triple spir-unknown-unknown -DFUNCPTREXT3// RUN: %clang_cc1 %s -cl-std=CL1.0 -verify -pedantic -fsyntax-only -triple spir-unknown-unknown -DVARARGEXT4 5#ifdef FUNCPTREXT6#pragma OPENCL EXTENSION __cl_clang_function_pointers : enable7#endif8#ifdef VARARGEXT9#pragma OPENCL EXTENSION __cl_clang_variadic_functions : enable10#endif11 12// Variadic functions13void vararg_f(int, ...);14#ifndef VARARGEXT15// expected-error@-2 {{invalid prototype, variadic arguments are not allowed in OpenCL}}16#endif17void __vararg_f(int, ...);18typedef void (*vararg_fptr_t)(int, ...);19#ifndef VARARGEXT20// expected-error@-2 {{invalid prototype, variadic arguments are not allowed in OpenCL}}21#endif22#ifndef FUNCPTREXT23// expected-error@-5 {{pointers to functions are not allowed}}24#endif25int printf(__constant const char *st, ...);26#ifndef VARARGEXT27// expected-error@-2 {{invalid prototype, variadic arguments are not allowed in OpenCL}}28#endif29 30// Struct type with function pointer field31typedef struct s32{33   void (*f)(struct s *self, int *i);34#ifndef FUNCPTREXT35// expected-error@-2 {{pointers to functions are not allowed}}36#endif37} s_t;38 39//Function pointer40void foo(void*);41#ifdef FUNCPTREXT42//expected-note@-2{{passing argument to parameter here}}43#endif44 45// Expect no diagnostics for an empty parameter list.46void bar();47 48void bar()49{50  // declaring a function pointer is an error51  void (*fptr)(int);52#ifndef FUNCPTREXT53  // expected-error@-2 {{pointers to functions are not allowed}}54#endif55 56  // taking the address of a function is an error57  foo((void*)foo);58#ifndef FUNCPTREXT59  // expected-error@-2{{taking address of function is not allowed}}60#else61  // FIXME: Functions should probably be in the address space defined by the62  // implementation. It might make sense to put them into the Default address63  // space that is bind to a physical segment by the target rather than fixing64  // 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#endif67 68  foo(&foo);69#ifndef FUNCPTREXT70  // expected-error@-2{{taking address of function is not allowed}}71#else72  // expected-error@-4{{passing 'void (*)(__private void *__private)' to parameter of type '__private void *' changes address space of pointer}}73#endif74 75  // FIXME: If we stop rejecting the line below a bug (PR49315) gets76  // hit due to incorrectly handled pointer conversion.77#ifndef FUNCPTREXT78  // initializing an array with the address of functions is an error79  void* vptrarr[2] = {foo, &foo}; // expected-error{{taking address of function is not allowed}} expected-error{{taking address of function is not allowed}}80#endif81 82  // just calling a function is correct83  foo(0);84}85