Skip to content

Commit b06471a

Browse files
George Rokosmemfrob
authored andcommitted
[libomptarget] Keep the Shadow Pointer Map up-to-date
D105812 introduced a regression where if a PTR_AND_OBJ entry was mapped on the device, then 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. Differential Revision: https://reviews.llvm.org/D105947
1 parent 102ca41 commit b06471a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

openmp/libomptarget/src/omptarget.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,20 @@ int targetDataBegin(ident_t *loc, DeviceTy &Device, int32_t arg_num,
564564

565565
Device.ShadowMtx.lock();
566566
auto Entry = Device.ShadowPtrMap.find(Pointer_HstPtrBegin);
567-
// If this pointer is not in the map we need to insert it.
568-
if (Entry == Device.ShadowPtrMap.end()) {
569-
// create shadow pointers for this entry
567+
// If this pointer is not in the map we need to insert it. If the map
568+
// contains a stale entry, we need to update it (e.g. if the pointee was
569+
// deallocated and later on is reallocated at another device address). The
570+
// latter scenario is the subject of LIT test env/base_ptr_ref_count.c. An
571+
// entry is removed from ShadowPtrMap only when the PTR of a PTR_AND_OBJ
572+
// pair is deallocated, not when the OBJ is deallocated. In
573+
// env/base_ptr_ref_count.c the PTR is a global "declare target" pointer,
574+
// so it stays in the map for the lifetime of the application. When the
575+
// OBJ is deallocated and later on allocated again (at a different device
576+
// address), ShadowPtrMap still contains an entry for Pointer_HstPtrBegin
577+
// which is stale, pointing to the old ExpectedTgtPtrBase of the OBJ.
578+
if (Entry == Device.ShadowPtrMap.end() ||
579+
Entry->second.TgtPtrVal != ExpectedTgtPtrBase) {
580+
// create or update shadow pointers for this entry
570581
Device.ShadowPtrMap[Pointer_HstPtrBegin] = {
571582
HstPtrBase, PointerTgtPtrBegin, ExpectedTgtPtrBase};
572583
UpdateDevPtr = true;

0 commit comments

Comments
 (0)