public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/97045] New: A wrong column is selected when addressing individual elements of unlimited polymorphic dummy argument
@ 2020-09-14 14:45 igor.gayday at mu dot edu
  2020-09-20 16:57 ` [Bug fortran/97045] " pault at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: igor.gayday at mu dot edu @ 2020-09-14 14:45 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97045
           Summary: A wrong column is selected when addressing individual
                    elements of unlimited polymorphic dummy argument
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: igor.gayday at mu dot edu
  Target Milestone: ---

Consider the following Fortran program:

program test_prg
  implicit none
  integer :: i
  integer, allocatable :: arr(:, :)

  arr = reshape([(i, i = 1, 100)], [10, 10])
  do i = 1, 3
    print *, 'Column', i
    call write_array(arr(1:2, i)) 
  end do

contains

  subroutine write_array(array)
    class(*), intent(in) :: array(:)
    integer :: i

    do i = 1, size(array)
      select type (elem => array(i))
        type is (integer)
          print '(I0)', elem
      end select
    end do
  end subroutine


  subroutine write_array_alt(array)
    class(*), intent(in) :: array(:)
    integer :: i

    select type (array)
      type is (integer)
        print '(I0)', array
    end select
  end subroutine

end program

Compiled with gfortran 9.3.0 (and 10.2), the program prints:

 Column           1
1
2
 Column           2
21
22
 Column           3
41
42

As you can see, it skips every other column. If I replace the call to
write_array with the call to write_array_alt, where I select type of the whole
array and not individual elements, then every column is printed, as expected.

This issue was originally reported here:
https://stackoverflow.com/questions/63841012/a-wrong-column-is-selected-when-addressing-individual-elements-of-unlimited-poly

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

* [Bug fortran/97045] A wrong column is selected when addressing individual elements of unlimited polymorphic dummy argument
  2020-09-14 14:45 [Bug fortran/97045] New: A wrong column is selected when addressing individual elements of unlimited polymorphic dummy argument igor.gayday at mu dot edu
@ 2020-09-20 16:57 ` pault at gcc dot gnu.org
  2020-09-25 15:34 ` pault at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pault at gcc dot gnu.org @ 2020-09-20 16:57 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pault at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |pault at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-09-20
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #1 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 49244
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49244&action=edit
Patch for the PR

Thanks for posting on Bugzilla, Igor. It makes the workflow much easier.

The attached fixes the problem and regtests OK. The first part of the patch
does not affect your testcase since it only has effect for character selectors.

I'll be some days before I get to submit this because I have a bit of a
backlog.

Regards

Paul

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

* [Bug fortran/97045] A wrong column is selected when addressing individual elements of unlimited polymorphic dummy argument
  2020-09-14 14:45 [Bug fortran/97045] New: A wrong column is selected when addressing individual elements of unlimited polymorphic dummy argument igor.gayday at mu dot edu
  2020-09-20 16:57 ` [Bug fortran/97045] " pault at gcc dot gnu.org
@ 2020-09-25 15:34 ` pault at gcc dot gnu.org
  2020-09-30 12:44 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pault at gcc dot gnu.org @ 2020-09-25 15:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 49272
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49272&action=edit
Updated patch

It turned out that with the original patch, character payloads of the unlimited
polymorphic array were still not behaving properly - see the test below.

I am about to submit to the fortran list.

Thanks again

Paul

! { dg-do run }
!
! Test the fix for PR97045. The report was for the INTEGER version. Testing
! revealed a further bug with the character versions.
!
! Contributed by Igor Gayday  <igor.gayday@mu.edu>
!
program test_prg
  implicit none
  integer :: i
  integer, allocatable :: arr(:, :)
  character(kind = 1, len = 2), allocatable :: chr(:, :)
  character(kind = 4, len = 2), allocatable :: chr4(:, :)

  arr = reshape ([(i, i = 1, 9)], [3, 3])
  do i = 1, 3
    call write_array(arr(1:2, i), i)
  end do

  chr = reshape([(char (i)//char (i+1), i = 65, 83, 2)], [3, 3])
  do i = 1, 3
    call write_array (chr(1:2, i), i)
  end do

  chr4 = reshape([(char (i, kind = 4)//char (i+1, kind = 4), i = 65, 83, 2)], &
                 [3, 3])
  do i = 1, 3
    call write_array (chr4(1:2, i), i)
  end do

contains

  subroutine write_array(array, j)
    class(*), intent(in) :: array(:)
    integer :: i = 2
    integer :: j, k

    select type (elem => array(i))
      type is (integer)
        k = 3*(j-1)+i
        if (elem .ne. k) stop 1
      type is (character(kind = 1, len = *))
        k = 63 + 2*(3*(j-1)+i)
        if (elem .ne. char (k)//char (k+1)) print *, elem, "   ", char
(k)//char (k+1)
      type is (character(kind = 4, len = *))
        k = 63 + 2*(3*(j-1)+i)
        if (elem .ne. char (k, kind = 4)//char (k+1, kind = 4)) stop 3
    end select

  end subroutine

end program

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

* [Bug fortran/97045] A wrong column is selected when addressing individual elements of unlimited polymorphic dummy argument
  2020-09-14 14:45 [Bug fortran/97045] New: A wrong column is selected when addressing individual elements of unlimited polymorphic dummy argument igor.gayday at mu dot edu
  2020-09-20 16:57 ` [Bug fortran/97045] " pault at gcc dot gnu.org
  2020-09-25 15:34 ` pault at gcc dot gnu.org
@ 2020-09-30 12:44 ` cvs-commit at gcc dot gnu.org
  2023-10-30 19:42 ` anlauf at gcc dot gnu.org
  2023-10-31  7:32 ` pault at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-30 12:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS 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:fcc4891d7f3bff1a3f7428f12830bc942989306c

