[flang-commits] [flang] 3c10eb4 - [flang] Check that a SELECT TYPE selector is not a procedure
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Fri Mar 10 09:08:51 PST 2023
Author: Peter Klausler
Date: 2023-03-10T09:08:43-08:00
New Revision: 3c10eb4942d458245869d167b67af28a1bfa0d5c
URL: https://github.com/llvm/llvm-project/commit/3c10eb4942d458245869d167b67af28a1bfa0d5c
DIFF: https://github.com/llvm/llvm-project/commit/3c10eb4942d458245869d167b67af28a1bfa0d5c.diff
LOG: [flang] Check that a SELECT TYPE selector is not a procedure
A SELECT TYPE statement's selector must be a variable or expression,
not a procedure; specifically, a function with a polymorphic result
is unacceptable.
Differential Revision: https://reviews.llvm.org/D145742
Added:
Modified:
flang/lib/Semantics/check-select-type.cpp
flang/test/Semantics/selecttype01.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-select-type.cpp b/flang/lib/Semantics/check-select-type.cpp
index d1c867c253448..c67248ba62407 100644
--- a/flang/lib/Semantics/check-select-type.cpp
+++ b/flang/lib/Semantics/check-select-type.cpp
@@ -254,16 +254,16 @@ void SelectTypeChecker::Enter(const parser::SelectTypeConstruct &construct) {
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);
+ }
}
}
diff --git a/flang/test/Semantics/selecttype01.f90 b/flang/test/Semantics/selecttype01.f90
index f0b3e6ea103e8..4ac7fe6aafc46 100644
--- a/flang/test/Semantics/selecttype01.f90
+++ b/flang/test/Semantics/selecttype01.f90
@@ -277,3 +277,14 @@ subroutine WorkingPolymorphism
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
More information about the flang-commits
mailing list