Hi! On 2020-12-04T22:15:46+0800, Chung-Lin Tang wrote: > this is a new version of the structure element mapping patch for OpenMP 5.0 requirement > changes. > (gomp_exit_data): [...] > adjust to queue splay-tree keys for removal > after main loop. > --- a/libgomp/target.c > +++ b/libgomp/target.c > @@ -2485,14 +2714,17 @@ gomp_exit_data (struct gomp_device_descr *devicep, size_t mapnum, > + int nrmvars = 0; > + splay_tree_key remove_vars[mapnum]; > + > for (i = 0; i < mapnum; i++) > { > - if (k->refcount == 0) > - gomp_remove_var (devicep, k); > + > + /* Structure elements lists are removed altogether at once, which > + may cause immediate deallocation of the target_mem_desc, causing > + errors if we still have following element siblings to copy back. > + While we're at it, it also seems more disciplined to simply > + queue all removals together for processing below. > + > + Structured block unmapping (i.e. gomp_unmap_vars_internal) should > + not have this problem, since they maintain an additional > + tgt->refcount = 1 reference to the target_mem_desc to start with. > + */ > + if (do_remove) > + remove_vars[nrmvars++] = k; > } > > + for (int i = 0; i < nrmvars; i++) > + gomp_remove_var (devicep, remove_vars[i]); > + > gomp_mutex_unlock (&devicep->lock); > } Upcoming work of mine actually now does require this change also for 'gomp_unmap_vars_internal', such that 'gomp_remove_var' be deferred until after all 'gomp_copy_dev2host' calls have been handled. I've pushed to devel/omp/gcc-12 commit 65037818987ffce7d6f466fa8bde13e9f59a3218 "In 'libgomp/target.c:gomp_unmap_vars_internal', defer 'gomp_remove_var'", see attached. Grüße Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955