[Openmp-commits] [PATCH] D105947: [libomptarget] Keep the Shadow Pointer Map up-to-date

George Rokos via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Tue Jul 13 15:46:41 PDT 2021


grokos created this revision.
grokos added reviewers: tianshilei1992, jdenny.
grokos added a project: OpenMP.
grokos requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

D105812 <https://reviews.llvm.org/D105812> introduced a regression where if a PTR_AND_OBJ entry was mapped on the device, later the OBJ was deallocated and then reallocated at a different address, the Shadow Pointer Map would still contain an entry for the PTR but pointing to the old address. This caused test `env/base_ptr_ref_count.c` to fail.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105947

Files:
  openmp/libomptarget/src/omptarget.cpp


Index: openmp/libomptarget/src/omptarget.cpp
===================================================================
--- openmp/libomptarget/src/omptarget.cpp
+++ openmp/libomptarget/src/omptarget.cpp
@@ -564,9 +564,12 @@
 
       Device.ShadowMtx.lock();
       auto Entry = Device.ShadowPtrMap.find(Pointer_HstPtrBegin);
-      // If this pointer is not in the map we need to insert it.
-      if (Entry == Device.ShadowPtrMap.end()) {
-        // create shadow pointers for this entry
+      // If this pointer is not in the map we need to insert it. If the map
+      // contains a stale entry, we need to update it (e.g. if the pointee was
+      // deallocated and later on is reallocated at another device address).
+      if (Entry == Device.ShadowPtrMap.end() ||
+          Entry->second.TgtPtrVal != ExpectedTgtPtrBase) {
+        // create or update shadow pointers for this entry
         Device.ShadowPtrMap[Pointer_HstPtrBegin] = {
             HstPtrBase, PointerTgtPtrBegin, ExpectedTgtPtrBase};
         UpdateDevPtr = true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105947.358450.patch
Type: text/x-patch
Size: 1038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210713/6dd59491/attachment.bin>


More information about the Openmp-commits mailing list