[flang-commits] [flang] a183668 - [flang] Move check for statement function in BLOCK construct
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Thu Mar 2 13:48:14 PST 2023
Author: Peter Klausler
Date: 2023-03-02T13:48:09-08:00
New Revision: a183668ac6ce276941dd43dddd3eb08a4ed30aa8
URL: https://github.com/llvm/llvm-project/commit/a183668ac6ce276941dd43dddd3eb08a4ed30aa8
DIFF: https://github.com/llvm/llvm-project/commit/a183668ac6ce276941dd43dddd3eb08a4ed30aa8.diff
LOG: [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
Added:
Modified:
flang/lib/Semantics/check-declarations.cpp
flang/lib/Semantics/resolve-names.cpp
flang/test/Semantics/blockconstruct01.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index fc93022af209..540f004863f4 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -1054,6 +1054,11 @@ void CheckHelper::CheckSubprogram(
*host);
}
}
+ 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()
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 774beb60fe78..dbce1ac262cb 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -7692,7 +7692,6 @@ void ResolveNamesVisitor::Post(const parser::TypeGuardStmt &x) {
ConstructVisitor::Post(x);
}
bool ResolveNamesVisitor::Pre(const parser::StmtFunctionStmt &x) {
- CheckNotInBlock("STATEMENT FUNCTION"); // C1107
if (HandleStmtFunction(x)) {
return false;
} else {
diff --git a/flang/test/Semantics/blockconstruct01.f90 b/flang/test/Semantics/blockconstruct01.f90
index f6e9a780b852..3b0a343b15d5 100644
--- a/flang/test/Semantics/blockconstruct01.f90
+++ b/flang/test/Semantics/blockconstruct01.f90
@@ -56,11 +56,11 @@ subroutine s6_c1107(x, y)
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
-
More information about the flang-commits
mailing list