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

--- Comment #5 from anlauf at gcc dot gnu.org ---
Further data points:

- introducing a temporary array for the result, e.g.

  integer :: aux_array(4)

and using it as

  aux_array = array(:, sort_2(i(1:2)) )
  write(*,*) 'line 5:',aux_array

generates correct code, and the bounds-checking code is sane.

- the original code line

  write(*,*) 'line 4:',array(:, sort_2(i(1:2)) )

generates 2 (!) calls to sort_2, with the version used in the bounds-checking
not having the descriptor of the argument array set up:

        struct array01_integer(kind=4) parm.2;
        integer(kind=8) D.4814;
        struct array01_integer(kind=4) parm.3;
        integer(kind=8) D.4821;
        struct array01_integer(kind=4) parm.4;

        D.4814 = (integer(kind=8)) sort_2 ((integer(kind=4)[0:] *)
parm.2.data);
        if (D.4814 <= 0)
...
        parm.3.span = 4;
        parm.3.dtype = {.elem_len=4, .version=0, .rank=1, .type=1};
        parm.3.dim[0].lbound = 1;
        parm.3.dim[0].ubound = 2;
        parm.3.dim[0].stride = 1;
        parm.3.data = (void *) &i[0];
        parm.3.offset = -1;
        D.4821 = (integer(kind=8)) sort_2 ((integer(kind=4)[0:] *)
parm.3.data);

Maybe the write statement is interfering?

Reply via email to