[flang-commits] [flang] 047168d - [flang] Fix parser crash (#105875)
via flang-commits
flang-commits at lists.llvm.org
Mon Aug 26 10:54:07 PDT 2024
Author: Peter Klausler
Date: 2024-08-26T10:54:03-07:00
New Revision: 047168dae79cd6e0087eb86810006c635f017df6
URL: https://github.com/llvm/llvm-project/commit/047168dae79cd6e0087eb86810006c635f017df6
DIFF: https://github.com/llvm/llvm-project/commit/047168dae79cd6e0087eb86810006c635f017df6.diff
LOG: [flang] Fix parser crash (#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 https://github.com/llvm/llvm-project/issues/105779.
Added:
flang/test/Parser/recovery05.f90
Modified:
flang/lib/Parser/io-parsers.cpp
Removed:
################################################################################
diff --git a/flang/lib/Parser/io-parsers.cpp b/flang/lib/Parser/io-parsers.cpp
index ca0dbedc8da427..25b09efd40c529 100644
--- a/flang/lib/Parser/io-parsers.cpp
+++ b/flang/lib/Parser/io-parsers.cpp
@@ -27,7 +27,8 @@ TYPE_PARSER(construct<IoUnit>(variable / lookAhead(space / ",);\n"_ch)) ||
construct<IoUnit>(fileUnitNumber) || construct<IoUnit>(star))
// R1202 file-unit-number -> scalar-int-expr
-TYPE_PARSER(construct<FileUnitNumber>(scalarIntExpr / !"="_tok))
+TYPE_PARSER(construct<FileUnitNumber>(
+ scalarIntExpr / (lookAhead(space >> ",)"_ch) || atEndOfStmt)))
// R1204 open-stmt -> OPEN ( connect-spec-list )
TYPE_CONTEXT_PARSER("OPEN statement"_en_US,
diff --git a/flang/test/Parser/recovery05.f90 b/flang/test/Parser/recovery05.f90
new file mode 100644
index 00000000000000..9c8c3689b27bd5
--- /dev/null
+++ b/flang/test/Parser/recovery05.f90
@@ -0,0 +1,5 @@
+! RUN: not %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
+continue
+! CHECK: error: expected end of statement
+flush iostat=1
+end
More information about the flang-commits
mailing list