From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14598 invoked by alias); 6 Nov 2013 19:52:59 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 13828 invoked by uid 48); 6 Nov 2013 19:50:56 -0000 From: "fxcoudert at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/59026] New: ELEMENTAL procedure with VALUE arguments emits wrong code Date: Wed, 06 Nov 2013 19:52:00 -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: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fxcoudert at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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 Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-11/txt/msg00533.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59026 Bug ID: 59026 Summary: ELEMENTAL procedure with VALUE arguments emits wrong code Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: fxcoudert at gcc dot gnu.org The following source is compiled into wrong code: interface elemental integer function foo(x) integer, intent(in), value :: x end function end interface print *, foo(42) print *, foo([0,1]) end For all versions of gfortran starting from 4.3 (and up to current trunk), the second call to FOO is miscompiled. Looking at the generated code (-fdump-tree-original), the first call is, as expected, by value: D.1882 = foo (42); _gfortran_transfer_integer_write (&dt_parm.0, &D.1882, 4); while the second call is by-reference: D.1887 = A.2[S.3]; D.1888 = foo (&D.1887); _gfortran_transfer_integer_write (&dt_parm.1, &D.1888, 4); This can be confirmed by adding an actual FOO function such as: elemental integer function foo(x) integer, intent(in), value :: x foo = x - 1 end function Running the complete program then yields: 41 1370438451 1370438451