public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: "José Rui Faustino de Sousa" <jrfsousa@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-9919] Fortran: Fix double function call with -fcheck=pointer [PR] Date: Wed, 16 Jun 2021 00:55:56 +0000 (GMT) [thread overview] Message-ID: <20210616005556.76E4B3857C67@sourceware.org> (raw) https://gcc.gnu.org/g:ec6d6554da7771519f39fee32c97707698dbe50a commit r10-9919-gec6d6554da7771519f39fee32c97707698dbe50a Author: José Rui Faustino de Sousa <jrfsousa@gmail.com> Date: Wed Jun 16 00:55:37 2021 +0000 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. Diff: --- gcc/fortran/trans-expr.c | 7 ++--- gcc/testsuite/gfortran.dg/PR82376.f90 | 59 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index e35f3147a8e..a12cd2fde5a 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -5958,11 +5958,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, || (!e->value.function.esym && e->symtree->n.sym->attr.pointer)) && fsym && fsym->attr.target) - { - gfc_conv_expr (&parmse, e); - parmse.expr = gfc_build_addr_expr (NULL_TREE, parmse.expr); - } - + /* Make sure the function only gets called once. */ + gfc_conv_expr_reference (&parmse, e, false); else if (e->expr_type == EXPR_FUNCTION && e->symtree->n.sym->result && e->symtree->n.sym->result != e->symtree->n.sym diff --git a/gcc/testsuite/gfortran.dg/PR82376.f90 b/gcc/testsuite/gfortran.dg/PR82376.f90 new file mode 100644 index 00000000000..07143ab7e82 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/PR82376.f90 @@ -0,0 +1,59 @@ +! { 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-06-16 0:55 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210616005556.76E4B3857C67@sourceware.org \ --to=jrfsousa@gcc.gnu.org \ --cc=gcc-cvs@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: linkBe 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).