Skip to content

Commit dc72960

Browse files
committed
[OpenMP][FIX] Do not dereference a potential nullptr
The first thread state in the new GPU runtime doesn't have a previous one and we should not dereference the nullptr placeholder. Reviewed By: tianshilei1992 Differential Revision: https://reviews.llvm.org/D111946
1 parent b291597 commit dc72960

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

openmp/libomptarget/DeviceRTL/src/State.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ struct ThreadStateTy {
263263
PreviousThreadState = nullptr;
264264
}
265265

266-
void init(ThreadStateTy &PreviousTS) {
267-
ICVState = PreviousTS.ICVState;
268-
PreviousThreadState = &PreviousTS;
266+
void init(ThreadStateTy *PreviousTS) {
267+
ICVState = PreviousTS ? PreviousTS->ICVState : TeamState.ICVState;
268+
PreviousThreadState = PreviousTS;
269269
}
270270
};
271271

@@ -369,7 +369,7 @@ void state::enterDataEnvironment() {
369369
unsigned TId = mapping::getThreadIdInBlock();
370370
ThreadStateTy *NewThreadState =
371371
static_cast<ThreadStateTy *>(__kmpc_alloc_shared(sizeof(ThreadStateTy)));
372-
NewThreadState->init(*ThreadStates[TId]);
372+
NewThreadState->init(ThreadStates[TId]);
373373
ThreadStates[TId] = NewThreadState;
374374
}
375375

0 commit comments

Comments
 (0)