public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/99169] New: Segfault when passing allocatable scalar into intent(out) dummy argument
@ 2021-02-19 17:31 townsend at astro dot wisc.edu
  2021-02-19 19:49 ` [Bug fortran/99169] [9/10/11 Regression] " anlauf at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: townsend at astro dot wisc.edu @ 2021-02-19 17:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99169
           Summary: Segfault when passing allocatable scalar into
                    intent(out) dummy argument
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: townsend at astro dot wisc.edu
  Target Milestone: ---

Created attachment 50222
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50222&action=edit
Minimal working example

I've encountered a problem when passing an allocatable (and alread allocated)
scalar as an actual argument to a procedure with an intent(out) (but not
allocatable) dummy argument. The attached code illustrates the problem. 

Compiling with gfortran 10.2.0 at optimization level -O1 or -O2 leads to a
segmentation fault at runtime. The segfault arises when the dummy is assigned
within set_i(). This problem does not arise at optimization level -O0, and the
program performs as expected (outputting '5' to the terminal).

The problem also seems to disappear when set_i() is a CONTAINed procedure in
the main program, rather than a module procedure.

cheers,

Rich

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/99169] [9/10/11 Regression] Segfault when passing allocatable scalar into intent(out) dummy argument
  2021-02-19 17:31 [Bug fortran/99169] New: Segfault when passing allocatable scalar into intent(out) dummy argument townsend at astro dot wisc.edu
@ 2021-02-19 19:49 ` anlauf at gcc dot gnu.org
  2021-02-19 19:58 ` anlauf at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-02-19 19:49 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |8.4.1
           Priority|P3                          |P4
            Summary|Segfault when passing       |[9/10/11 Regression]
                   |allocatable scalar into     |Segfault when passing
                   |intent(out) dummy argument  |allocatable scalar into
                   |                            |intent(out) dummy argument
     Ever confirmed|0                           |1
   Target Milestone|---                         |9.4
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |NEW
      Known to fail|                            |10.2.1, 11.0, 9.3.1
   Last reconfirmed|                            |2021-02-19
                 CC|                            |anlauf at gcc dot gnu.org

--- Comment #1 from anlauf at gcc dot gnu.org ---
Confirmed.

The tree dump shows that since at least 9.3.1 we clobber the pointer:

  integer(kind=4) * i;
...
      i = (integer(kind=4) *) __builtin_malloc (4);
...
  i = {CLOBBER};
  set_i (i);

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/99169] [9/10/11 Regression] Segfault when passing allocatable scalar into intent(out) dummy argument
  2021-02-19 17:31 [Bug fortran/99169] New: Segfault when passing allocatable scalar into intent(out) dummy argument townsend at astro dot wisc.edu
  2021-02-19 19:49 ` [Bug fortran/99169] [9/10/11 Regression] " anlauf at gcc dot gnu.org
@ 2021-02-19 19:58 ` anlauf at gcc dot gnu.org
  2021-02-19 20:13 ` anlauf at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-02-19 19:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from anlauf at gcc dot gnu.org ---
Note/workaround: the {CLOBBER} disappears if the argument to set_i is declared
INOUT instead of OUT.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/99169] [9/10/11 Regression] Segfault when passing allocatable scalar into intent(out) dummy argument
  2021-02-19 17:31 [Bug fortran/99169] New: Segfault when passing allocatable scalar into intent(out) dummy argument townsend at astro dot wisc.edu
  2021-02-19 19:49 ` [Bug fortran/99169] [9/10/11 Regression] " anlauf at gcc dot gnu.org
  2021-02-19 19:58 ` anlauf at gcc dot gnu.org
@ 2021-02-19 20:13 ` anlauf at gcc dot gnu.org
  2021-02-19 20:20 ` anlauf at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-02-19 20:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from anlauf at gcc dot gnu.org ---
A conservative solution simply disables the clobber:

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 103cb31c664..ce7bfaa89e8 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -6082,6 +6084,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
                        /* FIXME - PR 87395 and PR 41453  */
                        && e->symtree->n.sym->attr.save == SAVE_NONE
                        && !e->symtree->n.sym->attr.associate_var
+                       && !e->symtree->n.sym->attr.allocatable
                        && e->ts.type != BT_CHARACTER && e->ts.type !=
