[flang-commits] [flang] [flang] Record the position of a labeled program-unit END statement (PR #217842)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Fri Aug 21 06:30:15 PDT 2026
================
@@ -0,0 +1,77 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! Every labeled statement records its own source position, so a diagnostic
+! about the label is reported on that statement. The position of a labeled
+! END statement of a program unit is the case worth pinning: label analysis
+! visits it in advance, before the statement visitor reaches it, so the
+! position has to be supplied explicitly rather than taken from the visitor's
+! current position. Without that, the diagnostic below has no location at all.
+!
+! `write(*,fmt=L)` names L as a format; every statement here is something other
+! than a FORMAT statement, so each one is reported.
+
+subroutine construct_stmts(n)
----------------
eugeneepshteyn wrote:
Since this is the file's first program unit, the PR description's own headline shape — a labeled END on the *first* unit, where the error previously had **no location at all** (null position) — isn't pinned: every labeled program-unit END below is in a later unit, which exercises only the stale-position variant (previous unit's position). `test_errors.py` fails on unlocated errors, so the null-position shape is mechanically pinnable; the case just needs to be the first unit in the file (verified to pass with this PR and fail without it):
```fortran
! Labeled END statement of the first program unit in the file: the recorded
! position was previously null, so the diagnostic had no location at all.
subroutine end_first_unit()
write(*,fmt=53)
!ERROR: '53' not a FORMAT
53 end subroutine
```
Optionally, a labeled `END PROCEDURE` case in a submodule would complete coverage of all four END forms the change touches (I verified that shape works).
https://github.com/llvm/llvm-project/pull/217842
More information about the flang-commits
mailing list