[llvm-branch-commits] [clang] [llvm] [clang][OpenMP] Emit lastprivate final copies in no-loop kernels (PR #224045)

Nicole Aschenbrenner via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Oct 30 01:26:11 PDT 2026


================
@@ -72,6 +72,48 @@ int main(void) {
   if (red != 1024)
     ++errors;
 
+  // No-loop kernel with a lastprivate variable (final value from thread executing last iteration)
+  for (int i = 0; i < 1024; ++i)
+    array[i] = 1;
+
+  int last = -1;
+#pragma omp target teams distribute parallel for lastprivate(last)
+  for (int i = 0; i < 1024; ++i) {
+    array[i] = i + 1;
+    last = i;
+  }
+  errors += check_errors(array);
+#ifdef ASSERT_LASTPRIVATE
----------------
nicebert wrote:

The assertions on the final value are guarded because they can't pass with current clang, independent of this PR. A scalar lastprivate on a combined target construct is currently passed to the kernel by value, so its final value is never copied back to the host.
Since OpenMP 5.0, list items in a reduction, lastprivate or linear clause on a combined target construct should be treated as if they were mapped as tofrom. This was implemented for reduction items but not for lastprivate, and there is an open issue for it (since 2021): llvm/llvm-project#49496. I intentionally did not fix it in this PR.
I can either drop the guarded checks until the issue is fixed, or keep them and add an explicit map(tofrom: last) to the pragmas so they run today. Which would you prefer?

https://github.com/llvm/llvm-project/pull/224045


More information about the llvm-branch-commits mailing list