[flang-commits] [flang] f0ffc69 - [flang] Fix parsing of WRITE(I+J) with more accurate look-ahead

peter klausler via flang-commits flang-commits at lists.llvm.org
Mon Feb 1 09:08:03 PST 2021


Author: peter klausler
Date: 2021-02-01T09:07:40-08:00
New Revision: f0ffc690d5bcb3d8c373cbe63ac9a2a3a10deee8

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

LOG: [flang] Fix parsing of WRITE(I+J) with more accurate look-ahead

The parsing of I/O units uses look-ahead to discriminate between
keywords, variables and expressions as part of distinguishing internal
from external I/O.  The look-ahead was inaccurate for variables that
appear as the initial parts of expressions.

Differential Revision: https://reviews.llvm.org/D95743

Added: 
    

Modified: 
    flang/lib/Parser/Fortran-parsers.cpp
    flang/lib/Parser/io-parsers.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Parser/Fortran-parsers.cpp b/flang/lib/Parser/Fortran-parsers.cpp
index a21acd04ad36..de59b26d5815 100644
--- a/flang/lib/Parser/Fortran-parsers.cpp
+++ b/flang/lib/Parser/Fortran-parsers.cpp
@@ -1084,7 +1084,8 @@ constexpr auto cosubscript{scalarIntExpr};
 // R924 image-selector ->
 //        lbracket cosubscript-list [, image-selector-spec-list] rbracket
 TYPE_CONTEXT_PARSER("image selector"_en_US,
-    construct<ImageSelector>("[" >> nonemptyList(cosubscript / !"="_tok),
+    construct<ImageSelector>(
+        "[" >> nonemptyList(cosubscript / lookAhead(space / ",]"_ch)),
         defaulted("," >> nonemptyList(Parser<ImageSelectorSpec>{})) / "]"))
 
 // R926 image-selector-spec ->

diff  --git a/flang/lib/Parser/io-parsers.cpp b/flang/lib/Parser/io-parsers.cpp
index 6294e5c40ab9..a4cf6971daf3 100644
--- a/flang/lib/Parser/io-parsers.cpp
+++ b/flang/lib/Parser/io-parsers.cpp
@@ -24,7 +24,7 @@ namespace Fortran::parser {
 // R905 char-variable -> variable
 // "char-variable" is attempted first since it's not type constrained but
 // syntactically ambiguous with "file-unit-number", which is constrained.
-TYPE_PARSER(construct<IoUnit>(variable / !"="_tok) ||
+TYPE_PARSER(construct<IoUnit>(variable / lookAhead(space / ",);\n"_ch)) ||
     construct<IoUnit>(fileUnitNumber) || construct<IoUnit>(star))
 
 // R1202 file-unit-number -> scalar-int-expr


        


More information about the flang-commits mailing list