public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/102287] New: optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines.
@ 2021-09-11  0:37 alipasha.celeris at gmail dot com
  2021-09-13 19:37 ` [Bug fortran/102287] " anlauf at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: alipasha.celeris at gmail dot com @ 2021-09-11  0:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102287
           Summary: optional allocatable array arguments (intent out) of
                    derived types with allocatable components are not
                    properly passed to subroutines.
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alipasha.celeris at gmail dot com
  Target Milestone: ---

Created attachment 51437
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51437&action=edit
minimum test case for the observed bug.  Segfaults on the call to "b" inside
"a".

In a chain of subroutine calls, where there is an allocatable optional array
argument, with intent (out), of a derived type with an allocatable component, 
if the argument is omitted in any of the calls (i.e. it is not present inside
the called routine) then the next call (inside the called routine) causes a
segfault.

This behavior is not observed when
  - the derived type has only non-allocatable components,
  - the optional dummy argument is scalar, or
  - the intent is not OUT.

The only factor that can cause the segfault seems to be the presence of an
allocatable component in the derived type, when the dummy argument is an
allocatable array.

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

* [Bug fortran/102287] optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines.
  2021-09-11  0:37 [Bug fortran/102287] New: optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines alipasha.celeris at gmail dot com
@ 2021-09-13 19:37 ` anlauf at gcc dot gnu.org
  2021-09-13 20:55 ` anlauf at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-09-13 19:37 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-09-13
             Status|UNCONFIRMED                 |NEW

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

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

* [Bug fortran/102287] optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines.
  2021-09-11  0:37 [Bug fortran/102287] New: optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines alipasha.celeris at gmail dot com
  2021-09-13 19:37 ` [Bug fortran/102287] " anlauf at gcc dot gnu.org
@ 2021-09-13 20:55 ` anlauf at gcc dot gnu.org
  2021-09-14 19:05 ` anlauf at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-09-13 20:55 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #2 from anlauf at gcc dot gnu.org ---
We need to wrap the deallocation of INTENT(out) allocatable components into
a test for presence, like:

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 18d665192f0..076cffdd77f 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -6548,6 +6548,19 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
                    // deallocate the components first
                    tmp = gfc_deallocate_alloc_comp (fsym->ts.u.derived,
                                                     parmse.expr, e->rank);
+                   /* But check whether dummy argument is optional.  */
+                   if (tmp != NULL_TREE
+                       && fsym->attr.optional
+                       && e->expr_type == EXPR_VARIABLE
+                       && e->symtree->n.sym->attr.optional)
+                     {
+                       tree present, notpres;
+                       present = gfc_conv_expr_present (e->symtree->n.sym);
+                       notpres = build_empty_stmt (input_location);
+                       tmp = fold_build3_loc (input_location, COND_EXPR,
+                                              void_type_node,
+                                              present, tmp, notpres);
+                       }
                    if (tmp != NULL_TREE)
                      gfc_add_expr_to_block (&se->pre, tmp);
                  }

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

* [Bug fortran/102287] optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines.
  2021-09-11  0:37 [Bug fortran/102287] New: optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines alipasha.celeris at gmail dot com
  2021-09-13 19:37 ` [Bug fortran/102287] " anlauf at gcc dot gnu.org
  2021-09-13 20:55 ` anlauf at gcc dot gnu.org
@ 2021-09-14 19:05 ` anlauf at gcc dot gnu.org
  2021-09-16 18:12 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-09-14 19:05 UTC (permalink / raw)
  To: gcc-bugs

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

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 #3 from anlauf at gcc dot gnu.org ---
Slightly cleaned up and submitted:

https://gcc.gnu.org/pipermail/fortran/2021-September/056522.html

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

* [Bug fortran/102287] optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines.
  2021-09-11  0:37 [Bug fortran/102287] New: optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines alipasha.celeris at gmail dot com
                   ` (2 preceding siblings ...)
  2021-09-14 19:05 ` anlauf at gcc dot gnu.org
@ 2021-09-16 18:12 ` cvs-commit at gcc dot gnu.org
  2021-09-19 19:19 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-16 18:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 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:cfea7b86f2430b9cb8018379b071f4004233119c

commit r12-3584-gcfea7b86f2430b9cb8018379b071f4004233119c
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Sep 16 20:12:21 2021 +0200

    Fortran - fix handling of optional allocatable DT arguments with
INTENT(OUT)

    gcc/fortran/ChangeLog:

            PR fortran/102287
            * trans-expr.c (gfc_conv_procedure_call): Wrap deallocation of
            allocatable components of optional allocatable derived type
            procedure arguments with INTENT(OUT) into a presence check.

    gcc/testsuite/ChangeLog:

            PR fortran/102287
            * gfortran.dg/intent_out_14.f90: New test.

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

