diff --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp --- a/openmp/libomptarget/src/omptarget.cpp +++ b/openmp/libomptarget/src/omptarget.cpp @@ -802,6 +802,10 @@ // If we copied the struct to the host, we need to restore the pointer. if (ArgTypes[I] & OMP_TGT_MAPTYPE_FROM) { void **ShadowHstPtrAddr = (void **)Itr->first; + // Wait for device-to-host memcopies for whole struct to complete, + // before restoring the correct host pointer. + if (AsyncInfo.synchronize() != OFFLOAD_SUCCESS) + return OFFLOAD_FAIL; *ShadowHstPtrAddr = Itr->second.HstPtrVal; DP("Restoring original host pointer value " DPxMOD " for host " "pointer " DPxMOD "\n", @@ -885,6 +889,10 @@ auto CB = [&](ShadowPtrListTy::iterator &Itr) { void **ShadowHstPtrAddr = (void **)Itr->first; + // Wait for device-to-host memcopies for whole struct to complete, + // before restoring the correct host pointer. + if (AsyncInfo.synchronize() != OFFLOAD_SUCCESS) + return OFFLOAD_FAIL; *ShadowHstPtrAddr = Itr->second.HstPtrVal; DP("Restoring original host pointer value " DPxMOD " for host pointer " DPxMOD "\n",