xref: /llvm-project/clang/test/CodeGenSYCL/functionptr-addrspace.cpp (revision 7c1d9b15eee3a34678addab2bab66f3020ac0753)
1*7c1d9b15SFangrui Song // RUN: %clang_cc1 -fsycl-is-device -triple spir64 -verify -emit-llvm %s -o - | FileCheck %s
24eaf5846SElizabeth Andrews 
34eaf5846SElizabeth Andrews // expected-no-diagnostics
44eaf5846SElizabeth Andrews 
54eaf5846SElizabeth Andrews template <typename Name, typename Func>
kernel_single_task(const Func & kernelFunc)64eaf5846SElizabeth Andrews __attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
74eaf5846SElizabeth Andrews   kernelFunc();
84eaf5846SElizabeth Andrews }
94eaf5846SElizabeth Andrews 
109466b491SNikita Popov // CHECK: define dso_local spir_func{{.*}}invoke_function{{.*}}(ptr noundef %fptr, ptr addrspace(4) noundef %ptr)
invoke_function(int (* fptr)(),int * ptr)114eaf5846SElizabeth Andrews void invoke_function(int (*fptr)(), int *ptr) {}
124eaf5846SElizabeth Andrews 
f()134eaf5846SElizabeth Andrews int f() { return 0; }
144eaf5846SElizabeth Andrews 
main()154eaf5846SElizabeth Andrews int main() {
164eaf5846SElizabeth Andrews   kernel_single_task<class fake_kernel>([=]() {
174eaf5846SElizabeth Andrews     int (*p)() = f;
184eaf5846SElizabeth Andrews     int (&r)() = *p;
194eaf5846SElizabeth Andrews     int a = 10;
204eaf5846SElizabeth Andrews     invoke_function(p, &a);
214eaf5846SElizabeth Andrews     invoke_function(r, &a);
224eaf5846SElizabeth Andrews     invoke_function(f, &a);
234eaf5846SElizabeth Andrews   });
244eaf5846SElizabeth Andrews   return 0;
254eaf5846SElizabeth Andrews }
26