[flang-commits] [PATCH] D142745: [flang] Catch statement function typing error
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Fri Jan 27 09:22:58 PST 2023
klausler created this revision.
klausler added a reviewer: jeanPerier.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
Emit an error message when the right-hand side expression of a statement function
definition cannot be converted to the type of the statement function.
https://reviews.llvm.org/D142745
Files:
flang/lib/Semantics/resolve-names.cpp
flang/test/Semantics/stmt-func01.f90
Index: flang/test/Semantics/stmt-func01.f90
===================================================================
--- flang/test/Semantics/stmt-func01.f90
+++ flang/test/Semantics/stmt-func01.f90
@@ -31,6 +31,9 @@
!PORTABILITY: Statement function 'sf8' should not pass an array argument that is not a whole array
sf8(n) = sum(a(1:2))
sf8a(n) = sum(a) ! ok
+ integer :: sf9
+ !ERROR: Defining expression of statement function 'sf9' cannot be converted to its result type INTEGER(4)
+ sf9(n) = "bad"
contains
real function explicit(x,y)
integer, intent(in) :: x
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -7426,7 +7426,8 @@
// expressions, so it's safe to defer processing their definitions.)
void ResolveNamesVisitor::AnalyzeStmtFunctionStmt(
const parser::StmtFunctionStmt &stmtFunc) {
- Symbol *symbol{std::get<parser::Name>(stmtFunc.t).symbol};
+ const auto &name{std::get<parser::Name>(stmtFunc.t)};
+ Symbol *symbol{name.symbol};
auto *details{symbol ? symbol->detailsIf<SubprogramDetails>() : nullptr};
if (!details || !symbol->scope()) {
return;
@@ -7438,8 +7439,12 @@
PopScope();
if (auto expr{AnalyzeExpr(context(), stmtFunc)}) {
if (auto type{evaluate::DynamicType::From(*symbol)}) {
- if (auto converted{ConvertToType(*type, std::move(*expr))}) {
+ if (auto converted{evaluate::ConvertToType(*type, std::move(*expr))}) {
details->set_stmtFunction(std::move(*converted));
+ } else {
+ Say(name.source,
+ "Defining expression of statement function '%s' cannot be converted to its result type %s"_err_en_US,
+ name.source, type->AsFortran());
}
} else {
details->set_stmtFunction(std::move(*expr));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142745.492798.patch
Type: text/x-patch
Size: 1887 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230127/6285c015/attachment-0001.bin>
More information about the flang-commits
mailing list