public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/113363] New: ICE on ASSOCIATE and unlimited polymorphic function
@ 2024-01-12 20:31 anlauf at gcc dot gnu.org
  2024-01-14  8:54 ` [Bug fortran/113363] " pault at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-01-12 20:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113363
           Summary: ICE on ASSOCIATE and unlimited polymorphic function
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anlauf at gcc dot gnu.org
  Target Milestone: ---

While discussing a patch for PR89645/99065, the following issue with
ASSOCIATE and unlimited polymorphic functions was found:

https://gcc.gnu.org/pipermail/fortran/2024-January/060098.html

program p
  implicit none
  class(*), allocatable :: x(:)
  x = foo()
  call prt (x)
  deallocate (x)            ! up to here all is fine...
  associate (var => foo())  ! <- crash here
    call prt (var)          ! <- or here
  end associate
contains
  function foo() result(res)
    class(*), allocatable :: res(:)
    res = [42]
  end function foo
  subroutine prt (x)
    class(*), intent(in) :: x(:)
    select type (x)
    type is (integer)
       print *, x
    class default
       stop 99
    end select
  end subroutine prt
end


This ICEs on current trunk for any of the indicated statements.

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

* [Bug fortran/113363] ICE on ASSOCIATE and unlimited polymorphic function
  2024-01-12 20:31 [Bug fortran/113363] New: ICE on ASSOCIATE and unlimited polymorphic function anlauf at gcc dot gnu.org
@ 2024-01-14  8:54 ` pault at gcc dot gnu.org
  2024-01-14  9:22 ` pault at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2024-01-14  8:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to anlauf from comment #0)
> While discussing a patch for PR89645/99065, the following issue with
> ASSOCIATE and unlimited polymorphic functions was found:
> 
> https://gcc.gnu.org/pipermail/fortran/2024-January/060098.html
> 
> program p
>   implicit none
>   class(*), allocatable :: x(:)
>   x = foo()
>   call prt (x)
>   deallocate (x)            ! up to here all is fine...
>   associate (var => foo())  ! <- crash here
>     call prt (var)          ! <- or here
>   end associate
> contains
>   function foo() result(res)
>     class(*), allocatable :: res(:)
>     res = [42]
>   end function foo
>   subroutine prt (x)
>     class(*), intent(in) :: x(:)
>     select type (x)
>     type is (integer)
>        print *, x
>     class default
>        stop 99
>     end select
>   end subroutine prt
> end
> 
> 
> This ICEs on current trunk for any of the indicated statements.

The associate bit is fixed with a one liner; with the patch applied:
@@ -2295,7 +2305,8 @@ trans_associate_var (gfc_symbol *sym, gfc_wrapped_block
*block)
     }

   /* Set the stringlength, when needed.  */
-  if (need_len_assign)
+  if (need_len_assign
+      && !(e->symtree->n.sym->attr.function && UNLIMITED_POLY
(e->symtree->n.sym)))
     {
       gfc_se se;
       gfc_init_se (&se, NULL);

the following gives the output in the comments:
program p
  implicit none
  class(*), allocatable :: x(:)
  allocate(x, source = foo())
  call prt (x)              ! Wrong output "6 hello e"
  deallocate (x)
  x = foo()
  call prt (x)              ! Wrong output "0  "
  deallocate (x)            !
  associate (var => foo())  ! Now OK
    call prt (var)          ! Now OK - outputs: "6 hello bye   "
  end associate
contains
  function foo() result(res)
    class(*), allocatable :: res(:)
    res = ["hello ","bye   "]
  end function foo
  subroutine prt (x)
    class(*), intent(in) :: x(:)
    select type (x)
    type is (character(*))
       print *, len(x), x
    class default
       stop 99
    end select
  end subroutine prt
end

Both allocation with source and assignment are broken :-(

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

* [Bug fortran/113363] ICE on ASSOCIATE and unlimited polymorphic function
  2024-01-12 20:31 [Bug fortran/113363] New: ICE on ASSOCIATE and unlimited polymorphic function anlauf at gcc dot gnu.org
  2024-01-14  8:54 ` [Bug fortran/113363] " pault at gcc dot gnu.org
