[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
================
@@ -857,19 +857,25 @@ class ParseTreeAnalyzer {
}
// 6.2.5., paragraph 2
+ //
+ // `position` is the source position of the labeled statement itself. It is
+ // passed in rather than read from currentPosition_ because the END statement
+ // of a program unit is visited in advance, before the statement visitor has
+ // moved currentPosition_ onto it.
void AddTargetLabelDefinition(parser::Label label,
LabeledStmtClassificationSet labeledStmtClassificationSet,
- ProxyForScope scope, bool isExecutableConstructEndStmt) {
+ ProxyForScope scope, bool isExecutableConstructEndStmt,
+ parser::CharBlock position) {
CheckLabelInRange(label);
----------------
eugeneepshteyn wrote:
(Definitely as a separate PR. I can do it, if you like.)
Optional, in-theme completion: `CheckLabelInRange` still reports at `currentPosition_`, so an out-of-range label on a program-unit END stays unlocated even with this PR:
```fortran
subroutine s()
print *, "body"
100000 end subroutine
```
```console
error: Label '100000' is out of range
```
(no source location, before and after). Since this function now has the position in hand, passing it down to `CheckLabelInRange` (and `currentPosition_` from the four `AddLabelReference*` helpers, which are visited normally) completes the plumbing. Fine as an immediate follow-up if you prefer to keep this PR minimal.
https://github.com/llvm/llvm-project/pull/217842
More information about the flang-commits
mailing list