[llvm] [OpenMP] Fix race in setupIndirectCallTable (PR #215274)

Alex Duran via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 06:35:26 PDT 2026


https://github.com/adurang created https://github.com/llvm/llvm-project/pull/215274

The IndirectCallTable variable where the table is constructed is a local variable. The copy to the device is right now not synchronized, so the frame where the table resides can be overwritten before the GPU copy has accessed the host data which corrupts the device side table.

Fix it by make it a synchronous operation.

>From 8ebf2c6a3702d97cc72addb6fbb2b986e4b5751d Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Mon, 10 Aug 2026 06:28:44 -0700
Subject: [PATCH] [OpenMP] Fix race in setupIndirectCallTable

The IndirectCallTable variable where the table is constructed is allocated
on the stack. The copy to the device is right now not synchronized, so
the frame where the table resides can be overwritten before the GPU
copy has accessed the host data.

Fix it by make it a synchronous operation.
---
 offload/libomptarget/device.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/offload/libomptarget/device.cpp b/offload/libomptarget/device.cpp
index 18339e9afe975..aaeeca69844e7 100644
--- a/offload/libomptarget/device.cpp
+++ b/offload/libomptarget/device.cpp
@@ -200,6 +200,12 @@ setupIndirectCallTable(DeviceTy &Device, __tgt_device_image *Image,
                         AsyncInfo))
     return error::createOffloadError(error::ErrorCode::INVALID_BINARY,
                                      "failed to copy data");
+  // The IndirectCallTable is on the stack, so we must syncronize to ensure
+  // the data is copied before we return.
+  if (Device.synchronize(AsyncInfo))
+    return error::createOffloadError(error::ErrorCode::INVALID_BINARY,
+                                     "failed to synchronize after copying data");
+
   return std::pair<void *, uint64_t>(DevicePtr, IndirectCallTable.size());
 }
 



More information about the llvm-commits mailing list