public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "anlauf at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-113377-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113377

            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) = 1, m(4)
  m = 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 = 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 = 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=4) two (integer(kind=4) & restrict i, integer(kind=4) j,
logical(kind=1) .j)

but one has:

    D.4339 = (integer(kind=4) *) j;
    {
      integer(kind=8) S.3;
      integer(kind=8) D.4341;

      D.4341 = stride.0;
      S.3 = 1;
      while (1)
        {
          if (S.3 > 4) goto L.1;
          *((integer(kind=4) *) __result.0 + (sizetype) ((S.3 * D.4341 +
D.4338) * 4)) = two (&(*i)[S.3 + -1], *D.4339);
          S.3 = S.3 + 1;
        }
      L.1:;

             reply	other threads:[~2024-01-13 14:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-13 14:21 anlauf at gcc dot gnu.org [this message]
2024-01-14 10:51 ` [Bug fortran/113377] " mikael at gcc dot gnu.org
2024-01-14 20:05 ` anlauf at gcc dot gnu.org
2024-01-16 21:05 ` anlauf at gcc dot gnu.org
2024-01-16 22:02 ` anlauf at gcc dot gnu.org
2024-01-19 18:46 ` mikael at gcc dot gnu.org
2024-01-19 19:25 ` mikael at gcc dot gnu.org
2024-01-19 21:16 ` anlauf at gcc dot gnu.org
2024-01-19 21:19 ` anlauf at gcc dot gnu.org
2024-01-21 20:24 ` cvs-commit at gcc dot gnu.org
2024-01-24 19:28 ` cvs-commit at gcc dot gnu.org
2024-01-25 18:26 ` anlauf at gcc dot gnu.org
2024-01-28 19:26 ` cvs-commit at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-113377-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).