https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103276
Bug ID: 103276 Summary: [openacc] Trying to map already mapped data Product: gcc Version: og11 (devel/omp/gcc-11) Status: UNCONFIRMED Severity: normal Priority: P3 Component: libgomp Assignee: unassigned at gcc dot gnu.org Reporter: tetra2005 at gmail dot com CC: jakub at gcc dot gnu.org Target Milestone: --- Created attachment 51811 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51811&action=edit Reprocase I've ran into a duplicate mapping error with OpenACC which seems to be caused by invalid handling of ENTER DATA pragma. The pragma, when applied to a parameter of derived type, also maps some spurious local variable to device memory. After the function exits, another one is called and tries to map it's own local variables which causes aliasing conflict due to overlapping memory ranges in libgomp splay tree structures: libgomp: Trying to map into device [0x7fffffffcf80..0x7fffffffcfd8) object when [0x7fffffffcfc8..0x7fffffffcfd0) is already mapped The assembly looks like leaq 8(%rsp), %rax # POINTER TO LOCAL STACK VAR ... subq $8, %rsp movl $2, %esi # mapnum movq %rdi, 24(%rsp) # hostaddrs[0] (OK) movl $-1, %edi # flags_m movq %rax, 32(%rsp) # hostaddrs[1] (POINTS TO LOCAL STACK VAR) xorl %eax, %eax pushq $0 leaq 32(%rsp), %rdx # hostaddrs call GOACC_enter_exit_data Here hostaddrs[1] points to a spurious variable in current stack frame. Gimple code seems to be correct voidD.27 copyin_simple (struct simple & restrict varD.3961) { struct .omp_data_t.1D.3962 D.3965; ... # .MEM_4 = VDEF <.MEM_3> D.3965.varD.3964 = &varD.3961; but expanded RTL is not: ;; .omp_data_arr.2.var = &var; (insn 8 7 9 (parallel [ (set (reg:DI 84) (plus:DI (reg/f:DI 77 virtual-stack-vars) (const_int -24 [0xffffffffffffffe8]))) (clobber (reg:CC 17 flags)) ]) "repro.f90":11:28 -1 (nil)) (insn 9 8 0 (set (mem/f/c:DI (plus:DI (reg/f:DI 77 virtual-stack-vars) (const_int -8 [0xfffffffffffffff8])) [6 D.3965.varD.3964+0 S8 A64]) (reg:DI 84)) "repro.f90":11:28 -1 (nil)) Reproduced with attached code on devel/omp/gcc-11 branch (commit f85ed2296, 2021 Nov 10) with gfortran -O2 -ffree-form -ffree-line-length-none -fopenacc -foffload-options=-march=gfx908 -fdump-tree-all-all -fdump-rtl-all-all -S repro.f90