blob: 83c3b4a6bcf9089074d270a74d06ea7fe1f1b208 [file] [log] [blame]
Alexey Bader1f277942017-10-11 11:16:31 +00001// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -triple spir-unknown-unknown
Pekka Jaaskelainen8690a682014-02-20 13:52:08 +00002
Anastasia Stulova7c305332016-10-28 12:59:39 +00003// Variadic functions
4void vararg_f(int, ...); // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}}
5void __vararg_f(int, ...);
6typedef void (*vararg_fptr_t)(int, ...); // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}}
Alexey Bader037dbe952017-06-02 18:08:58 +00007 // expected-error@-1{{pointers to functions are not allowed}}
Anastasia Stulova7c305332016-10-28 12:59:39 +00008int printf(__constant const char *st, ...); // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}}
9
Alexey Bader037dbe952017-06-02 18:08:58 +000010// Struct type with function pointer field
11typedef struct s
12{
13 void (*f)(struct s *self, int *i); // expected-error{{pointers to functions are not allowed}}
14} s_t;
15
Anastasia Stulova7c305332016-10-28 12:59:39 +000016//Function pointer
Pekka Jaaskelainen8690a682014-02-20 13:52:08 +000017void foo(void*);
18
Alexey Bader1f277942017-10-11 11:16:31 +000019// Expect no diagnostics for an empty parameter list.
20void bar();
21
Pekka Jaaskelainen8690a682014-02-20 13:52:08 +000022void bar()
23{
24 // declaring a function pointer is an error
25 void (*fptr)(int); // expected-error{{pointers to functions are not allowed}}
26
27 // taking the address of a function is an error
28 foo((void*)foo); // expected-error{{taking address of function is not allowed}}
29 foo(&foo); // expected-error{{taking address of function is not allowed}}
30
Anastasia Stulovacf04d042016-01-05 14:39:27 +000031 // initializing an array with the address of functions is an error
32 void* vptrarr[2] = {foo, &foo}; // expected-error{{taking address of function is not allowed}} expected-error{{taking address of function is not allowed}}
33
Pekka Jaaskelainen8690a682014-02-20 13:52:08 +000034 // just calling a function is correct
35 foo(0);
36}