[flang-commits] [flang] [flang][parser] handle semicolons uniformly in program unit constructs (PR #181180)
via flang-commits
flang-commits at lists.llvm.org
Thu Feb 12 08:41:59 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-parser
Author: Andre Kuhlenschmidt (akuhlens)
<details>
<summary>Changes</summary>
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)
---
Full diff: https://github.com/llvm/llvm-project/pull/181180.diff
2 Files Affected:
- (modified) flang/lib/Parser/program-parsers.cpp (+6-5)
- (added) flang/test/Parser/bug176914.f90 (+16)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/181180
More information about the flang-commits
mailing list