[Openmp-commits] [PATCH] D111946: [OpenMP][FIX] Do not dereference a potential nullptr

Johannes Doerfert via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Sat Oct 16 12:21:52 PDT 2021


jdoerfert created this revision.
jdoerfert added reviewers: tianshilei1992, jhuber6.
Herald added subscribers: guansong, bollu, yaxunl.
jdoerfert requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: OpenMP.

The first thread state in the new GPU runtime doesn't have a previous
one and we should not dereference the nullptr placeholder.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111946

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


Index: openmp/libomptarget/DeviceRTL/src/State.cpp
===================================================================
--- openmp/libomptarget/DeviceRTL/src/State.cpp
+++ openmp/libomptarget/DeviceRTL/src/State.cpp
@@ -263,9 +263,9 @@
     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 @@
   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;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111946.380204.patch
Type: text/x-patch
Size: 879 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20211016/a17c5b00/attachment.bin>


More information about the Openmp-commits mailing list