You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[OpenCL] Allow taking address of functions as an extension.
When '__cl_clang_function_pointers' extension is enabled the parser should allow obtaining the function address. This fixes PR49264! Differential Revision: https://reviews.llvm.org/D97203
Copy file name to clipboardExpand all lines: clang/test/SemaOpenCL/func.cl
+24-2Lines changed: 24 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -38,6 +38,9 @@ typedef struct s
38
38
39
39
//Function pointer
40
40
voidfoo(void*);
41
+
#ifdefFUNCPTREXT
42
+
//expected-note@-2{{passing argument to parameter here}}
43
+
#endif
41
44
42
45
// Expect no diagnostics for an empty parameter list.
43
46
voidbar();
@@ -51,11 +54,30 @@ void bar()
51
54
#endif
52
55
53
56
// taking the address of a function is an error
54
-
foo((void*)foo); // expected-error{{taking address of function is not allowed}}
55
-
foo(&foo); // expected-error{{taking address of function is not allowed}}
57
+
foo((void*)foo);
58
+
#ifndefFUNCPTREXT
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
56
67
68
+
foo(&foo);
69
+
#ifndefFUNCPTREXT
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
+
#ifndefFUNCPTREXT
57
78
// initializing an array with the address of functions is an error
58
79
void*vptrarr[2] = {foo, &foo}; // expected-error{{taking address of function is not allowed}} expected-error{{taking address of function is not allowed}}
0 commit comments