From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 01EA5385702E; Mon, 29 Mar 2021 15:36:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01EA5385702E From: "andrew.burgess at embecosm dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: andrew.burgess at embecosm dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Mar 2021 15:36:37 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99816 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 =3D 1, n a(i) =3D 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=20 This is a test. Breakpoint 1, sub (a=3D..., n=3D10) at bug.f90:5 5 100 continue ! Breakpoint here. (gdb) c Continuing. 1.00000000 2.00000000 3.00000000 4.00000000=20=20=20= =20=20=20 5.00000000 6.00000000 7.00000000 8.00000000 9.00000= 000=20 10.0000000=20=20=20=20 [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=3Ddecodedline bug.x bug.x: file format elf64-x86-64 Contents of the .debug_line section: CU: ./bug.f90: File name Line number Starting address V= iew=20 Stmt bug.f90 1 0x401176=20= =20=20=20=20=20=20=20=20 x bug.f90 1 0x401183=20= =20=20=20=20=20=20=20=20 x bug.f90 3 0x4011a7=20= =20=20=20=20=20=20=20=20 x bug.f90 3 0x4011b4=20= =20=20=20=20=20=20=20 bug.f90 4 0x4011c1=20= =20=20=20=20=20=20=20=20 x bug.f90 3 0x4011d8=20= =20=20=20=20=20=20=20=20 x bug.f90 5 0x4011de=20= =20=20=20=20=20=20=20=20 x bug.f90 6 0x4011df=20= =20=20=20=20=20=20=20=20 x bug.f90 7 0x4011e0=20= =20=20=20=20=20=20=20=20 x bug.f90 9 0x4011e3=20= =20=20=20=20=20=20=20=20 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 4011c1: 8b 45 ec mov -0x14(%rbp),%eax 4011c4: 48 98 cltq=20=20=20 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 4011de: 90 nop <----------- Line = 5 is recorded as here! 4011df: 90 nop 4011e0: 5b pop %rbx 4011e1: 5d pop %rbp 4011e2: c3 retq=20=20=20 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).=