BT_DERIVED
                        && e->ts.type != BT_CLASS && !sym->attr.elemental;

This should result only in a missed optimization.
Is there a way to get sth. like:

  *i = {CLOBBER};

so that we do not clobber the pointer but the pointer to?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/99169] [9/10/11 Regression] Segfault when passing allocatable scalar into intent(out) dummy argument
  2021-02-19 17:31 [Bug fortran/99169] New: Segfault when passing allocatable scalar into intent(out) dummy argument townsend at astro dot wisc.edu
                   ` (2 preceding siblings ...)
  2021-02-19 20:13 ` anlauf at gcc dot gnu.org
@ 2021-02-19 20:20 ` anlauf at gcc dot gnu.org
  2021-02-19 21:17 ` anlauf at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-02-19 20:20 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tkoenig at gcc dot gnu.org

--- Comment #4 from anlauf at gcc dot gnu.org ---
The following code in trans-expr.c was added by Thomas, so adding him in CC:

      else if (add_clobber && expr->ref == NULL)
        {
          tree clobber;
          tree var;
          /* FIXME: This fails if var is passed by reference, see PR
             41453.  */
          var = expr->symtree->n.sym->backend_decl;
          clobber = build_clobber (TREE_TYPE (var));
          gfc_add_modify (&se->pre, var, clobber);
        }

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/99169] [9/10/11 Regression] Segfault when passing allocatable scalar into intent(out) dummy argument
  2021-02-19 17:31 [Bug fortran/99169] New: Segfault when passing allocatable scalar into intent(out) dummy argument townsend at astro dot wisc.edu
                   ` (3 preceding siblings ...)
  2021-02-19 20:20 ` anlauf at gcc dot gnu.org
@ 2021-02-19 21:17 ` anlauf at gcc dot gnu.org
  2021-02-21 20:44 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-02-19 21:17 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |anlauf at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #5 from anlauf at gcc dot gnu.org ---
Patch: https://gcc.gnu.org/pipermail/fortran/2021-February/055741.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/99169] [9/10/11 Regression] Segfault when passing allocatable scalar into intent(out) dummy argument
  2021-02-19 17:31 [Bug fortran/99169] New: Segfault when passing allocatable scalar into intent(out) dummy argument townsend at astro dot wisc.edu
                   ` (4 preceding siblings ...)
  2021-02-19 21:17 ` anlauf at gcc dot gnu.org
@ 2021-02-21 20:44 ` cvs-commit at gcc dot gnu.org
  2021-02-23 18:14 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-02-21 20:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:2df374b337a5f6cf5528e91718e4e12e4006b7ae

commit r11-7315-g2df374b337a5f6cf5528e91718e4e12e4006b7ae
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Sun Feb 21 21:44:24 2021 +0100

    PR fortran/99169 - Do not clobber allocatable intent(out) dummy argument

    gcc/fortran/ChangeLog:

            * trans-expr.c (gfc_conv_procedure_call): Do not add clobber to
            allocatable intent(out) argument.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/intent_optimize_3.f90: New test.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/99169] [9/10/11 Regression] Segfault when passing allocatable scalar into intent(out) dummy argument
  2021-02-19 17:31 [Bug fortran/99169] New: Segfault when passing allocatable scalar into intent(out) dummy argument townsend at astro dot wisc.edu
                   ` (5 preceding siblings ...)
  2021-02-21 20:44 ` cvs-commit at gcc dot gnu.org
