Skip to content

Commit 047168d

Browse files
authored
[flang] Fix parser crash (llvm#105875)
The production for a bare file unit number in an I/O statement checks that the scalar integer expression isn't followed by "=", in order to disambiguate FLUSHN from FLUSHN=1, and to not treat a control specifier keyword as an integer expression. The implementation of this check used !"="_tok, which has the side effect of producing no error message; this can lead to a parsing crash later when a failed parse of an erroneous program is found to have produced no errors. Rewrite as a lookAhead call for those characters that acually can follow a bare unit number. Fixes llvm#105779.
1 parent b52728d commit 047168d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

flang/lib/Parser/io-parsers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ TYPE_PARSER(construct<IoUnit>(variable / lookAhead(space / ",);\n"_ch)) ||
2727
construct<IoUnit>(fileUnitNumber) || construct<IoUnit>(star))
2828

2929
// R1202 file-unit-number -> scalar-int-expr
30-
TYPE_PARSER(construct<FileUnitNumber>(scalarIntExpr / !"="_tok))
30+
TYPE_PARSER(construct<FileUnitNumber>(
31+
scalarIntExpr / (lookAhead(space >> ",)"_ch) || atEndOfStmt)))
3132

3233
// R1204 open-stmt -> OPEN ( connect-spec-list )
3334
TYPE_CONTEXT_PARSER("OPEN statement"_en_US,

flang/test/Parser/recovery05.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
! RUN: not %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
2+
continue
3+
! CHECK: error: expected end of statement
4+
flush iostat=1
5+
end

0 commit comments

Comments
 (0)