[flang-commits] [PATCH] D145742: [flang] Check that a SELECT TYPE selector is not a procedure

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Mar 9 16:28:49 PST 2023


klausler created this revision.
klausler added a reviewer: clementval.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

A SELECT TYPE statement's selector must be a variable or expression,
not a procedure; specifically, a function with a polymorphic result
is unacceptable.


https://reviews.llvm.org/D145742

Files:
  flang/lib/Semantics/check-select-type.cpp
  flang/test/Semantics/selecttype01.f90


Index: flang/test/Semantics/selecttype01.f90
===================================================================
--- flang/test/Semantics/selecttype01.f90
+++ flang/test/Semantics/selecttype01.f90
@@ -277,3 +277,14 @@
       print *, "default"
   end select
 end
+
+subroutine CheckNotProcedure
+  use m1
+  !ERROR: Selector may not be a procedure
+  select type (x=>f)
+  end select
+ contains
+  function f() result(res)
+    class(shape), allocatable :: res
+  end
+end
Index: flang/lib/Semantics/check-select-type.cpp
===================================================================
--- flang/lib/Semantics/check-select-type.cpp
+++ flang/lib/Semantics/check-select-type.cpp
@@ -254,16 +254,16 @@
       std::get<parser::Statement<parser::SelectTypeStmt>>(construct.t)};
   const auto &selectType{selectTypeStmt.statement};
   const auto &unResolvedSel{std::get<parser::Selector>(selectType.t)};
-  const auto *selector{GetExprFromSelector(unResolvedSel)};
-
-  if (!selector) {
-    return; // expression semantics failed on Selector
-  }
-  if (auto exprType{selector->GetType()}) {
-    const auto &typeCaseList{
-        std::get<std::list<parser::SelectTypeConstruct::TypeCase>>(
-            construct.t)};
-    TypeCaseValues{context_, *exprType}.Check(typeCaseList);
+  if (const auto *selector{GetExprFromSelector(unResolvedSel)}) {
+    if (IsProcedure(*selector)) {
+      context_.Say(
+          selectTypeStmt.source, "Selector may not be a procedure"_err_en_US);
+    } else if (auto exprType{selector->GetType()}) {
+      const auto &typeCaseList{
+          std::get<std::list<parser::SelectTypeConstruct::TypeCase>>(
+              construct.t)};
+      TypeCaseValues{context_, *exprType}.Check(typeCaseList);
+    }
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145742.503967.patch
Type: text/x-patch
Size: 1754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230310/2729b7d8/attachment.bin>


More information about the flang-commits mailing list