[OpenACC] Don't open-code 'gomp_remove_var' in 'acc_unmap_data'
authorThomas Schwinge <thomas@codesourcery.com>
Fri, 29 May 2020 12:21:03 +0000 (14:21 +0200)
committerThomas Schwinge <thomas@codesourcery.com>
Thu, 4 Jun 2020 16:56:37 +0000 (18:56 +0200)
libgomp/
* oacc-mem.c (acc_unmap_data): Don't open-code 'gomp_remove_var'.

Co-Authored-By: Julian Brown <julian@codesourcery.com>
libgomp/oacc-mem.c

index 6314f5d..8e8c7c3 100644 (file)
@@ -468,8 +468,6 @@ acc_unmap_data (void *h)
                  (void *) h, (int) host_size);
     }
 
-  splay_tree_remove (&acc_dev->mem_map, n);
-
   struct target_mem_desc *tgt = n->tgt;
 
   if (tgt->refcount == REFCOUNT_INFINITY)
@@ -482,8 +480,12 @@ acc_unmap_data (void *h)
      'acc_map_data'.  */
   assert (tgt->refcount == 1);
 
-  free (tgt->array);
-  free (tgt);
+  /* Nullifying these fields prevents 'gomp_unmap_tgt' via 'gomp_remove_var'
+     from freeing the target memory.  */
+  tgt->tgt_end = 0;
+  tgt->to_free = NULL;
+
+  gomp_remove_var (acc_dev, n);
 
   gomp_mutex_unlock (&acc_dev->lock);