[flang-commits] [flang] [flang][parser] handle semicolons uniformly in program unit constructs (PR #181180)
Andre Kuhlenschmidt via flang-commits
flang-commits at lists.llvm.org
Thu Feb 12 08:41:19 PST 2026
https://github.com/akuhlens created https://github.com/llvm/llvm-project/pull/181180
Modifies the parser so that a semicolon is a valid separator between programming unit statements, and tweaks how leading semicolons and spaces are parsed so that they don't count for progress toward programming unit parsing.
fixes [#176994](https://github.com/llvm/llvm-project/issues/176994)
>From 02cc8041dd97537dd970252d70948d9f0f907fad Mon Sep 17 00:00:00 2001
From: Andre Kuhlenschmidt <akuhlenschmi at nvidia.com>
Date: Mon, 9 Feb 2026 15:20:51 -0800
Subject: [PATCH] initial commit
---
flang/lib/Parser/program-parsers.cpp | 11 ++++++-----
flang/test/Parser/bug176914.f90 | 16 ++++++++++++++++
2 files changed, 22 insertions(+), 5 deletions(-)
create mode 100644 flang/test/Parser/bug176914.f90
diff --git a/flang/lib/Parser/program-parsers.cpp b/flang/lib/Parser/program-parsers.cpp
index dac377c29d9db..7aea0ad59ae96 100644
--- a/flang/lib/Parser/program-parsers.cpp
+++ b/flang/lib/Parser/program-parsers.cpp
@@ -68,9 +68,9 @@ static constexpr auto programUnit{
construct<ProgramUnit>(indirect(functionSubprogram)) ||
construct<ProgramUnit>(indirect(Parser<MainProgram>{}))};
-static constexpr auto normalProgramUnit{
- !consumedAllInput >> StartNewSubprogram{} >> programUnit /
- skipMany(";"_tok) / space / recovery(endOfLine, skipToNextLineIfAny)};
+static constexpr auto normalProgramUnit{!consumedAllInput >>
+ StartNewSubprogram{} >>
+ programUnit / recovery(endOfStmt, skipToNextLineIfAny)};
static constexpr auto globalCompilerDirective{
construct<ProgramUnit>(indirect(compilerDirective))};
@@ -91,8 +91,9 @@ TYPE_PARSER(
"nonstandard usage: empty source file"_port_en_US,
skipStuffBeforeStatement >> consumedAllInput >>
pure<std::list<ProgramUnit>>()) ||
- some(globalCompilerDirective || globalOpenACCCompilerDirective ||
- normalProgramUnit) /
+ some(skipStuffBeforeStatement >> (globalCompilerDirective ||
+ globalOpenACCCompilerDirective ||
+ normalProgramUnit)) /
skipStuffBeforeStatement))
// R507 declaration-construct ->
diff --git a/flang/test/Parser/bug176914.f90 b/flang/test/Parser/bug176914.f90
new file mode 100644
index 0000000000000..ee31a1d295ec8
--- /dev/null
+++ b/flang/test/Parser/bug176914.f90
@@ -0,0 +1,16 @@
+!RUN: %flang_fc1 -fdebug-dump-parse-tree-no-sema %s 2>&1 | FileCheck %s
+! CHECK: Program -> ProgramUnit -> MainProgram
+! CHECK-NEXT: | ProgramStmt -> Name = 'semicolon'
+; program semicolon
+use semi;
+IMPLICIT NONE ;
+testvar2 = testvar
+;; ; intvar = testvar + testvar2;intvar2=intvar;
+print *,testvar , testvar2, intvar, intvar2
+! CHECK: | EndProgramStmt
+! CHECK: ProgramUnit -> SubroutineSubprogram
+! CHECK-NEXT: | SubroutineStmt
+! CHECK-NEXT: | | Name = 'test'
+end ; ; subroutine test( arg1, arg2 );real arg1, arg2;;;; arg1=arg2; ; ; end;;;
+;;
+! CHECK: | EndSubroutineStmt
\ No newline at end of file
More information about the flang-commits
mailing list