Skip to content

Commit 646f19b

Browse files
committed
[flang] Format label scope is independent of block scope
Compilation of the following program currently generates a warning message: i = 1 if (i .eq. 0) then write(6, 200) i 200 format (I8) end if write(6, 200) i end x.f90:6:9: Label '200' is not in scope write(6, 200) i ^^^^^^^^^^^^^^^ Whereas branch targets must conform to the Clause 11.1.2.1 program requirement "Transfer of control to the interior of a block from outside the block is prohibited, ...", this doesn't apply to format statement references.
1 parent 8931add commit 646f19b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

flang/lib/Semantics/resolve-labels.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,12 @@ void CheckScopeConstraints(const SourceStmtList &stmts,
935935
parser::MessageFormattedText{
936936
"Label '%u' was not found"_err_en_US, SayLabel(label)});
937937
} else if (!InInclusiveScope(scopes, scope, target.proxyForScope)) {
938+
// Clause 11.1.2.1 prohibits transfer of control to the interior of a
939+
// block from outside the block, but this does not apply to formats.
940+
if (target.labeledStmtClassificationSet.test(
941+
TargetStatementEnum::Format)) {
942+
continue;
943+
}
938944
context.Say(position,
939945
parser::MessageFormattedText{
940946
"Label '%u' is not in scope"_en_US, SayLabel(label)});

flang/test/Semantics/io07.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
2011 format(:2L2)
1818
2012 format(2L2 : 2L2)
1919

20+
write(*,2013) 'Hello'
21+
if (2+2.eq.4) then
22+
2013 format(A10) ! ok to reference outside the if block
23+
endif
24+
2025
! C1302 warnings; no errors
2126
2051 format(1X3/)
2227
2052 format(1X003/)

0 commit comments

Comments
 (0)