[flang-commits] [flang] 646f19b - [flang] Format label scope is independent of block scope

peter klausler via flang-commits flang-commits at lists.llvm.org
Mon Aug 31 13:34:55 PDT 2020


Author: peter klausler
Date: 2020-08-31T13:34:28-07:00
New Revision: 646f19bb9dc86ea5baf38969697a15d0f162ddb0

URL: https://github.com/llvm/llvm-project/commit/646f19bb9dc86ea5baf38969697a15d0f162ddb0
DIFF: https://github.com/llvm/llvm-project/commit/646f19bb9dc86ea5baf38969697a15d0f162ddb0.diff

LOG: [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.

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-labels.cpp
    flang/test/Semantics/io07.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-labels.cpp b/flang/lib/Semantics/resolve-labels.cpp
index 0c67a079d483..2ae84ed02302 100644
--- a/flang/lib/Semantics/resolve-labels.cpp
+++ b/flang/lib/Semantics/resolve-labels.cpp
@@ -935,6 +935,12 @@ void CheckScopeConstraints(const SourceStmtList &stmts,
           parser::MessageFormattedText{
               "Label '%u' was not found"_err_en_US, SayLabel(label)});
     } else if (!InInclusiveScope(scopes, scope, target.proxyForScope)) {
+      // Clause 11.1.2.1 prohibits transfer of control to the interior of a
+      // block from outside the block, but this does not apply to formats.
+      if (target.labeledStmtClassificationSet.test(
+              TargetStatementEnum::Format)) {
+        continue;
+      }
       context.Say(position,
           parser::MessageFormattedText{
               "Label '%u' is not in scope"_en_US, SayLabel(label)});

diff  --git a/flang/test/Semantics/io07.f90 b/flang/test/Semantics/io07.f90
index 6f8c9be80f35..75ca54b43c92 100644
--- a/flang/test/Semantics/io07.f90
+++ b/flang/test/Semantics/io07.f90
@@ -17,6 +17,11 @@
 2011 format(:2L2)
 2012 format(2L2 : 2L2)
 
+     write(*,2013) 'Hello'
+     if (2+2.eq.4) then
+2013   format(A10) ! ok to reference outside the if block
+     endif
+
      ! C1302 warnings; no errors
 2051 format(1X3/)
 2052 format(1X003/)


        


More information about the flang-commits mailing list