From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B35D03858C52; Tue, 13 Jun 2023 19:27:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B35D03858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686684476; bh=/1Oei6k0+Aa70D71Kxf4gK+j+OuMf8d7ncCpBmY3PUM=; h=From:To:Subject:Date:From; b=RiPsTVI64xvZgGCzGUNuWkxs1Rfaf1MRt9wkxl8wUnpXILT/ihNlsqWDrpR4NPmBC TPDtczf1/Gzk+eN869wVUAyZO+eplz4dTMQ9te3M4Gomdsvt96b7hlmBrtHU2PsuA/ m14vHr65Y47e/nPSlCxNxcffh80LbQIX9GM2cwNY= From: "anlauf at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/110241] New: Redundant temporaries passing empty array constructors Date: Tue, 13 Jun 2023 19:27:56 +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: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: anlauf at gcc dot gnu.org 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110241 Bug ID: 110241 Summary: Redundant temporaries passing empty array constructors Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: anlauf at gcc dot gnu.org Target Milestone: --- Found while working on pr86277: program p call sub ([real :: 42.]) ! Single temporary call sub ([real :: ]) ! Double temporary contains subroutine sub (arg) real, intent(in), optional :: arg(:) if (.not. present (arg)) stop 1 end end The dump-tree (at r14-1795-gc1691509e5a887) shows the following for the first call: { static real(kind=3D4) A.4[1] =3D {4.2e+1}; struct array01_real(kind=3D4) parm.5; parm.5.span =3D 4; parm.5.dtype =3D {.elem_len=3D4, .rank=3D1, .type=3D3}; parm.5.dim[0].lbound =3D 1; parm.5.dim[0].ubound =3D 1; parm.5.dim[0].stride =3D 1; parm.5.data =3D (void *) &A.4[0]; parm.5.offset =3D -1; sub (&parm.5); } which is as expected, but for the second call: { struct array01_real(kind=3D4) atmp.6; real(kind=3D4) A.7[0]; struct array01_real(kind=3D4) atmp.9; real(kind=3D4) A.10[0]; typedef real(kind=3D4) [0]; atmp.6.dtype =3D {.elem_len=3D4, .rank=3D1, .type=3D3}; atmp.6.dim[0].stride =3D 1; atmp.6.dim[0].lbound =3D 0; atmp.6.dim[0].ubound =3D -1; atmp.6.span =3D 4; atmp.6.data =3D (void * restrict) &A.7; atmp.6.offset =3D 0; typedef real(kind=3D4) [0]; atmp.9.dtype =3D {.elem_len=3D4, .rank=3D1, .type=3D3}; atmp.9.dim[0].stride =3D 1; atmp.9.dim[0].lbound =3D 0; atmp.9.dim[0].ubound =3D -1; atmp.9.span =3D 4; atmp.9.data =3D (void * restrict) &A.10; atmp.9.offset =3D 0; { integer(kind=3D8) S.11; S.11 =3D 0; while (1) { if (S.11 >=3D 0) goto L.2; (*(real(kind=3D4)[0] * restrict) atmp.9.data)[S.11] =3D (*(real(kind=3D4)[0] * restrict) atmp.6.data)[S.11]; S.11 =3D S.11 + 1; } L.2:; } sub (&atmp.9); } While this is at least correct code (as opposed to before the fix for pr862= 77), it could be as simple as for the non-empty constructor. (There's a patch attached to the other pr demonstrating that this can be achieved for this code snippet).=