https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103276

--- Comment #8 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Comment on attachment 63120
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63120
avoid taking address of reference in map

I might do something wrong, but if I run:
  TYPE simple
    integer(2) v
  END TYPE
CONTAINS
  SUBROUTINE COPYIN_SIMPLE(VAR)
    TYPE(simple) :: VAR
    !$ACC ENTER DATA COPYIN(VAR)
    !$OMP TARGET ENTER DATA map(var)
  END SUBROUTINE

I get a message of the kind
(sorry deleted the actual one, i.e. I might mistype now)

libgomp: Trying to map into device
   [0x7fffffffd8d0..0x7fffffffd8d8) object when
   [0x7fffffffd8d0..0x7fffffffd8d2) is already mapped

which seems to make perfectly sense. I believe now that the problem is not
the '&':

    .omp_data_arr.9.D.4734 = var.2_1;
    .omp_data_arr.9.var = &var;
    #pragma omp target enter data \
        map(to:*var.2_1 [len: 2]) map(alloc:var [pointer assign, bias: 0])

which makes sense in terms of the runtime library handling.

IMHO, the actual problem is that there is a pointer assign (aka
GOMP_MAP_TO_PSET) at the first place - even though there is no pointer at all!


Thus, if the stack address of the pointer gets re-used, it will fail.

OpenMP testcase - fails accordingly with:

libgomp: Trying to map into device [0x7fff06266630..0x7fff06266644) object when
[0x7fff06266640..0x7fff06266648) is already mapped

---------------------------<cut>------------------------------------
module m
contains
  subroutine map_it(a, b)
    integer(2) :: a, b
    optional :: b
    !$omp target enter data map(a, b)
  end subroutine
  subroutine other()
    integer(2) :: array(10)
    !$omp target map(alloc: array)
      array = 1
    !$omp end target
  end
end

use m
integer(2) :: x1, x2
x1 = 1; x2 = 2
call map_it(x1, x2)
call other()
end
---------------------------<cut>------------------------------------


BTW: At least at a glance, the C++ testcase seems to be fine (looking at the
dump + it also does not fail at runtime):

void map_it (short *a, short &b)
{
  #pragma omp target enter data map(a[:1], b)
}

void other()
{
  short array[10];
  #pragma omp target map(alloc: array)
    array[0] = array[9] = 1;
}

int main()
{
  short x1 = 1, x2 = 2;
  map_it (&x1, x2);
  other ();
}

Reply via email to