[flang-commits] [PATCH] D145103: [flang] Disallow intrinsics and statement functions from generics
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Wed Mar 1 11:58:33 PST 2023
klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a reviewer: sscalpone.
Herald added a project: All.
klausler requested review of this revision.
Generic interfaces are not permitted to have intrinsic procedures or
statement functions as specific procedures.
https://reviews.llvm.org/D145103
Files:
flang/lib/Semantics/check-declarations.cpp
flang/test/Semantics/generic06.f90
Index: flang/test/Semantics/generic06.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/generic06.f90
@@ -0,0 +1,20 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+module m
+ !ERROR: Specific procedure 'sin' of generic interface 'yintercept' may not be INTRINSIC
+ intrinsic sin
+ interface yIntercept
+ procedure sin
+ end interface
+ !ERROR: Specific procedure 'cos' of generic interface 'xintercept' may not be INTRINSIC
+ intrinsic cos
+ generic :: xIntercept => cos
+end module
+
+subroutine foo
+ interface slope
+ procedure tan
+ end interface
+ !ERROR: Specific procedure 'tan' of generic interface 'slope' may not be a statement function
+ tan(x) = sin(x) / cos(x)
+end subroutine
+
Index: flang/lib/Semantics/check-declarations.cpp
===================================================================
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -83,7 +83,7 @@
const SourceName &, const Symbol &, const Procedure &, std::size_t);
bool CheckDefinedAssignment(const Symbol &, const Procedure &);
bool CheckDefinedAssignmentArg(const Symbol &, const DummyArgument &, int);
- void CheckSpecificsAreDistinguishable(const Symbol &, const GenericDetails &);
+ void CheckSpecifics(const Symbol &, const GenericDetails &);
void CheckEquivalenceSet(const EquivalenceSet &);
void CheckBlockData(const Scope &);
void CheckGenericOps(const Scope &);
@@ -1337,7 +1337,7 @@
void CheckHelper::CheckGeneric(
const Symbol &symbol, const GenericDetails &details) {
- CheckSpecificsAreDistinguishable(symbol, details);
+ CheckSpecifics(symbol, details);
common::visit(common::visitors{
[&](const GenericKind::DefinedIo &io) {
CheckDefinedIoProc(symbol, details, io);
@@ -1360,11 +1360,36 @@
}
// Check that the specifics of this generic are distinguishable from each other
-void CheckHelper::CheckSpecificsAreDistinguishable(
+void CheckHelper::CheckSpecifics(
const Symbol &generic, const GenericDetails &details) {
GenericKind kind{details.kind()};
DistinguishabilityHelper helper{context_};
for (const Symbol &specific : details.specificProcs()) {
+ if (specific.attrs().test(Attr::ABSTRACT)) {
+ if (auto *msg{messages_.Say(generic.name(),
+ "Generic interface '%s' must not use abstract interface '%s' as a specific procedure"_err_en_US,
+ generic.name(), specific.name())}) {
+ msg->Attach(
+ specific.name(), "Definition of '%s'"_en_US, specific.name());
+ }
+ continue;
+ }
+ if (specific.attrs().test(Attr::INTRINSIC)) {
+ if (auto *msg{messages_.Say(specific.name(),
+ "Specific procedure '%s' of generic interface '%s' may not be INTRINSIC"_err_en_US,
+ specific.name(), generic.name())}) {
+ msg->Attach(generic.name(), "Definition of '%s'"_en_US, generic.name());
+ }
+ continue;
+ }
+ if (IsStmtFunction(specific)) {
+ if (auto *msg{messages_.Say(specific.name(),
+ "Specific procedure '%s' of generic interface '%s' may not be a statement function"_err_en_US,
+ specific.name(), generic.name())}) {
+ msg->Attach(generic.name(), "Definition of '%s'"_en_US, generic.name());
+ }
+ continue;
+ }
if (const Procedure *procedure{Characterize(specific)}) {
if (procedure->HasExplicitInterface()) {
helper.Add(generic, kind, specific, *procedure);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145103.501617.patch
Type: text/x-patch
Size: 3573 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230301/984f553b/attachment-0001.bin>
More information about the flang-commits
mailing list