Get Source Code Location of a Loop


I was wondering what is the proper way to extract the source code line
info for a loop e.g. where it begins. I was using the getStartLoc()
method from the Loop class. But for the following loop nest:

do k=1,nz <----------- Should report this line
  do i=2,nx
    Dzold = Dz_jlow(i,j,k)
    Dz_jlow(i,j,k) = axe(i) * Dz_jlow(i,j,k) + &
                     bxe(i) * ((Hy(i,j,k )-Hy(i-1,j,k))*dxinv + &
                               (Hx(i,j-1,k)-Hx(i,j,k ))*dyinv)
    Ez(i,j,k) = aye(j) * Ez(i,j,k) + &
                bye(j) * (czh(k)*Dz_jlow(i,j,k) - fzh(k)*Dzold) * epsinv
  end do <------------------ reports this line
end do

If I want to know where in the source code the "k-loop" begins, it
reports the "end do" statement of the inner loop (see above), which is

How to get the proper beginning line in the source?

Thanks a lot.

Loop::getStartLoc() looks up the DebugLoc in the metadata attached to
the loop. It is up to the language frontend (classic flang? f18 flang?
Dragonegg?). Therefore, it is up to the frontend to correctly set that

However, getStartLoc() also has a fallback strategy to look for debug
info of the pre-header. After loop-rotation of the outer loop, the
inner loop's pre-header would might have been merged with the exit
condition of the outer loop.

How to get the proper beginning line in the source?

This is the responsibility of your Fortran front-end.