@ 2024-01-14  9:22 ` pault at gcc dot gnu.org
  2024-01-17 14:46 ` pault at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2024-01-14  9:22 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-01-14
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           Assignee|unassigned at gcc dot gnu.org      |pault at gcc dot gnu.org

--- Comment #2 from Paul Thomas <pault at gcc dot gnu.org> ---

> 
> Both allocation with source and assignment are broken :-(

With numerical output from foo ([1,2,3,4,5]), we get:

           1           3           5          33           1
           1           2           3           4           5
           1           2           3           4           5

So allocation with source is broken here as well but assignment is OK.

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

* [Bug fortran/113363] ICE on ASSOCIATE and unlimited polymorphic function
  2024-01-12 20:31 [Bug fortran/113363] New: ICE on ASSOCIATE and unlimited polymorphic function anlauf at gcc dot gnu.org
  2024-01-14  8:54 ` [Bug fortran/113363] " pault at gcc dot gnu.org
  2024-01-14  9:22 ` pault at gcc dot gnu.org
@ 2024-01-17 14:46 ` pault at gcc dot gnu.org
  2024-04-03 18:56 ` anlauf at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2024-01-17 14:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to Paul Thomas from comment #2)
> > 
> > Both allocation with source and assignment are broken :-(
> 
> With numerical output from foo ([1,2,3,4,5]), we get:
> 
>            1           3           5          33           1
>            1           2           3           4           5
>            1           2           3           4           5
> 
> So allocation with source is broken here as well but assignment is OK.

I have confirmed that the construction of e3rhs starting at trans-stmt.cc:6653
is the cause of the problem with allocation. I have to put this on one side
until the end of February.

Paul

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

* [Bug fortran/113363] ICE on ASSOCIATE and unlimited polymorphic function
  2024-01-12 20:31 [Bug fortran/113363] New: ICE on ASSOCIATE and unlimited polymorphic function anlauf at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-01-17 14:46 ` pault at gcc dot gnu.org
@ 2024-04-03 18:56 ` anlauf at gcc dot gnu.org
  2024-04-04  6:27 ` pault at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-04-03 18:56 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |14.0
             Status|NEW                         |RESOLVED

--- Comment #4 from anlauf at gcc dot gnu.org ---
This PR has been fixed as part of the large commit r14-9489-g3fd46d859cda10 .

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

* [Bug fortran/113363] ICE on ASSOCIATE and unlimited polymorphic function
  2024-01-12 20:31 [Bug fortran/113363] New: ICE on ASSOCIATE and unlimited polymorphic function anlauf at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-04-03 18:56 ` anlauf at gcc dot gnu.org
@ 2024-04-04  6:27 ` pault at gcc dot gnu.org
  2024-04-04 19:12 ` anlauf at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2024-04-04  6:27 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Thomas <pault at gcc dot gnu.org> changed:

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

--- Comment #5 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to anlauf from comment #4)
> This PR has been fixed as part of the large commit r14-9489-g3fd46d859cda10 .

Not here. As far as I can tell the results remain exactly the same for both
character and numeric results from 'foo'.

Is it possible that there is a patch lurking in your tree that has fixed it?

Cheers

Paul

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

* [Bug fortran/113363] ICE on ASSOCIATE and unlimited polymorphic function
  2024-01-12 20:31 [Bug fortran/113363] New: ICE on ASSOCIATE and unlimited polymorphic function anlauf at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2024-04-04  6:27 ` pault at gcc dot gnu.org
@ 2024-04-04 19:12 ` anlauf at gcc dot gnu.org
  2024-04-06 10:05 ` pault at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-04-04 19:12 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |REOPENED

--- Comment #6 from anlauf at gcc dot gnu.org ---
(In reply to Paul Thomas from comment #5)
> (In reply to anlauf from comment #4)
> > This PR has been fixed as part of the large commit r14-9489-g3fd46d859cda10 .
> 
> Not here. As far as I can tell the results remain exactly the same for both
> character and numeric results from 'foo'.

Oops, I only checked that comment#0 is fixed (-> gfortran.dg/associate_66.f90)
and overlooked the other case in comment#1.

Reopening.

Regarding ALLOCATE with SOURCE and CHARACTER, I have a partial patch
for pr113793.  Need to look again into that one.

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

* [Bug fortran/113363] ICE on ASSOCIATE and unlimited polymorphic function
  2024-01-12 20:31 [Bug fortran/113363] New: ICE on ASSOCIATE and unlimited polymorphic function anlauf at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2024-04-04 19:12 ` anlauf at gcc dot gnu.org
@ 2024-04-06 10:05 ` pault at gcc dot gnu.org
  2024-05-07  7:43 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2024-04-06 10:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 57892
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57892&action=edit
Fix for this PR

The attachment has two fixes for the PR :-)

The first chunk in trans-array.cc is an  alternative to the direct, rather
brutal chunk in trans-stmt.cc. The latter, though, isolates the fix to allocate
statements. I am not entirely sure which is better.

It needs some comments and a proper testcase.

Cheers

Paul

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

* [Bug fortran/113363] ICE on ASSOCIATE and unlimited polymorphic function
  2024-01-12 20:31 [Bug fortran/113363] New: ICE on ASSOCIATE and unlimited polymorphic function anlauf at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2024-04-06 10:05 ` pault at gcc dot gnu.org
@ 2024-05-07  7:43 ` rguenth at gcc dot gnu.org
  2024-05-13  6:27 ` cvs-commit at gcc dot gnu.org
  2024-05-13  6:37 ` pault at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-05-07  7:43 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|14.0                        |14.2

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 14.1 is being released, retargeting bugs to GCC 14.2.

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

* [Bug fortran/113363] ICE on ASSOCIATE and unlimited polymorphic function
  2024-01-12 20:31 [Bug fortran/113363] New: ICE on ASSOCIATE and unlimited polymorphic function anlauf at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2024-05-07  7:43 ` rguenth at gcc dot gnu.org
@ 2024-05-13  6:27 ` cvs-commit at gcc dot gnu.org
  2024-05-13  6:37 ` pault at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-13  6:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Paul Thomas <pault@gcc.gnu.org>:

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

commit r15-394-g2d0eeb529d400e61197a09c56011be976dd81ef0
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Mon May 13 07:27:20 2024 +0100

    Fortran: Fix wrong code in unlimited polymorphic assignment [PR113363]

    2024-05-13  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/113363
            * trans-array.cc (gfc_array_init_size): Use the expr3 dtype so
            that the correct element size is used.
            * trans-expr.cc (gfc_conv_procedure_call): Remove restriction
            that ss and ss->loop be present for the finalization of class
            array function results.
            (trans_class_assignment): Use free and malloc, rather than
            realloc, for character expressions assigned to unlimited poly
            entities.
            * trans-stmt.cc (gfc_trans_allocate): Build a correct rhs for
            the assignment of an unlimited polymorphic 'source'.

    gcc/testsuite/
            PR fortran/113363
            * gfortran.dg/pr113363.f90: New test.

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

* [Bug fortran/113363] ICE on ASSOCIATE and unlimited polymorphic function
  2024-01-12 20:31 [Bug fortran/113363] New: ICE on ASSOCIATE and unlimited polymorphic function anlauf at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2024-05-13  6:27 ` cvs-commit at gcc dot gnu.org
@ 2024-05-13  6:37 ` pault at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2024-05-13  6:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Paul Thomas <pault at gcc dot gnu.org> ---
Leave open partly because it is awaiting backporting to 14-branch but also
because there are remaining, pre-existing issues involving parentheses around
selector/source expressions:
https://gcc.gnu.org/pipermail/fortran/2024-May/060510.html

Paul

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

end of thread, other threads:[~2024-05-13  6:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-12 20:31 [Bug fortran/113363] New: ICE on ASSOCIATE and unlimited polymorphic function anlauf at gcc dot gnu.org
2024-01-14  8:54 ` [Bug fortran/113363] " pault at gcc dot gnu.org
2024-01-14  9:22 ` pault at gcc dot gnu.org
2024-01-17 14:46 ` pault at gcc dot gnu.org
2024-04-03 18:56 ` anlauf at gcc dot gnu.org
2024-04-04  6:27 ` pault at gcc dot gnu.org
2024-04-04 19:12 ` anlauf at gcc dot gnu.org
2024-04-06 10:05 ` pault at gcc dot gnu.org
2024-05-07  7:43 ` rguenth at gcc dot gnu.org
2024-05-13  6:27 ` cvs-commit at gcc dot gnu.org
2024-05-13  6:37 ` pault 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).