From e2733c82bd5cacfdcb97dfea44f42b70e8b0182c Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Mon, 10 Mar 2025 13:16:09 -0700 Subject: [PATCH] [flang] Accept useless label on top-level FUNCTION (#129603) The look-ahead parser for function program units didn't allow for a useless label on the statement. Fixes https://github.com/llvm/llvm-project/issues/129456. --- flang/lib/Parser/program-parsers.cpp | 2 +- flang/test/Parser/func-label.f | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 flang/test/Parser/func-label.f diff --git a/flang/lib/Parser/program-parsers.cpp b/flang/lib/Parser/program-parsers.cpp index e365cd24a6ae..d6e7f1129718 100644 --- a/flang/lib/Parser/program-parsers.cpp +++ b/flang/lib/Parser/program-parsers.cpp @@ -64,7 +64,7 @@ static constexpr auto programUnit{ construct(indirect(subroutineSubprogram)) || construct(indirect(Parser{})) || construct(indirect(Parser{})) || - lookAhead(validFunctionStmt) >> + lookAhead(maybe(label) >> validFunctionStmt) >> construct(indirect(functionSubprogram)) || construct(indirect(Parser{}))}; 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 000000000000..d78545177f64 --- /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 +