public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "andrew.burgess at embecosm dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/99816] New: fortran do loop line table issue
Date: Mon, 29 Mar 2021 15:36:36 +0000	[thread overview]
Message-ID: <bug-99816-4@http.gcc.gnu.org/bugzilla/> (raw)

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.00000000       2.00000000       3.00000000       4.00000000      
5.00000000       6.00000000       7.00000000       8.00000000       9.00000000 
     10.0000000    
  [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 name                            Line number    Starting address    View 
  Stmt
  bug.f90                                        1            0x401176         
     x
  bug.f90                                        1            0x401183         
     x
  bug.f90                                        3            0x4011a7         
     x
  bug.f90                                        3            0x4011b4        
  bug.f90                                        4            0x4011c1         
     x
  bug.f90                                        3            0x4011d8         
     x
  bug.f90                                        5            0x4011de         
     x
  bug.f90                                        6            0x4011df         
     x
  bug.f90                                        7            0x4011e0         
     x
  bug.f90                                        9            0x4011e3         
     x

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

  ....
  4011b4:       39 55 ec                cmp    %edx,-0x14(%rbp)
  4011b7:       0f 9f c0                setg   %al
  4011ba:       0f b6 c0                movzbl %al,%eax
  4011bd:       85 c0                   test   %eax,%eax
  4011bf:       75 1d                   jne    4011de <sub_+0x68>
  4011c1:       8b 45 ec                mov    -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                   jmp    4011b4 <sub_+0x3e>
  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).

             reply	other threads:[~2021-03-29 15:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-29 15:36 andrew.burgess at embecosm dot com [this message]
2021-03-29 16:08 ` [Bug fortran/99816] " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-99816-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).