File: func.cl

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (84 lines) | stat: -rw-r--r-- 2,923 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// RUN: %clang_cc1 %s -cl-std=CL1.0 -verify -pedantic -fsyntax-only -triple spir-unknown-unknown
// RUN: %clang_cc1 %s -cl-std=CL1.0 -verify -pedantic -fsyntax-only -triple spir-unknown-unknown -DFUNCPTREXT
// RUN: %clang_cc1 %s -cl-std=CL1.0 -verify -pedantic -fsyntax-only -triple spir-unknown-unknown -DVARARGEXT

#ifdef FUNCPTREXT
#pragma OPENCL EXTENSION __cl_clang_function_pointers : enable
#endif
#ifdef VARARGEXT
#pragma OPENCL EXTENSION __cl_clang_variadic_functions : enable
#endif

// Variadic functions
void vararg_f(int, ...);
#ifndef VARARGEXT
// expected-error@-2 {{invalid prototype, variadic arguments are not allowed in OpenCL}}
#endif
void __vararg_f(int, ...);
typedef void (*vararg_fptr_t)(int, ...);
#ifndef VARARGEXT
// expected-error@-2 {{invalid prototype, variadic arguments are not allowed in OpenCL}}
#endif
#ifndef FUNCPTREXT
// expected-error@-5 {{pointers to functions are not allowed}}
#endif
int printf(__constant const char *st, ...);
#ifndef VARARGEXT
// expected-error@-2 {{invalid prototype, variadic arguments are not allowed in OpenCL}}
#endif

// Struct type with function pointer field
typedef struct s
{
   void (*f)(struct s *self, int *i);
#ifndef FUNCPTREXT
// expected-error@-2 {{pointers to functions are not allowed}}
#endif
} s_t;

//Function pointer
void foo(void*);
#ifdef FUNCPTREXT
//expected-note@-2{{passing argument to parameter here}}
#endif

// Expect no diagnostics for an empty parameter list.
void bar();

void bar()
{
  // declaring a function pointer is an error
  void (*fptr)(int);
#ifndef FUNCPTREXT
  // expected-error@-2 {{pointers to functions are not allowed}}
#endif

  // taking the address of a function is an error
  foo((void*)foo);
#ifndef FUNCPTREXT
  // expected-error@-2{{taking address of function is not allowed}}
#else
  // FIXME: Functions should probably be in the address space defined by the
  // implementation. It might make sense to put them into the Default address
  // space that is bind to a physical segment by the target rather than fixing
  // it to any of the concrete OpenCL address spaces during parsing.
  // expected-error@-8{{casting 'void (*)(__private void *__private)' to type '__private void *' changes address space}}
#endif

  foo(&foo);
#ifndef FUNCPTREXT
  // expected-error@-2{{taking address of function is not allowed}}
#else
  // expected-error@-4{{passing 'void (*)(__private void *__private)' to parameter of type '__private void *' changes address space of pointer}}
#endif

  // FIXME: If we stop rejecting the line below a bug (PR49315) gets
  // hit due to incorrectly handled pointer conversion.
#ifndef FUNCPTREXT
  // initializing an array with the address of functions is an error
  void* vptrarr[2] = {foo, &foo}; // expected-error{{taking address of function is not allowed}} expected-error{{taking address of function is not allowed}}
#endif

  // just calling a function is correct
  foo(0);
}