https://github.com/koparasy created 
https://github.com/llvm/llvm-project/pull/230327

Port clang/test/CodeGenSYCL/functionptr-addrspace.cpp to ClangIR.

>From f098d80e99bf877453d19778d5bc99626f2764be Mon Sep 17 00:00:00 2001
From: Konstantinos Parasyris <[email protected]>
Date: Thu, 8 Oct 2026 16:59:06 -0700
Subject: [PATCH] [CIR][SYCL][NFC] Add functionptr-addrspace test

Port clang/test/CodeGenSYCL/functionptr-addrspace.cpp to ClangIR.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
---
 .../CIR/CodeGenSYCL/functionptr-addrspace.cpp | 33 +++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 clang/test/CIR/CodeGenSYCL/functionptr-addrspace.cpp

diff --git a/clang/test/CIR/CodeGenSYCL/functionptr-addrspace.cpp 
b/clang/test/CIR/CodeGenSYCL/functionptr-addrspace.cpp
new file mode 100644
index 00000000000000..266dc4e18254f2
--- /dev/null
+++ b/clang/test/CIR/CodeGenSYCL/functionptr-addrspace.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fsycl-is-device -triple spir64 -verify -fclangir -emit-cir 
%s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
+// RUN: %clang_cc1 -fsycl-is-device -triple spir64 -verify -fclangir 
-emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
+// RUN: %clang_cc1 -fsycl-is-device -triple spir64 -verify -emit-llvm %s -o 
%t.ll
+// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
+
+// expected-no-diagnostics
+
+template <typename Name, typename Func>
+__attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
+  kernelFunc();
+}
+
+// Function pointers stay in the program address space (0); data pointers use
+// the generic address space (4).
+// CIR: cir.func {{.*}}@_Z15invoke_functionPFivEPi(%{{.*}}: 
!cir.ptr<!cir.func<() -> !s32i>> {{.*}}, %{{.*}}: !cir.ptr<!s32i, 
target_address_space(4)> {{.*}}) cc(spir_function)
+// LLVM: define dso_local spir_func{{.*}}invoke_function{{.*}}(ptr noundef 
%{{.*}}, ptr addrspace(4) noundef %{{.*}})
+[[clang::sycl_external]] 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;
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to