public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/110826] New: Fortran array of derived type with a pointer to function with dimensional arguments
@ 2023-07-26 20:55 mysecmailboks at gmail dot com
  2024-03-08 10:14 ` [Bug fortran/110826] Fortran array of derived type with a pointer to function with dimensional arguments fails redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: mysecmailboks at gmail dot com @ 2023-07-26 20:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110826
           Summary: Fortran array of derived type with a pointer to
                    function with dimensional arguments
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mysecmailboks at gmail dot com
  Target Milestone: ---

The following program fails at `func_array(1)%f => zero_state`:
```
program test_func_array
   implicit none

   type pp
     procedure(func_template), pointer, nopass :: f =>null()
   end type pp

   abstract interface
      function func_template(state) result(dstate)
        implicit none
        real, dimension(:,:), intent(in)                    :: state
        real, dimension(size(state,1), size(state,2)) :: dstate
      end function
   end interface

   type(pp) :: func_array(4)
   real, dimension(4,6) :: state

   func_array(1)%f => zero_state

   print*,func_array(1)%f(state)
contains

  function zero_state(state) result(dstate)
    implicit none
    real, dimension(:,:), intent(in)                    :: state
    real, dimension(size(state,1), size(state,2)) :: dstate

    dstate = 0.

  end function zero_state
end program test_func_array
```
I have tested with various `gfortran` compilers at https://godbolt.org/. The
error is roughly the same. Along the lines of:
```
f951: internal compiler error: spec_dimen_size(): Bad dimension
0x75ee87 gfc_internal_error(char const*, ...)
        ???:0
0x72a016 spec_dimen_size(gfc_array_spec*, int, __mpz_struct (*) [1])
        ???:0
0x7d4bcb gfc_expression_rank(gfc_expr*)
        ???:0
0x7de37b gfc_resolve_code(gfc_code*, gfc_namespace*)
        ???:0
0x7c7500 gfc_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
ASM generation compiler returned: 1
f951: internal compiler error: spec_dimen_size(): Bad dimension
0x75ee87 gfc_internal_error(char const*, ...)
        ???:0
0x72a016 spec_dimen_size(gfc_array_spec*, int, __mpz_struct (*) [1])
        ???:0
0x7d4bcb gfc_expression_rank(gfc_expr*)
        ???:0
0x7de37b gfc_resolve_code(gfc_code*, gfc_namespace*)
        ???:0
0x7c7500 gfc_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Execution build compiler returned: 1
```

The same error is given even if the dimensional arguments are explicitly
defined (as opposed to using `size`).

The program works if func_array is a scalar:
```
   type(pp) :: func_array
   real, dimension(4,6) :: state

   func_array%f => zero_state

   print*,func_array%f(state)
```

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

* [Bug fortran/110826] Fortran array of derived type with a pointer to function with dimensional arguments fails
  2023-07-26 20:55 [Bug fortran/110826] New: Fortran array of derived type with a pointer to function with dimensional arguments mysecmailboks at gmail dot com
@ 2024-03-08 10:14 ` redi at gcc dot gnu.org
  2024-03-11 20:33 ` anlauf at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-08 10:14 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-03-08
     Ever confirmed|0                           |1
           Keywords|                            |ice-on-valid-code
             Status|UNCONFIRMED                 |NEW

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

* [Bug fortran/110826] Fortran array of derived type with a pointer to function with dimensional arguments fails
  2023-07-26 20:55 [Bug fortran/110826] New: Fortran array of derived type with a pointer to function with dimensional arguments mysecmailboks at gmail dot com
  2024-03-08 10:14 ` [Bug fortran/110826] Fortran array of derived type with a pointer to function with dimensional arguments fails redi at gcc dot gnu.org
@ 2024-03-11 20:33 ` anlauf at gcc dot gnu.org
  2024-03-11 21:21 ` anlauf at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-03-11 20:33 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #1 from anlauf at gcc dot gnu.org ---
The following patch appears to fix the ICE and produce working code:

diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc
index 3a6e3a7c95b..0cb636b22c4 100644
--- a/gcc/fortran/array.cc
+++ b/gcc/fortran/array.cc
@@ -2597,6 +2597,13 @@ gfc_array_dimen_size (gfc_expr *array, int dimen, mpz_t
*result)
     case EXPR_FUNCTION:
       for (ref = array->ref; ref; ref = ref->next)
        {
+         /* Ultimate component is a procedure pointer.  */
+         if (ref->type == REF_COMPONENT
+             && !ref->next
+             && ref->u.c.component->attr.function
+             && IS_PROC_POINTER (ref->u.c.component))
+           return false;
+
          if (ref->type != REF_ARRAY)
            continue;

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

* [Bug fortran/110826] Fortran array of derived type with a pointer to function with dimensional arguments fails
  2023-07-26 20:55 [Bug fortran/110826] New: Fortran array of derived type with a pointer to function with dimensional arguments mysecmailboks at gmail dot com
  2024-03-08 10:14 ` [Bug fortran/110826] Fortran array of derived type with a pointer to function with dimensional arguments fails redi at gcc dot gnu.org
  2024-03-11 20:33 ` anlauf at gcc dot gnu.org
@ 2024-03-11 21:21 ` anlauf at gcc dot gnu.org
  2024-03-12 18:16 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-03-11 21:21 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #2 from anlauf at gcc dot gnu.org ---
Submitted: https://gcc.gnu.org/pipermail/fortran/2024-March/060314.html

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

* [Bug fortran/110826] Fortran array of derived type with a pointer to function with dimensional arguments fails
  2023-07-26 20:55 [Bug fortran/110826] New: Fortran array of derived type with a pointer to function with dimensional arguments mysecmailboks at gmail dot com
                   ` (2 preceding siblings ...)
  2024-03-11 21:21 ` anlauf at gcc dot gnu.org
@ 2024-03-12 18:16 ` cvs-commit at gcc dot gnu.org
  2024-03-15 21:08 ` cvs-commit at gcc dot gnu.org
  2024-03-15 21:11 ` anlauf at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-12 18:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from GCC 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:81ee1298b47d3f3b3712ef3f3b2929ca26c4bcd2

commit r14-9442-g81ee1298b47d3f3b3712ef3f3b2929ca26c4bcd2
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Mar 11 22:05:51 2024 +0100

    Fortran: handle procedure pointer component in DT array [PR110826]

    gcc/fortran/ChangeLog:

            PR fortran/110826
            * array.cc (gfc_array_dimen_size): When walking the ref chain of an
            array and the ultimate component is a procedure pointer, do not try
            to figure out its dimension even if it is a array-valued function.

    gcc/testsuite/ChangeLog:

            PR fortran/110826
            * gfortran.dg/proc_ptr_comp_53.f90: New test.

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

* [Bug fortran/110826] Fortran array of derived type with a pointer to function with dimensional arguments fails
  2023-07-26 20:55 [Bug fortran/110826] New: Fortran array of derived type with a pointer to function with dimensional arguments mysecmailboks at gmail dot com
                   ` (3 preceding siblings ...)
  2024-03-12 18:16 ` cvs-commit at gcc dot gnu.org
@ 2024-03-15 21:08 ` cvs-commit at gcc dot gnu.org
  2024-03-15 21:11 ` anlauf at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-15 21:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:4e9f475cdc8617f94c903656faaf28910c21c29b

commit r13-8445-g4e9f475cdc8617f94c903656faaf28910c21c29b
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Mar 11 22:05:51 2024 +0100

    Fortran: handle procedure pointer component in DT array [PR110826]

    gcc/fortran/ChangeLog:

            PR fortran/110826
            * array.cc (gfc_array_dimen_size): When walking the ref chain of an
            array and the ultimate component is a procedure pointer, do not try
            to figure out its dimension even if it is a array-valued function.

    gcc/testsuite/ChangeLog:

            PR fortran/110826
            * gfortran.dg/proc_ptr_comp_53.f90: New test.

    (cherry picked from commit 81ee1298b47d3f3b3712ef3f3b2929ca26c4bcd2)

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

* [Bug fortran/110826] Fortran array of derived type with a pointer to function with dimensional arguments fails
  2023-07-26 20:55 [Bug fortran/110826] New: Fortran array of derived type with a pointer to function with dimensional arguments mysecmailboks at gmail dot com
                   ` (4 preceding siblings ...)
  2024-03-15 21:08 ` cvs-commit at gcc dot gnu.org
@ 2024-03-15 21:11 ` anlauf at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-03-15 21:11 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |13.3
         Resolution|---                         |FIXED

--- Comment #5 from anlauf at gcc dot gnu.org ---
Fixed on mainline for gcc-14, and backported to 13-branch.  Closing.

Thanks for the report!

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

end of thread, other threads:[~2024-03-15 21:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-26 20:55 [Bug fortran/110826] New: Fortran array of derived type with a pointer to function with dimensional arguments mysecmailboks at gmail dot com
2024-03-08 10:14 ` [Bug fortran/110826] Fortran array of derived type with a pointer to function with dimensional arguments fails redi at gcc dot gnu.org
2024-03-11 20:33 ` anlauf at gcc dot gnu.org
2024-03-11 21:21 ` anlauf at gcc dot gnu.org
2024-03-12 18:16 ` cvs-commit at gcc dot gnu.org
2024-03-15 21:08 ` cvs-commit at gcc dot gnu.org
2024-03-15 21:11 ` 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).