[flang-commits] [PATCH] D145112: [flang] Move check for statement function in BLOCK construct
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Wed Mar 1 12:58:04 PST 2023
klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
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.
https://reviews.llvm.org/D145112
Files:
flang/lib/Semantics/check-declarations.cpp
flang/lib/Semantics/resolve-names.cpp
flang/test/Semantics/blockconstruct01.f90
Index: flang/test/Semantics/blockconstruct01.f90
===================================================================
--- flang/test/Semantics/blockconstruct01.f90
+++ flang/test/Semantics/blockconstruct01.f90
@@ -56,11 +56,11 @@
end
subroutine s7_c1107
- integer x
+ integer x, arr(1)
inc(x) = x + 1
block
- !ERROR: STATEMENT FUNCTION statement is not allowed in a BLOCK construct
+ !ERROR: A statement function definition may not appear in a BLOCK construct
dec(x) = x - 1
+ arr(x) = x - 1 ! ok
end block
end
-
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -7700,7 +7700,6 @@
ConstructVisitor::Post(x);
}
bool ResolveNamesVisitor::Pre(const parser::StmtFunctionStmt &x) {
- CheckNotInBlock("STATEMENT FUNCTION"); // C1107
if (HandleStmtFunction(x)) {
return false;
} else {
Index: flang/lib/Semantics/check-declarations.cpp
===================================================================
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -1045,6 +1045,11 @@
symbol, *stmtFunction, context_.foldingContext())}) {
SayWithDeclaration(symbol, std::move(*msg));
}
+ if (GetProgramUnitOrBlockConstructContaining(symbol).kind() ==
+ Scope::Kind::BlockConstruct) { // C1107
+ messages_.Say(symbol.name(),
+ "A statement function definition may not appear in a BLOCK construct"_err_en_US);
+ }
}
if (IsElementalProcedure(symbol)) {
// See comment on the similar check in CheckProcEntity()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145112.501646.patch
Type: text/x-patch
Size: 1693 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230301/b1257176/attachment-0001.bin>
More information about the flang-commits
mailing list