From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 74C723851C0C; Mon, 14 Sep 2020 15:42:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74C723851C0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600098127; bh=T+o0HzXSFkTvLa/FhE6XPpmJaWeBTneG4zqAoWTQUUE=; h=From:To:Subject:Date:From; b=BfQv6dZaHEgLC7CJRSy3esnHJ5/6QzvppogSWkuF3Hu+3cGwP8ZbGjsDbLDL2wPI3 KmAoXbJiO2m/m9Zx4xctm6Qd2mWmiYpmJNRClxIw0irAnpCjU8Ggj1geNoApCydOkX eAQ27Z0I1f8zBwuWkU3g+DNcXXXkKDY7ZbOiWRp0= From: "igor.gayday at mu dot edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/97046] New: Bad interaction between lbound/ubound, allocatable arrays and bind(C) subroutine with dimension(..) parameter Date: Mon, 14 Sep 2020 15:42:07 +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: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: igor.gayday at mu dot edu 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: Mon, 14 Sep 2020 15:42:07 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97046 Bug ID: 97046 Summary: Bad interaction between lbound/ubound, allocatable arrays and bind(C) subroutine with dimension(..) parameter Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: igor.gayday at mu dot edu Target Milestone: --- Consider the following code: MODULE FOO INTERFACE SUBROUTINE dummyc(x0) BIND(C, name=3D"sync") type(*), dimension(..) :: x0 END SUBROUTINE END INTERFACE contains SUBROUTINE dummy(x0) type(*), dimension(..) :: x0 call dummyc(x0) END SUBROUTINE END MODULE PROGRAM main USE FOO IMPLICIT NONE integer :: before(2), after(2) INTEGER, parameter :: n =3D 1 DOUBLE PRECISION, ALLOCATABLE :: buf(:) DOUBLE PRECISION :: buf2(n) ALLOCATE(buf(n)) before(1) =3D LBOUND(buf,1) before(2) =3D UBOUND(buf,1) CALL dummy (buf) after(1) =3D LBOUND(buf,1) after(2) =3D UBOUND(buf,1) if (before(1) .NE. after(1)) stop 1 if (before(2) .NE. after(2)) stop 2 before(1) =3D LBOUND(buf2,1) before(2) =3D UBOUND(buf2,1) CALL dummy (buf2) after(1) =3D LBOUND(buf2,1) after(2) =3D LBOUND(buf2,1) if (before(1) .NE. after(1)) stop 3 if (before(2) .NE. after(2)) stop 4 END PROGRAM lbound() and ubound() of an allocatable array return different values=20 before and after a Fortran subroutine with dimension(..) parameter (that=20 in turns invokes a bind(C) subroutine) is invoked. Note that if the main program directly CALL dummyc(buf) (instead of=20 dummy(buf)), then the error does not occur. gcc versions 9.2.0, 10.2.0 and the latest master branch are all affected. In particular, this causes issues with mpi_f08 module, see: https://stackoverflow.com/questions/63824065/lbound-of-an-array-changes-aft= er-call-to-mpi-gatherv-when-using-mpi-f08-module This might be a duplicate of Bug #94070.=