@ 2021-02-23 18:14 ` cvs-commit at gcc dot gnu.org
  2021-02-23 18:27 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-02-23 18:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:e111925dbddb63ca1ee9e43412c7e896ba5c1105

commit r10-9385-ge111925dbddb63ca1ee9e43412c7e896ba5c1105
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Sun Feb 21 21:44:24 2021 +0100

    PR fortran/99169 - Do not clobber allocatable intent(out) dummy argument

    gcc/fortran/ChangeLog:

            * trans-expr.c (gfc_conv_procedure_call): Do not add clobber to
            allocatable intent(out) argument.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/intent_optimize_3.f90: New test.

    (cherry picked from commit 2df374b337a5f6cf5528e91718e4e12e4006b7ae)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/99169] [9/10/11 Regression] Segfault when passing allocatable scalar into intent(out) dummy argument
  2021-02-19 17:31 [Bug fortran/99169] New: Segfault when passing allocatable scalar into intent(out) dummy argument townsend at astro dot wisc.edu
                   ` (6 preceding siblings ...)
  2021-02-23 18:14 ` cvs-commit at gcc dot gnu.org
@ 2021-02-23 18:27 ` cvs-commit at gcc dot gnu.org
  2021-02-23 18:29 ` anlauf at gcc dot gnu.org
  2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-02-23 18:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:baf4c27c8754c1f7bbad3f577a4bd890528c0e75

commit r9-9247-gbaf4c27c8754c1f7bbad3f577a4bd890528c0e75
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Sun Feb 21 21:44:24 2021 +0100

    PR fortran/99169 - Do not clobber allocatable intent(out) dummy argument

    gcc/fortran/ChangeLog:

            * trans-expr.c (gfc_conv_procedure_call): Do not add clobber to
            allocatable intent(out) argument.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/intent_optimize_3.f90: New test.

    (cherry picked from commit 2df374b337a5f6cf5528e91718e4e12e4006b7ae)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/99169] [9/10/11 Regression] Segfault when passing allocatable scalar into intent(out) dummy argument
  2021-02-19 17:31 [Bug fortran/99169] New: Segfault when passing allocatable scalar into intent(out) dummy argument townsend at astro dot wisc.edu
                   ` (7 preceding siblings ...)
  2021-02-23 18:27 ` cvs-commit at gcc dot gnu.org
@ 2021-02-23 18:29 ` anlauf at gcc dot gnu.org
  2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-02-23 18:29 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #9 from anlauf at gcc dot gnu.org ---
Fixed on master for gcc-11, and on 10- and 9-branches.

Thanks for the report!

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/99169] [9/10/11 Regression] Segfault when passing allocatable scalar into intent(out) dummy argument
  2021-02-19 17:31 [Bug fortran/99169] New: Segfault when passing allocatable scalar into intent(out) dummy argument townsend at astro dot wisc.edu
                   ` (8 preceding siblings ...)
  2021-02-23 18:29 ` anlauf at gcc dot gnu.org
@ 2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-09-25 12:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Mikael Morin <mikael@gcc.gnu.org>:

https://gcc.gnu.org/g:95375ffb3dd59f51e79408dd3b2b620dc1af71b1

commit r13-2840-g95375ffb3dd59f51e79408dd3b2b620dc1af71b1
Author: Mikael Morin <mikael@gcc.gnu.org>
Date:   Thu Sep 1 11:27:36 2022 +0200

    fortran: Support clobbering of allocatables and pointers [PR41453]

    This adds support for clobbering of allocatable and pointer scalar
    variables passed as actual argument to a subroutine when the associated
    dummy has the INTENT(OUT) attribute.
    Support was explicitly disabled (since the beginning for pointers, since
    r11-7315-g2df374b337a5f6cf5528e91718e4e12e4006b7ae for allocatables),
    but the clobber generation code seems to support it well, as
    demonstrated by the newly added testcase.

            PR fortran/41453
            PR fortran/99169

    gcc/fortran/ChangeLog:

            * trans-expr.cc (gfc_conv_procedure_call): Remove conditions
            on ALLOCATABLE and POINTER attributes guarding clobber
            generation.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/intent_optimize_9.f90: New test.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-09-25 12:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-19 17:31 [Bug fortran/99169] New: Segfault when passing allocatable scalar into intent(out) dummy argument townsend at astro dot wisc.edu
2021-02-19 19:49 ` [Bug fortran/99169] [9/10/11 Regression] " anlauf at gcc dot gnu.org
2021-02-19 19:58 ` anlauf at gcc dot gnu.org
2021-02-19 20:13 ` anlauf at gcc dot gnu.org
2021-02-19 20:20 ` anlauf at gcc dot gnu.org
2021-02-19 21:17 ` anlauf at gcc dot gnu.org
2021-02-21 20:44 ` cvs-commit at gcc dot gnu.org
2021-02-23 18:14 ` cvs-commit at gcc dot gnu.org
2021-02-23 18:27 ` cvs-commit at gcc dot gnu.org
2021-02-23 18:29 ` anlauf at gcc dot gnu.org
2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org

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).