[Openmp-commits] [openmp] dc72960 - [OpenMP][FIX] Do not dereference a potential nullptr

Johannes Doerfert via Openmp-commits openmp-commits at lists.llvm.org
Wed Oct 27 16:18:52 PDT 2021


Author: Johannes Doerfert
Date: 2021-10-27T18:18:39-05:00
New Revision: dc72960967d7a440d0dfd30bbc70e4131ca5e239

URL: https://github.com/llvm/llvm-project/commit/dc72960967d7a440d0dfd30bbc70e4131ca5e239
DIFF: https://github.com/llvm/llvm-project/commit/dc72960967d7a440d0dfd30bbc70e4131ca5e239.diff

LOG: [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

Added: 
    

Modified: 
    openmp/libomptarget/DeviceRTL/src/State.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/DeviceRTL/src/State.cpp b/openmp/libomptarget/DeviceRTL/src/State.cpp
index b35b9b3e7837..538dc95ddcee 100644
--- a/openmp/libomptarget/DeviceRTL/src/State.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/State.cpp
@@ -263,9 +263,9 @@ struct ThreadStateTy {
     PreviousThreadState = nullptr;
   }
 
-  void init(ThreadStateTy &PreviousTS) {
-    ICVState = PreviousTS.ICVState;
-    PreviousThreadState = &PreviousTS;
+  void init(ThreadStateTy *PreviousTS) {
+    ICVState = PreviousTS ? PreviousTS->ICVState : TeamState.ICVState;
+    PreviousThreadState = PreviousTS;
   }
 };
 
@@ -369,7 +369,7 @@ void state::enterDataEnvironment() {
   unsigned TId = mapping::getThreadIdInBlock();
   ThreadStateTy *NewThreadState =
       static_cast<ThreadStateTy *>(__kmpc_alloc_shared(sizeof(ThreadStateTy)));
-  NewThreadState->init(*ThreadStates[TId]);
+  NewThreadState->init(ThreadStates[TId]);
   ThreadStates[TId] = NewThreadState;
 }
 


        


More information about the Openmp-commits mailing list