From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 569923858D1E; Sat, 13 Jan 2024 14:21:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 569923858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705155680; bh=9yc6UC4qJTZBveqxpmnOLyfMaPLVCiHxHL0mbzaZnH4=; h=From:To:Subject:Date:From; b=LEeLYTtbOEbvjSxvIQdWZUare2aW+IwJMyzjEIqmCtOxx1II1tdXACCi7eWPFUx+s zMB+JHPBCFAtJU8aRC/Vd0yaTzeyVLKton4sPjDDARu3q5kj1tyCSMc7VR9V1jCJ0h KQeztYrWip4YsV9IibJjmn903ViGZETSejOM637s= From: "anlauf at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/113377] New: Wrong code passing optional dummy argument to elemental procedure with optional dummy Date: Sat, 13 Jan 2024 14:21:19 +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=3D113377 Bug ID: 113377 Summary: Wrong code passing optional dummy argument to elemental procedure with optional dummy 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: --- There are likely several related PRs, e.g. pr67277, but here is a smaller reproducer: program p implicit none integer :: k(4) =3D 1, m(4) m =3D one (k) print *, m contains function one (i, j) result (r) integer, intent(in) :: i(4) integer, intent(in), optional :: j integer :: r(size(i)) r =3D two (i, j) ! scalarizer dereferences loop invariant j ... end elemental function two (i, j) result (r) integer, intent(in) :: i integer, value, optional :: j integer :: r r =3D 42*i end end This crashes in function one. A scalar invocation does not fail. The dump-tree suggests that the scalarizer sees the loop invariant j, unconditionally dereferences it outside the loop, generates code that unconditionally dereferences j in the invocation of two, and uses a wrong interface: integer(kind=3D4) two (integer(kind=3D4) & restrict i, integer(kind=3D4) j, logical(kind=3D1) .j) but one has: D.4339 =3D (integer(kind=3D4) *) j; { integer(kind=3D8) S.3; integer(kind=3D8) D.4341; D.4341 =3D stride.0; S.3 =3D 1; while (1) { if (S.3 > 4) goto L.1; *((integer(kind=3D4) *) __result.0 + (sizetype) ((S.3 * D.4341 + D.4338) * 4)) =3D two (&(*i)[S.3 + -1], *D.4339); S.3 =3D S.3 + 1; } L.1:;=