[flang-commits] [PATCH] D142745: [flang] Catch statement function typing error

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Feb 1 11:19:38 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG1b924783003f: [flang] Catch statement function typing error (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142745/new/

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
@@ -7508,7 +7508,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;
@@ -7520,8 +7521,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.494020.patch
Type: text/x-patch
Size: 1887 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230201/ec8c9c66/attachment.bin>


More information about the flang-commits mailing list