Skip to content

Conversation

@klausler
Copy link
Contributor

@klausler klausler commented Mar 3, 2025

The look-ahead parser for function program units didn't allow for a useless label on the statement.

Fixes #129456.

The look-ahead parser for function program units didn't allow
for a useless label on the statement.

Fixes llvm#129456.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:parser labels Mar 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 3, 2025

@llvm/pr-subscribers-flang-parser

Author: Peter Klausler (klausler)

Changes

The look-ahead parser for function program units didn't allow for a useless label on the statement.

Fixes #129456.


Full diff: https://github.com/llvm/llvm-project/pull/129603.diff

2 Files Affected:

  • (modified) flang/lib/Parser/program-parsers.cpp (+1-1)
  • (added) flang/test/Parser/func-label.f (+7)
diff --git a/flang/lib/Parser/program-parsers.cpp b/flang/lib/Parser/program-parsers.cpp
index e365cd24a6aed..d6e7f11297187 100644
--- a/flang/lib/Parser/program-parsers.cpp
+++ b/flang/lib/Parser/program-parsers.cpp
@@ -64,7 +64,7 @@ static constexpr auto programUnit{
     construct<ProgramUnit>(indirect(subroutineSubprogram)) ||
     construct<ProgramUnit>(indirect(Parser<Submodule>{})) ||
     construct<ProgramUnit>(indirect(Parser<BlockData>{})) ||
-    lookAhead(validFunctionStmt) >>
+    lookAhead(maybe(label) >> validFunctionStmt) >>
         construct<ProgramUnit>(indirect(functionSubprogram)) ||
     construct<ProgramUnit>(indirect(Parser<MainProgram>{}))};
 static constexpr auto normalProgramUnit{StartNewSubprogram{} >> programUnit /
diff --git a/flang/test/Parser/func-label.f b/flang/test/Parser/func-label.f
new file mode 100644
index 0000000000000..d78545177f64e
--- /dev/null
+++ b/flang/test/Parser/func-label.f
@@ -0,0 +1,7 @@
+! RUN: %flang_fc1 -fsyntax-only -pedantic %s 2>&1 | FileCheck --allow-empty %s
+!CHECK-NOT: error:
+ 1    function fun()
+ 2    end function
+ 3    write(6,*) "pass"
+ 4    end
+

@klausler klausler merged commit e2733c8 into llvm:main Mar 10, 2025
14 checks passed
@klausler klausler deleted the bug129456 branch March 10, 2025 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:parser flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Flang] Compile error when when a statement label is specified in function statement

3 participants