public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Paul Richard Thomas <paul.richard.thomas@gmail.com>
To: "José Rui Faustino de Sousa" <jrfsousa@gmail.com>
Cc: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [Patch, fortran] PR fortran/82376 - Duplicate function call using -fcheck=pointer
Date: Sun, 25 Apr 2021 16:26:04 +0100	[thread overview]
Message-ID: <CAGkQGi+nVp9OuqJyiWL4grymrJ1ocVzD2GsiZ9tWnfPLG_m0Cg@mail.gmail.com> (raw)
In-Reply-To: <abb19b0c-0f5b-4828-93a9-4db32c00253f@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1478 bytes --]

Hi José!

The fix is fine.

Note however that the testcase will pass even without the fix because you
haven't included the
! { dg-options "-fcheck=pointer" }.

In fact, I suggest that you use the version of the tescase that I have
attached that does not run but counts the number of occurrences of 'new' in
the tree dump.

OK for master, certainly for 11-branch, when it is open again, and for
10-branch after a wait.

Are you reliant on others to commit and push your patches or have you done
the FSF paperwork?

Thanks

Paul




On Thu, 22 Apr 2021 at 21:50, José Rui Faustino de Sousa via Fortran <
fortran@gcc.gnu.org> wrote:

> Hi All!
>
> Proposed patch to:
>
> PR82376 - Duplicate function call using -fcheck=pointer
>
> Patch tested only on x86_64-pc-linux-gnu.
>
> Evaluate function result and then pass a pointer, instead of a reference
> to the function itself, thus avoiding multiple evaluations of the function.
>
> Thank you very much.
>
> Best regards,
> José Rui
>
> Fortran: Fix double function call with -fcheck=pointer [PR]
>
> gcc/fortran/ChangeLog:
>
>         PR fortran/82376
>         * trans-expr.c (gfc_conv_procedure_call): Evaluate function result
>         and then pass a pointer.
>
> gcc/testsuite/ChangeLog:
>
>         PR fortran/82376
>         * gfortran.dg/PR82376.f90: New test.
>
>

-- 
"If you can't explain it simply, you don't understand it well enough" -
Albert Einstein

[-- Attachment #2: ptr-func-5.f90 --]
[-- Type: text/x-fortran, Size: 1211 bytes --]

! { dg-do compile }
! { dg-options "-fdump-tree-original -fcheck=pointer" }
!
! Test the fix for PR82376. The pointer check was doubling up the call
! to new. The fix reduces the count of 'new' from 5 to 4.
!
! Contributed by José Rui Faustino de Sousa  <jrfsousa@gmail.com>
!
program main_p

  integer, parameter :: n = 10

  type :: foo_t
    integer, pointer :: v =>null()
  end type foo_t

  integer, save :: pcnt = 0

  type(foo_t) :: int
  integer     :: i

  do i = 1, n
    call init(int, i)
    if(.not.associated(int%v)) stop 1
    if(int%v/=i) stop 2
    if(pcnt/=i) stop 3
  end do

contains

  function new(data) result(this)
    integer, target, intent(in) :: data

    integer, pointer :: this

    nullify(this)
    this => data
    pcnt = pcnt + 1
    return
  end function new

  subroutine init(this, data)
    type(foo_t), intent(out) :: this
    integer,     intent(in)  :: data

    call set(this, new(data))
    return
  end subroutine init

  subroutine set(this, that)
    type(foo_t),     intent(inout) :: this
    integer, target, intent(in)    :: that

    this%v => that
    return
  end subroutine set

end program main_p
! { dg-final { scan-tree-dump-times "new" 4 "original" } }

      reply	other threads:[~2021-04-25 15:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-22 17:32 José Rui Faustino de Sousa
2021-04-25 15:26 ` Paul Richard Thomas [this message]

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=CAGkQGi+nVp9OuqJyiWL4grymrJ1ocVzD2GsiZ9tWnfPLG_m0Cg@mail.gmail.com \
    --to=paul.richard.thomas@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jrfsousa@gmail.com \
    /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).