From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6317B3857827; Thu, 19 May 2022 09:28:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6317B3857827 From: "zed.three at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/105658] New: Passing array component to unlimited polymorphic routine passes wrong slice Date: Thu, 19 May 2022 09:28:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: zed.three 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: Thu, 19 May 2022 09:28:10 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105658 Bug ID: 105658 Summary: Passing array component to unlimited polymorphic routine passes wrong slice Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: zed.three at gmail dot com Target Milestone: --- The following program: program f implicit none type :: foo integer :: member1 integer :: member2 end type foo type(foo), dimension(3) :: thing =3D [foo(1, 2), foo(3, 4), foo(5, 6)] call print_poly(thing%member1) call print_int(thing%member1) contains subroutine print_poly(array) class(*), dimension(:), intent(in) :: array select type(array) type is (integer) print*, array end select end subroutine subroutine print_int(array) integer, dimension(:), intent(in) :: array print*, array end subroutine end program f prints: 1 2 3 1 3 5 when we would expect: 1 3 5 1 3 5 Adding `-fcheck=3Dall`, we get the warning "Fortran runtime warning: An arr= ay temporary was created" _only_ for the call to `print_int`. Adding an extra set of parentheses to the `print_poly` call (`call print_poly((thing%member1))` gives the expected behaviour, I guess because = it's forcing an array temporary? This behaviour is present in 4.9.4 through to the trunk currently available= on Compiler Explorer ((Compiler-Explorer-Build-gcc-7da9a089608b0ca09683332ce014fb6184842724-binu= tils-2.38) 13.0.0 20220518 (experimental))=