[Openmp-commits] [openmp] aab62aa - [OpenMP][Offloading] Fixed a crash caused by dereferencing nullptr

Shilei Tian via Openmp-commits openmp-commits at lists.llvm.org
Wed Jan 5 20:04:38 PST 2022


Author: Shilei Tian
Date: 2022-01-05T23:04:29-05:00
New Revision: aab62aab043162a03e2693dca1be2194bccdeee4

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

LOG: [OpenMP][Offloading] Fixed a crash caused by dereferencing nullptr

In function `DeviceTy::getTargetPointer`, `Entry` could be `nullptr` because of
zero length array section. We need to check if it is a valid iterator before
using it.

Reviewed By: ronlieb

Differential Revision: https://reviews.llvm.org/D116716

Added: 
    

Modified: 
    openmp/libomptarget/src/device.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/src/device.cpp b/openmp/libomptarget/src/device.cpp
index 75935b30520c2..738284e82f20b 100644
--- a/openmp/libomptarget/src/device.cpp
+++ b/openmp/libomptarget/src/device.cpp
@@ -305,7 +305,9 @@ DeviceTy::getTargetPointer(void *HstPtrBegin, void *HstPtrBase, int64_t Size,
     DataMapMtx.unlock();
     // If not a host pointer and no present modifier, we need to wait for the
     // event if it exists.
-    if (!IsHostPtr && !HasPresentModifier) {
+    // Note: Entry might be nullptr because of zero length array section.
+    if (Entry != HostDataToTargetListTy::iterator() && !IsHostPtr &&
+        !HasPresentModifier) {
       Entry->lock();
       void *Event = Entry->getEvent();
       if (Event) {


        


More information about the Openmp-commits mailing list