[flang-commits] [PATCH] D110952: [flang] Better error recovery for missing THEN in ELSE IF
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Fri Oct 1 11:31:33 PDT 2021
klausler created this revision.
klausler added a reviewer: clementval.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a reviewer: sscalpone.
klausler requested review of this revision.
The THEN keyword in the "ELSE IF (test) THEN" statement is useless
syntactically, and to omit it is a common error (at least for me!)
that has poor error recovery. This patch changes the parser to
cough up a simple "expected 'THEN'" and still recognize the rest of
the IF construct.
https://reviews.llvm.org/D110952
Files:
flang/lib/Evaluate/check-expression.cpp
flang/lib/Parser/executable-parsers.cpp
flang/test/Parser/elseif-then.f90
Index: flang/test/Parser/elseif-then.f90
===================================================================
--- /dev/null
+++ flang/test/Parser/elseif-then.f90
@@ -0,0 +1,8 @@
+! RUN: not %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
+! CHECK-NOT: expected '=>'
+! CHECK: error: expected 'THEN'
+if (.false.) then
+else if (.false.)
+else
+end if
+end
Index: flang/lib/Parser/executable-parsers.cpp
===================================================================
--- flang/lib/Parser/executable-parsers.cpp
+++ flang/lib/Parser/executable-parsers.cpp
@@ -310,7 +310,7 @@
many(construct<IfConstruct::ElseIfBlock>(
unambiguousStatement(construct<ElseIfStmt>(
"ELSE IF" >> parenthesized(scalarLogicalExpr),
- "THEN" >> maybe(name))),
+ recovery("THEN"_tok, ok) >> maybe(name))),
block)),
maybe(construct<IfConstruct::ElseBlock>(
statement(construct<ElseStmt>("ELSE" >> maybe(name))), block)),
Index: flang/lib/Evaluate/check-expression.cpp
===================================================================
--- flang/lib/Evaluate/check-expression.cpp
+++ flang/lib/Evaluate/check-expression.cpp
@@ -93,7 +93,7 @@
}
bool IsConstantExprHelper::operator()(const ProcedureRef &call) const {
- // LBOUND, UBOUND, and SIZE with DIM= arguments will have been reritten
+ // LBOUND, UBOUND, and SIZE with DIM= arguments will have been rewritten
// into DescriptorInquiry operations.
if (const auto *intrinsic{std::get_if<SpecificIntrinsic>(&call.proc().u)}) {
if (intrinsic->name == "kind" ||
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110952.376583.patch
Type: text/x-patch
Size: 1610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20211001/6825a39a/attachment.bin>
More information about the flang-commits
mailing list