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

            Bug ID: 92785
           Summary: expressions passed as real arguments to a dummy
                    polymorphic argument fail with indexing error
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: urbanjost at comcast dot net
  Target Milestone: ---

I thought this was a duplicate of Bug 84074 at first.  I could not
find a way to tell when a fix is applied to a release and GNU Fortran
(Ubuntu 9.2.1-17ubuntu1~18.04.1) 9.2.1 20191102 seems to have come out
after the fix for 84074 was applied?

Is there a field somewhere I am missing that would tell at what release
a fix becomes available?

Anyway, I took the code from Bug 84074 and compiled it and it ran OK
so I now assume this is a similar but distinct bug:

TEST PROGRAM

   program tst
      use iso_fortran_env, only : compiler_version, compiler_options
      implicit none
      integer :: i
      integer :: ibad=0
      integer :: iarr(10)=[(i*10,i=1,size(iarr))]
      character(len=:),allocatable :: line
      character(len=*),parameter :: expected= '10 20 30 40 50 60 70 80 90 100'
      print '(4a)', &
         'This file was compiled by ', compiler_version(), &
         ' using the options ',        compiler_options()
      call write_row('iarr                   ',iarr)   ! pass in the array, OK
      call write_row('iarr+0                 ',iarr+0) ! pass in an expression,
SHIFTED(?)
      call write_row('-iarr                  ',-iarr)  ! pass in an expression,
SHIFTED(?)
      call write_row('iarr(::1)              ',iarr(::1))
      call write_row('[iarr(::1)]            ',[iarr(::1)])
      call write_row('[(i*10,i=1,size(iarr))]',[(i*10,i=1,size(iarr))])
      call write_row('10*[(i,i=1,size(iarr))]',10*[(i,i=1,size(iarr))])
      if(ibad.gt.0)stop 'FAILED'
   contains
      subroutine write_scalar(g1)
         class(*) :: g1
         character(len=20) :: word
         select type(g1)
          type is (integer)
            write(word,'(i0)') g1
            line=line//trim(word)//' '
         end select
      end subroutine write_scalar
      subroutine write_row(string,array )
         character(len=*) :: string
         class(*) :: array(:)
         integer  :: i
         line=''
         do i = 1,size(array)
            call write_scalar( array(i) )
         enddo
         if(expected.eq.line)then
            write(*,*)string,':GOOD'
         else
            write(*,*)string,':BAD. EXPECTED [',expected,'] got
[',trim(line),']'
            ibad=ibad+1
         endif
      end subroutine write_row
   end program tst

OUTPUTS

 GIVES BAD ANSWERS WITHOUT BOUNDS CHECK


   This file was compiled by GCC version 9.2.1 20191102 using the options
-mtune=generic -march=x86-64 -Wall -Wextra -fno-strict-aliasing -fwrapv
    iarr                   :GOOD
    iarr+0                 :BAD. EXPECTED [10 20 30 40 50 60 70 80 90 100] got
[20 30 40 50 60 70 80 90 100 335544320]
    -iarr                  :BAD. EXPECTED [10 20 30 40 50 60 70 80 90 100] got
[-20 -30 -40 -50 -60 -70 -80 -90 -100 335544320]
    iarr(::1)              :GOOD
    [iarr(::1)]            :BAD. EXPECTED [10 20 30 40 50 60 70 80 90 100] got
[20 30 40 50 60 70 80 90 100 8064]
    [(i*10,i=1,size(iarr))]:GOOD
    10*[(i,i=1,size(iarr))]:GOOD
   This file was compiled by GCC version 9.2.1 20191102 using the options
-mtune=generic -march=x86-64 -g0 -Wall -Wextra -fbacktrace -fno-strict-aliasing
-fwrapv -fbounds-check
    iarr                   :GOOD
   STOP FAILED

 FAILS WITH BOUNDS CHECK

   At line 36 of file xx.f90
   Fortran runtime error: Index '10' of dimension 1 of array 'array%_data'
above upper bound of 9

   Error termination. Backtrace:
   #0  0x7fab5f57f74a
   #1  0x7fab5f580235
   #2  0x7fab5f580712
   #3  0x7fab5fe0190d
   #4  0x7fab5fe00f58
   #5  0x7fab5fe01f40
   #6  0x7fab5f181b96
   #7  0x7fab5fe00b29
   #8  0xffffffffffffffff

Reply via email to