* [Bug fortran/102287] optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines.
  2021-09-11  0:37 [Bug fortran/102287] New: optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines alipasha.celeris at gmail dot com
                   ` (3 preceding siblings ...)
  2021-09-16 18:12 ` cvs-commit at gcc dot gnu.org
@ 2021-09-19 19:19 ` cvs-commit at gcc dot gnu.org
  2021-09-21 18:51 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-19 19:19 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:6527feb07c31689c6d31b7bd16fec9ada691e06b

commit r11-9015-g6527feb07c31689c6d31b7bd16fec9ada691e06b
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Sep 16 20:12:21 2021 +0200

    Fortran - fix handling of optional allocatable DT arguments with
INTENT(OUT)

    gcc/fortran/ChangeLog:

            PR fortran/102287
            * trans-expr.c (gfc_conv_procedure_call): Wrap deallocation of
            allocatable components of optional allocatable derived type
            procedure arguments with INTENT(OUT) into a presence check.

    gcc/testsuite/ChangeLog:

            PR fortran/102287
            * gfortran.dg/intent_out_14.f90: New test.

    (cherry picked from commit cfea7b86f2430b9cb8018379b071f4004233119c)

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

* [Bug fortran/102287] optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines.
  2021-09-11  0:37 [Bug fortran/102287] New: optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines alipasha.celeris at gmail dot com
                   ` (4 preceding siblings ...)
  2021-09-19 19:19 ` cvs-commit at gcc dot gnu.org
@ 2021-09-21 18:51 ` cvs-commit at gcc dot gnu.org
  2021-09-21 19:06 ` cvs-commit at gcc dot gnu.org
  2021-09-21 19:10 ` anlauf at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-21 18:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 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:216a4be1cc18119a83df562f7abb3dcebd9ce512

commit r10-10141-g216a4be1cc18119a83df562f7abb3dcebd9ce512
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Sep 16 20:12:21 2021 +0200

    Fortran - fix handling of optional allocatable DT arguments with
INTENT(OUT)

    gcc/fortran/ChangeLog:

            PR fortran/102287
            * trans-expr.c (gfc_conv_procedure_call): Wrap deallocation of
            allocatable components of optional allocatable derived type
            procedure arguments with INTENT(OUT) into a presence check.

    gcc/testsuite/ChangeLog:

            PR fortran/102287
            * gfortran.dg/intent_out_14.f90: New test.

    (cherry picked from commit cfea7b86f2430b9cb8018379b071f4004233119c)

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

* [Bug fortran/102287] optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines.
  2021-09-11  0:37 [Bug fortran/102287] New: optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines alipasha.celeris at gmail dot com
                   ` (5 preceding siblings ...)
  2021-09-21 18:51 ` cvs-commit at gcc dot gnu.org
@ 2021-09-21 19:06 ` cvs-commit at gcc dot gnu.org
  2021-09-21 19:10 ` anlauf at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-21 19:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 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:4210c6c62f6938cd70d768b1bd1ea98d13e3b805

commit r9-9737-g4210c6c62f6938cd70d768b1bd1ea98d13e3b805
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Sep 16 20:12:21 2021 +0200

    Fortran - fix handling of optional allocatable DT arguments with
INTENT(OUT)

    gcc/fortran/ChangeLog:

            PR fortran/102287
            * trans-expr.c (gfc_conv_procedure_call): Wrap deallocation of
            allocatable components of optional allocatable derived type
            procedure arguments with INTENT(OUT) into a presence check.

    gcc/testsuite/ChangeLog:

            PR fortran/102287
            * gfortran.dg/intent_out_14.f90: New test.

    (cherry picked from commit cfea7b86f2430b9cb8018379b071f4004233119c)

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

* [Bug fortran/102287] optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines.
  2021-09-11  0:37 [Bug fortran/102287] New: optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines alipasha.celeris at gmail dot com
                   ` (6 preceding siblings ...)
  2021-09-21 19:06 ` cvs-commit at gcc dot gnu.org
@ 2021-09-21 19:10 ` anlauf at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-09-21 19:10 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #8 from anlauf at gcc dot gnu.org ---
Fixed on all open branches.  Closing.

Thanks for the report!

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

end of thread, other threads:[~2021-09-21 19:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-11  0:37 [Bug fortran/102287] New: optional allocatable array arguments (intent out) of derived types with allocatable components are not properly passed to subroutines alipasha.celeris at gmail dot com
2021-09-13 19:37 ` [Bug fortran/102287] " anlauf at gcc dot gnu.org
2021-09-13 20:55 ` anlauf at gcc dot gnu.org
2021-09-14 19:05 ` anlauf at gcc dot gnu.org
2021-09-16 18:12 ` cvs-commit at gcc dot gnu.org
2021-09-19 19:19 ` cvs-commit at gcc dot gnu.org
2021-09-21 18:51 ` cvs-commit at gcc dot gnu.org
2021-09-21 19:06 ` cvs-commit at gcc dot gnu.org
2021-09-21 19:10 ` anlauf 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).