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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-03-17
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |wrong-code

--- Comment #2 from anlauf at gcc dot gnu.org ---
Confirmed.  I also have the gut feeling that there is a duplicate.

It appears that we do not initialize the pointer.  Consider:

program boom
  use, intrinsic :: iso_c_binding, only: c_loc
  implicit none
  complex, save, target :: a(4) = [(1.,0.), (2.,0.), (3.,0.), (4.,0.)]
  real, pointer         :: p(:) => a(1:3:2)%re
  real, pointer         :: q(:) 
  q => a(1:3:2)%re
  print *, "size (p) =", size (p)
  print *, "size (q) =", size (q)
  print *, "c_loc(p(1)), c_loc(p(2)) =", c_loc(p(1)), c_loc(p(2))
  print *, "c_loc(q(1)), c_loc(q(2)) =", c_loc(q(1)), c_loc(q(2))
! print *, p ! this segfaults
  print *, q
end program boom

This prints e.g.

 size (p) =           1
 size (q) =           2
 c_loc(p(1)), c_loc(p(2)) =                    0                    0
 c_loc(q(1)), c_loc(q(2)) =              4202592              4202608
   1.00000000       3.00000000    

Crayftn 14.0 (the only compiler that I found to work here):

 size (p) = 2
 size (q) = 2
 c_loc(p(1)), c_loc(p(2)) = 4210816,  4210832
 c_loc(q(1)), c_loc(q(2)) = 4210816,  4210832
 1.,  3.

Reply via email to