Skip to content

[flang] Detect more misparsed statement functions (same name as funct… #73852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions flang/lib/Semantics/check-declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,9 @@ void CheckHelper::CheckSubprogram(
if (auto msg{evaluate::CheckStatementFunction(
symbol, *stmtFunction, context_.foldingContext())}) {
SayWithDeclaration(symbol, std::move(*msg));
} else if (IsPointer(symbol)) {
SayWithDeclaration(symbol,
"A statement function must not have the POINTER attribute"_err_en_US);
} else if (details.result().flags().test(Symbol::Flag::Implicit)) {
// 15.6.4 p2 weird requirement
if (const Symbol *
Expand Down
3 changes: 2 additions & 1 deletion flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3508,7 +3508,8 @@ bool SubprogramVisitor::HandleStmtFunction(const parser::StmtFunctionStmt &x) {
Symbol &ultimate{symbol->GetUltimate()};
if (ultimate.has<ObjectEntityDetails>() ||
ultimate.has<AssocEntityDetails>() ||
CouldBeDataPointerValuedFunction(&ultimate)) {
CouldBeDataPointerValuedFunction(&ultimate) ||
(&symbol->owner() == &currScope() && IsFunctionResult(*symbol))) {
misparsedStmtFuncFound_ = true;
return false;
}
Expand Down
30 changes: 30 additions & 0 deletions flang/test/Semantics/stmt-func01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,33 @@ subroutine foo
sf13(x) = 2.*x
end subroutine
end

subroutine s0
allocatable :: sf
!ERROR: 'sf' is not a callable procedure
sf(x) = 1.
end

subroutine s1
asynchronous :: sf
!ERROR: An entity may not have the ASYNCHRONOUS attribute unless it is a variable
sf(x) = 1.
end

subroutine s2
pointer :: sf
!ERROR: A statement function must not have the POINTER attribute
sf(x) = 1.
end

subroutine s3
save :: sf
!ERROR: The entity 'sf' with an explicit SAVE attribute must be a variable, procedure pointer, or COMMON block
sf(x) = 1.
end

subroutine s4
volatile :: sf
!ERROR: VOLATILE attribute may apply only to a variable
sf(x) = 1.
end
19 changes: 19 additions & 0 deletions flang/test/Semantics/stmt-func02.f90
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,23 @@ subroutine test3
!ERROR: 'sf' has not been declared as an array or pointer-valued function
sf(x) = 4.
end
function f()
!ERROR: Recursive call to 'f' requires a distinct RESULT in its declaration
!ERROR: Left-hand side of assignment is not definable
!BECAUSE: 'f()' is not a variable or pointer
f() = 1. ! statement function of same name as function
end
function g() result(r)
!WARNING: Name 'g' from host scope should have a type declaration before its local statement function definition
!ERROR: 'g' is already declared in this scoping unit
g() = 1. ! statement function of same name as function
end
function h1() result(r)
!ERROR: 'r' is not a callable procedure
r() = 1. ! statement function of same name as function result
end
function h2() result(r)
procedure(real), pointer :: r
r() = 1. ! not a statement function
end
end