From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 33FCF385C426; Sat, 23 May 2020 20:36:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 33FCF385C426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1590266194; bh=WfrE901lotU/eOrFZLI8abXs0/rm43sE3ygNE/o1HP8=; h=From:To:Subject:Date:From; b=QwvVOhuxiRJ4COQC9Yvs/bskSN89iK1DhTzuvA6xv1h+g0wbWV21bXsI2c03AVZbc YYDgUSx3vG9hu5JCFcItuLwinRCArIJgRrBeyaNye2gnEScbu4ZCCHRnFFSogbpF+5 lEnFO3lN1GHB5sEfFjhK1UoYeBtYr5qpc01oWYOg= From: "david.sagan at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libfortran/95293] New: Fortran not passing array by reference Date: Sat, 23 May 2020 20:36:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libfortran X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: david.sagan at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 May 2020 20:36:34 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95293 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 =3D 0 end type type scratch_struct type (cb_struct) :: cc(10) real :: zz(10) =3D 0 end type type (scratch_struct), target :: s1 ! s1%cc(2)%cbar =3D 7 call sub2(s1%cc%cbar) print *, 'Sub2 result:', s1%cc(2)%cbar, ' ! Wrong. Should be 10' s1%zz(2) =3D 7 call sub3(s1%zz) print *, 'Sub3 result:', s1%zz(2) !-------------------------------------- contains subroutine sub2(vec) real, target, intent(inout) :: vec(:) real, pointer :: ptr ptr =3D> vec(1) print *, 'In sub2:', associated(ptr, s1%cc(1)%cbar), vec(2) vec(2) =3D 23 s1%cc(2)%cbar =3D 10 end subroutine sub2 subroutine sub3(vec) real, target, intent(inout) :: vec(:) real, pointer :: ptr ptr =3D> vec(1) print *, 'In sub3:', associated(ptr, s1%zz(1)), vec(2) vec(2) =3D 23 s1%zz(2) =3D 10 end subroutine sub3 end program Running gives: > gfortran test.f90 > ./a.out=20 In sub2: F 7.00000000=20=20=20=20 Sub2 result: 23.0000000 ! Wrong. Should be 10 In sub3: T 7.00000000=20=20=20=20 Sub3 result: 10.0000000 I get the same result on Linux and Mac with gcc 8.3.1 and gcc 9.3.=