[flang-commits] [PATCH] D150783: [flang] Better error recovery for missing THEN in IF construct

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed May 17 08:01:18 PDT 2023


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a reviewer: sscalpone.
Herald added a project: All.
klausler requested review of this revision.

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.


https://reviews.llvm.org/D150783

Files:
  flang/lib/Parser/executable-parsers.cpp
  flang/test/Parser/missing-then.f90


Index: flang/test/Parser/missing-then.f90
===================================================================
--- /dev/null
+++ 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
Index: flang/lib/Parser/executable-parsers.cpp
===================================================================
--- flang/lib/Parser/executable-parsers.cpp
+++ flang/lib/Parser/executable-parsers.cpp
@@ -305,7 +305,8 @@
 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>(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150783.523053.patch
Type: text/x-patch
Size: 1032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230517/c7c85942/attachment.bin>


More information about the flang-commits mailing list