Skip to content

Commit a183668

Browse files
committed
[flang] Move check for statement function in BLOCK construct
A BLOCK construct may not contain a statement function definition; but it may of course contain an assignment statement with an array element on its left-hand side that looks like a statement function definition. These misparsed statement functions are converted into assignment statements during semantics once it is clear what they are. Move the C1107 check for a statement function definition in a block construct into declaration checking, which is where it probably should have been in the first place anyway. Differential Revision: https://reviews.llvm.org/D145112
1 parent f254acf commit a183668

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,11 @@ void CheckHelper::CheckSubprogram(
10541054
*host);
10551055
}
10561056
}
1057+
if (GetProgramUnitOrBlockConstructContaining(symbol).kind() ==
1058+
Scope::Kind::BlockConstruct) { // C1107
1059+
messages_.Say(symbol.name(),
1060+
"A statement function definition may not appear in a BLOCK construct"_err_en_US);
1061+
}
10571062
}
10581063
if (IsElementalProcedure(symbol)) {
10591064
// See comment on the similar check in CheckProcEntity()

flang/lib/Semantics/resolve-names.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7692,7 +7692,6 @@ void ResolveNamesVisitor::Post(const parser::TypeGuardStmt &x) {
76927692
ConstructVisitor::Post(x);
76937693
}
76947694
bool ResolveNamesVisitor::Pre(const parser::StmtFunctionStmt &x) {
7695-
CheckNotInBlock("STATEMENT FUNCTION"); // C1107
76967695
if (HandleStmtFunction(x)) {
76977696
return false;
76987697
} else {

flang/test/Semantics/blockconstruct01.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ subroutine s6_c1107(x, y)
5656
end
5757

5858
subroutine s7_c1107
59-
integer x
59+
integer x, arr(1)
6060
inc(x) = x + 1
6161
block
62-
!ERROR: STATEMENT FUNCTION statement is not allowed in a BLOCK construct
62+
!ERROR: A statement function definition may not appear in a BLOCK construct
6363
dec(x) = x - 1
64+
arr(x) = x - 1 ! ok
6465
end block
6566
end
66-

0 commit comments

Comments
 (0)