Skip to content

Commit 4ac2c2a

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web' (1 commits)
2 parents e5a78fa + b19e2e4 commit 4ac2c2a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,15 +2122,18 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
21222122

21232123
bool handlePointerType(FieldDecl *FD, QualType FieldTy) final {
21242124
// USM allows to use raw pointers instead of buffers/accessors, but these
2125-
// pointers point to the specially allocated memory. For pointer fields we
2126-
// add a kernel argument with the same type as field but global address
2127-
// space, because OpenCL requires it.
2125+
// pointers point to the specially allocated memory. For pointer fields,
2126+
// except for function pointer fields, we add a kernel argument with the
2127+
// same type as field but global address space, because OpenCL requires it.
2128+
// Function pointers should have program address space. This is set in
2129+
// CodeGen.
21282130
QualType PointeeTy = FieldTy->getPointeeType();
21292131
Qualifiers Quals = PointeeTy.getQualifiers();
21302132
auto AS = Quals.getAddressSpace();
21312133
// Leave global_device and global_host address spaces as is to help FPGA
21322134
// device in memory allocations
2133-
if (AS != LangAS::sycl_global_device && AS != LangAS::sycl_global_host)
2135+
if (!PointeeTy->isFunctionType() && AS != LangAS::sycl_global_device &&
2136+
AS != LangAS::sycl_global_host)
21342137
Quals.setAddressSpace(LangAS::sycl_global);
21352138
PointeeTy = SemaRef.getASTContext().getQualifiedType(
21362139
PointeeTy.getUnqualifiedType(), Quals);

clang/test/CodeGenSYCL/functionptr-addrspace.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,16 @@ int main() {
2121
invoke_function(r, &a);
2222
invoke_function(f, &a);
2323
});
24+
25+
// Test function pointer as kernel argument. Function pointers should have program address space i.e. 0.
26+
27+
int (*fptr)();
28+
int *ptr;
29+
30+
// define dso_local spir_kernel void @{{.*}}fake_kernel_2{{.*}}(i32 ()* align 4 %_arg_fptr, i32 addrspace(1)* align 4 %_arg_ptr)
31+
kernel_single_task<class fake_kernel_2>([=]() {
32+
invoke_function(fptr, ptr);
33+
});
34+
2435
return 0;
2536
}

0 commit comments

Comments
 (0)