public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/95293] New: Fortran not passing array by reference
@ 2020-05-23 20:36 david.sagan at gmail dot com
  2020-05-23 22:26 ` [Bug libfortran/95293] " kargl at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: david.sagan at gmail dot com @ 2020-05-23 20:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95293
           Summary: Fortran not passing array by reference
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david.sagan at gmail dot com
  Target Milestone: ---

The test program is:

program test
implicit none

type cb_struct
  real :: cbar = 0
end type

type scratch_struct
  type (cb_struct) :: cc(10)
  real :: zz(10) = 0
end type

type (scratch_struct), target :: s1

!

s1%cc(2)%cbar = 7
call sub2(s1%cc%cbar)
print *, 'Sub2 result:', s1%cc(2)%cbar, '  ! Wrong. Should be 10'

s1%zz(2) = 7
call sub3(s1%zz)
print *, 'Sub3 result:', s1%zz(2)

!--------------------------------------
contains

subroutine sub2(vec)
  real, target, intent(inout) :: vec(:)
  real, pointer :: ptr
  ptr => vec(1)
  print *, 'In sub2:', associated(ptr, s1%cc(1)%cbar), vec(2)
  vec(2) = 23
  s1%cc(2)%cbar = 10
end subroutine sub2

subroutine sub3(vec)
  real, target, intent(inout) :: vec(:)
  real, pointer :: ptr
  ptr => vec(1)
  print *, 'In sub3:', associated(ptr, s1%zz(1)), vec(2)
  vec(2) = 23
  s1%zz(2) = 10
end subroutine sub3

end program


Running gives:

> gfortran test.f90
> ./a.out 
 In sub2: F   7.00000000    
 Sub2 result:   23.0000000       ! Wrong. Should be 10
 In sub3: T   7.00000000    
 Sub3 result:   10.0000000

I get the same result on Linux and Mac with gcc 8.3.1 and gcc 9.3.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-12-07 14:34 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-23 20:36 [Bug libfortran/95293] New: Fortran not passing array by reference david.sagan at gmail dot com
2020-05-23 22:26 ` [Bug libfortran/95293] " kargl at gcc dot gnu.org
2020-05-23 22:43 ` david.sagan at gmail dot com
2020-05-24  1:53 ` sgk at troutmask dot apl.washington.edu
2020-05-24  6:47 ` tkoenig at gcc dot gnu.org
2020-05-24  7:55 ` sgk at troutmask dot apl.washington.edu
2020-05-24 14:45 ` david.sagan at gmail dot com
2020-05-24 16:27 ` sgk at troutmask dot apl.washington.edu
2020-07-08 12:24 ` dominiq at lps dot ens.fr
2020-07-08 18:42 ` kargl at gcc dot gnu.org
2020-12-02 21:47 ` dominiq at lps dot ens.fr
2020-12-03  7:28 ` tkoenig at gcc dot gnu.org
2020-12-07 14:34 ` dominiq at lps dot ens.fr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).