Skip to content

Commit

Permalink
[OpenMP][DeviceRTL] Fix an issue that thread array might be corrupted
Browse files Browse the repository at this point in the history
The shared memory stack in the device runtime assumes no intervined uses.
D135037 breaks the assumption, potentially causing the shared stack corruption.
This patch moves the thread array to heap memory. Since it is already the slow
path, it doesn't matter that much anyway.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D135391
  • Loading branch information
shiltian committed Oct 6, 2022
1 parent b9898e7 commit 32dc480
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions openmp/libomptarget/DeviceRTL/src/State.cpp
Expand Up @@ -263,11 +263,11 @@ void state::enterDataEnvironment(IdentTy *Ident) {
if (!atomic::load(ThreadStatesBitsPtr, atomic::seq_cst)) {
uint32_t Bytes = sizeof(ThreadStates[0]) * mapping::getBlockSize();
void *ThreadStatesPtr =
memory::allocShared(Bytes, "Thread state array allocation");
memory::allocGlobal(Bytes, "Thread state array allocation");
if (!atomic::cas(ThreadStatesBitsPtr, uintptr_t(0),
reinterpret_cast<uintptr_t>(ThreadStatesPtr),
atomic::seq_cst, atomic::seq_cst))
memory::freeShared(ThreadStatesPtr, Bytes,
memory::freeGlobal(ThreadStatesPtr, Bytes,
"Thread state array allocated multiple times");
ASSERT(atomic::load(ThreadStatesBitsPtr, atomic::seq_cst) &&
"Expected valid thread states bit!");
Expand Down

0 comments on commit 32dc480

Please sign in to comment.