[Bug fortran/99816] New: fortran do loop line table issue

2021-03-29 Thread andrew.burgess at embecosm dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99816

Bug ID: 99816
   Summary: fortran do loop line table issue
   Product: gcc
   Version: 11.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: fortran
  Assignee: unassigned at gcc dot gnu.org
  Reporter: andrew.burgess at embecosm dot com
  Target Milestone: ---

Consider this Fortran program:

  subroutine sub(a,n)
   dimension a(n)
   do 100 i = 1, n
   a(i) = i
  100  continue ! Breakpoint here.
   return
  end subroutine sub

  program test
dimension a(10)
write(*,*) 'This is a test.'
call sub(a,10)
write(*,*) a
  end program test

The line marked 'Breakpoint here' is line #5.  I compile the test as:

  gfortran -g3 -O0 -o bug.x bug.f90

The run this GDB session:

  $ gdb bug.x
  (gdb) b 5
  Breakpoint 1 at 0x4011de: file bug.f90, line 5.
  (gdb) r
  Starting program: /home/andrew/tmp/bug.x 
   This is a test.

  Breakpoint 1, sub (a=..., n=10) at bug.f90:5
  5 100  continue   ! Breakpoint here.
  (gdb) c
  Continuing.
 1.   2.   3.   4.  
5.   6.   7.   8.   9. 
 10.000
  [Inferior 1 (process 1170395) exited normally]

Notice that the breakpoint was only hit once, despite line #5 being the last
statement _within_ the loop.  My expectation was that this breakpoint would be
hit 10 times.

I then look at the line table (I've truncated the output, but included the
lines we care about):

  $  objdump --dwarf=decodedline bug.x

  bug.x: file format elf64-x86-64

  Contents of the .debug_line section:

  CU: ./bug.f90:
  File nameLine numberStarting addressView 
  Stmt
  bug.f9010x401176 
 x
  bug.f9010x401183 
 x
  bug.f9030x4011a7 
 x
  bug.f9030x4011b4
  bug.f9040x4011c1 
 x
  bug.f9030x4011d8 
 x
  bug.f9050x4011de 
 x
  bug.f9060x4011df 
 x
  bug.f9070x4011e0 
 x
  bug.f9090x4011e3 
 x

Finally, here's a snippet of the generated assembler code (from objdump -d)
with an annotation of my own:

  
  4011b4:   39 55 eccmp%edx,-0x14(%rbp)
  4011b7:   0f 9f c0setg   %al
  4011ba:   0f b6 c0movzbl %al,%eax
  4011bd:   85 c0   test   %eax,%eax
  4011bf:   75 1d   jne4011de 
  4011c1:   8b 45 ecmov-0x14(%rbp),%eax
  4011c4:   48 98   cltq   
  4011c6:   48 8d 48 ff lea-0x1(%rax),%rcx
  4011ca:   f3 0f 2a 45 ec  cvtsi2ssl -0x14(%rbp),%xmm0
  4011cf:   48 8b 45 d8 mov-0x28(%rbp),%rax
  4011d3:   f3 0f 11 04 88  movss  %xmm0,(%rax,%rcx,4)
  4011d8:   83 45 ec 01 addl   $0x1,-0x14(%rbp)
  4011dc:   eb d6   jmp4011b4 
  4011de:   90  nop  <--- Line 5 is
recorded as here!
  4011df:   90  nop
  4011e0:   5b  pop%rbx
  4011e1:   5d  pop%rbp
  4011e2:   c3  retq   

You can see that line 5 is clearly recorded at a point after the loop, hence
why we only hit the breakpoint once.

I've tested this with gfortran versions 'GNU Fortran (GCC) 9.3.1 20200408 (Red
Hat 9.3.1-2)' (my distro's default version) and also with current HEAD of
master branch (e19afa0645f).

[Bug fortran/99027] New: Incorrect ubound result

2021-02-09 Thread andrew.burgess at embecosm dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99027

Bug ID: 99027
   Summary: Incorrect ubound result
   Product: gcc
   Version: 11.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: fortran
  Assignee: unassigned at gcc dot gnu.org
  Reporter: andrew.burgess at embecosm dot com
  Target Milestone: ---

I believe I have run into a case where ubound is giving the wrong result.

Given:

  program test
integer, dimension (1:3,1:6) :: array
print *, "ubound = ", ubound (array (1, 1:4))
  end program test

I see the output:

  ubound =1

When I would have expected:

  ubound =4

Due to array (1, 1:4) being a 4 element 1-dimensional array.

I am seeing this behaviour in my default Fedora compiler:

  GNU Fortran (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)

But I also build current HEAD from git (26a3f288f18) and am still seeing this
issue:

  GNU Fortran (GCC) 11.0.0 20210209 (experimental)

Interestingly, if I change the test program to:

  program test
integer, dimension (1:3,1:6) :: array
print *, "ubound = ", ubound (array (1:2, 1:4))
  end program test

Then I do now see what I would expect for this case:

  ubound =2   4

[Bug fortran/99027] Incorrect ubound result

2021-02-20 Thread andrew.burgess at embecosm dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99027

Andrew Burgess  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|NEW |RESOLVED

--- Comment #4 from Andrew Burgess  ---
Can confirm that with latest GCC HEAD I am now seeing the results that I
expect.  Thanks for the quick fix.