[flang-commits] [flang] e86bf46 - [flang] Disallow intrinsics and statement functions from generics
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Thu Mar 2 09:50:55 PST 2023
Author: Peter Klausler
Date: 2023-03-02T09:50:49-08:00
New Revision: e86bf46825d664f7bde98f2d8b703eb4cceb926c
URL: https://github.com/llvm/llvm-project/commit/e86bf46825d664f7bde98f2d8b703eb4cceb926c
DIFF: https://github.com/llvm/llvm-project/commit/e86bf46825d664f7bde98f2d8b703eb4cceb926c.diff
LOG: [flang] Disallow intrinsics and statement functions from generics
Generic interfaces are not permitted to have intrinsic procedures or
statement functions as specific procedures.
Differential Revision: https://reviews.llvm.org/D145103
Added:
flang/test/Semantics/generic06.f90
Modified:
flang/lib/Semantics/check-declarations.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 8c38d0f59b6e..fe899466130b 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -83,7 +83,7 @@ class CheckHelper {
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 &);
@@ -1346,7 +1346,7 @@ void CheckHelper::CheckHostAssoc(
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);
@@ -1369,7 +1369,7 @@ void CheckHelper::CheckGeneric(
}
// 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_};
@@ -1381,6 +1381,23 @@ void CheckHelper::CheckSpecificsAreDistinguishable(
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()) {
diff --git a/flang/test/Semantics/generic06.f90 b/flang/test/Semantics/generic06.f90
new file mode 100644
index 000000000000..7f4f54b3b52a
--- /dev/null
+++ b/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
+
More information about the flang-commits
mailing list