commit r11-3554-gfcc4891d7f3bff1a3f7428f12830bc942989306c
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Wed Sep 30 13:44:39 2020 +0100

    This patch fixes PR97045 - unlimited polymorphic array element selectors.

    2020-30-09  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/97045
            * trans-array.c (gfc_conv_array_ref): Make sure that the class
            decl is passed to build_array_ref in the case of unlimited
            polymorphic entities.
            * trans-expr.c (gfc_conv_derived_to_class): Ensure that array
            refs do not preceed the _len component. Free the _len expr.
            * trans-stmt.c (trans_associate_var): Reset 'need_len_assign'
            for polymorphic scalars.
            * trans.c (gfc_build_array_ref): When the vptr size is used for
            span, multiply by the _len field of unlimited polymorphic
            entities, when non-zero.

    gcc/testsuite/
            PR fortran/97045
            * gfortran.dg/select_type_50.f90 : New test.

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

* [Bug fortran/97045] A wrong column is selected when addressing individual elements of unlimited polymorphic dummy argument
  2020-09-14 14:45 [Bug fortran/97045] New: A wrong column is selected when addressing individual elements of unlimited polymorphic dummy argument igor.gayday at mu dot edu
                   ` (2 preceding siblings ...)
  2020-09-30 12:44 ` cvs-commit at gcc dot gnu.org
@ 2023-10-30 19:42 ` anlauf at gcc dot gnu.org
  2023-10-31  7:32 ` pault at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-10-30 19:42 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |10.5.0
      Known to work|                            |11.3.0
             Status|ASSIGNED                    |WAITING

--- Comment #4 from anlauf at gcc dot gnu.org ---
This PR seems to have been fixed 3 years ago.

@Paul: can we close it?

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

* [Bug fortran/97045] A wrong column is selected when addressing individual elements of unlimited polymorphic dummy argument
  2020-09-14 14:45 [Bug fortran/97045] New: A wrong column is selected when addressing individual elements of unlimited polymorphic dummy argument igor.gayday at mu dot edu
                   ` (3 preceding siblings ...)
  2023-10-30 19:42 ` anlauf at gcc dot gnu.org
@ 2023-10-31  7:32 ` pault at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pault at gcc dot gnu.org @ 2023-10-31  7:32 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #5 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to anlauf from comment #4)
> This PR seems to have been fixed 3 years ago.
> 
> @Paul: can we close it?

That's a grand idea, Harald! Duly closed. I have no idea why it was marked as
'waiting'.

Thanks for the report.

Paul

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

end of thread, other threads:[~2023-10-31  7:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-14 14:45 [Bug fortran/97045] New: A wrong column is selected when addressing individual elements of unlimited polymorphic dummy argument igor.gayday at mu dot edu
2020-09-20 16:57 ` [Bug fortran/97045] " pault at gcc dot gnu.org
2020-09-25 15:34 ` pault at gcc dot gnu.org
2020-09-30 12:44 ` cvs-commit at gcc dot gnu.org
2023-10-30 19:42 ` anlauf at gcc dot gnu.org
2023-10-31  7:32 ` 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).