[flang-commits] [flang] 60b6730 - [flang] Better error recovery for missing THEN in IF construct
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Thu May 18 11:41:12 PDT 2023
Author: Peter Klausler
Date: 2023-05-18T11:41:07-07:00
New Revision: 60b673023f54e899c727e32414fd89b646a147e4
URL: https://github.com/llvm/llvm-project/commit/60b673023f54e899c727e32414fd89b646a147e4
DIFF: https://github.com/llvm/llvm-project/commit/60b673023f54e899c727e32414fd89b646a147e4.diff
LOG: [flang] Better error recovery for missing THEN in IF construct
Presented with "IF (...)" with no following tokens in the statement,
diagnose a missing "THEN" instead of complaining about all of the
possible action statement initial tokens that could have been there
for a non-construct IF statement.
Fixes https://github.com/llvm/llvm-project/issues/62299.
Differential Revision: https://reviews.llvm.org/D150783
Added:
flang/test/Parser/missing-then.f90
Modified:
flang/lib/Parser/executable-parsers.cpp
Removed:
################################################################################
diff --git a/flang/lib/Parser/executable-parsers.cpp b/flang/lib/Parser/executable-parsers.cpp
index fc67d11a7ed75..92e7d25d93d3b 100644
--- a/flang/lib/Parser/executable-parsers.cpp
+++ b/flang/lib/Parser/executable-parsers.cpp
@@ -305,7 +305,8 @@ TYPE_CONTEXT_PARSER(
TYPE_CONTEXT_PARSER("IF construct"_en_US,
construct<IfConstruct>(
statement(construct<IfThenStmt>(maybe(name / ":"),
- "IF" >> parenthesized(scalarLogicalExpr) / "THEN")),
+ "IF" >> parenthesized(scalarLogicalExpr) /
+ recovery("THEN"_tok, lookAhead(endOfStmt)))),
block,
many(construct<IfConstruct::ElseIfBlock>(
unambiguousStatement(construct<ElseIfStmt>(
diff --git a/flang/test/Parser/missing-then.f90 b/flang/test/Parser/missing-then.f90
new file mode 100644
index 0000000000000..ccaee3e801236
--- /dev/null
+++ b/flang/test/Parser/missing-then.f90
@@ -0,0 +1,8 @@
+! RUN: not %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
+!CHECK: expected 'THEN'
+!CHECK-NOT: expected 'PAUSE'
+if (.TRUE.)
+!CHECK: expected 'THEN'
+else if (.FALSE.)
+end if
+end
More information about the flang-commits
mailing list