[PATCH] D111566: [SYCL] Fix function pointer address space

Elizabeth Andrews via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 13 17:25:41 PDT 2021


eandrews updated this revision to Diff 379562.
eandrews added a comment.

Added a test


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111566/new/

https://reviews.llvm.org/D111566

Files:
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/test/CodeGenSYCL/functionptr-addressspace.cpp


Index: clang/test/CodeGenSYCL/functionptr-addressspace.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenSYCL/functionptr-addressspace.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsycl-is-device -emit-llvm -triple spir64 -verify -emit-llvm %s -o - | FileCheck %s
+
+// expected-no-diagnostics
+
+template <typename Name, typename Func>
+__attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
+  kernelFunc();
+}
+
+// CHECK: define dso_local spir_func{{.*}}invoke_function{{.*}}(i32 ()* %fptr, i32 addrspace(4)* %ptr)
+void invoke_function(int (*fptr)(), int *ptr) {}
+
+int f() { return 0; }
+
+int main() {
+  kernel_single_task<class fake_kernel>([=]() {
+    int (*p)() = f;
+    int (&r)() = *p;
+    int a = 10;
+    invoke_function(p, &a);
+    invoke_function(r, &a);
+    invoke_function(f, &a);
+  });
+  return 0;
+}
Index: clang/lib/CodeGen/CodeGenTypes.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenTypes.cpp
+++ clang/lib/CodeGen/CodeGenTypes.cpp
@@ -633,7 +633,9 @@
     const ReferenceType *RTy = cast<ReferenceType>(Ty);
     QualType ETy = RTy->getPointeeType();
     llvm::Type *PointeeType = ConvertTypeForMem(ETy);
-    unsigned AS = Context.getTargetAddressSpace(ETy);
+    unsigned AS = PointeeType->isFunctionTy()
+                      ? getDataLayout().getProgramAddressSpace()
+                      : Context.getTargetAddressSpace(ETy);
     ResultType = llvm::PointerType::get(PointeeType, AS);
     break;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111566.379562.patch
Type: text/x-patch
Size: 1576 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211014/0fa99c68/attachment.bin>


More information about the cfe-commits mailing list