[flang-commits] [flang] de457f6 - [flang] Error message situation should be a warning

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Oct 6 11:22:05 PDT 2022


Author: Peter Klausler
Date: 2022-10-06T11:21:36-07:00
New Revision: de457f64891c22a4680865642548f21b685491a1

URL: https://github.com/llvm/llvm-project/commit/de457f64891c22a4680865642548f21b685491a1
DIFF: https://github.com/llvm/llvm-project/commit/de457f64891c22a4680865642548f21b685491a1.diff

LOG: [flang] Error message situation should be a warning

f18 emits an error message when the same name is used in a scope
for both a procedure and a generic interface, and the procedure is
not a specific procedure of the generic interface.  It may be
questionable usage, and not portable, but it does not appear to
be non-conforming by a strict reading of the standard, and many
popular Fortran compilers accept it.

Differential Revision: https://reviews.llvm.org/D135205

Added: 
    

Modified: 
    flang/docs/Extensions.md
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Semantics/resolve17.f90
    flang/test/Semantics/resolve18.f90

Removed: 
    


################################################################################
diff  --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index 09b56080832df..f2bce2f86557d 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -440,3 +440,34 @@ end subroutine
   The precedent among the most commonly used compilers
   agrees with f18's interpretation: a `DATA` statement without any other
   specification of the name refers to the host-associated object.
+
+* Many Fortran compilers allow a non-generic procedure to be `USE`-associated
+  into a scope that also contains a generic interface of the same name
+  but does not have the `USE`-associated non-generic procedure as a
+  specific procedure.
+```
+module m1
+ contains
+  subroutine foo(n)
+    integer, intent(in) :: n
+  end subroutine
+end module
+
+module m2
+  use m1, only: foo
+  interface foo
+    module procedure noargs
+  end interface
+ contains
+  subroutine noargs
+  end subroutine
+end module
+```
+
+  This case elicits a warning from f18, as it should not be treated
+  any 
diff erently than the same case with the non-generic procedure of
+  the same name being defined in the same scope rather than being
+  `USE`-associated into it, which is explicitly non-conforming in the
+  standard and not allowed by most other compilers.
+  If the `USE`-associated entity of the same name is not a procedure,
+  most compilers disallow it as well.

diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index df3632616a223..51e07675c0321 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -3196,8 +3196,8 @@ void InterfaceVisitor::CheckGenericProcedures(Symbol &generic) {
   auto &details{generic.get<GenericDetails>()};
   if (auto *proc{details.CheckSpecific()}) {
     auto msg{
-        "'%s' may not be the name of both a generic interface and a"
-        " procedure unless it is a specific procedure of the generic"_err_en_US};
+        "'%s' should not be the name of both a generic interface and a"
+        " procedure unless it is a specific procedure of the generic"_warn_en_US};
     if (proc->name().begin() > generic.name().begin()) {
       Say(proc->name(), std::move(msg));
     } else {

diff  --git a/flang/test/Semantics/resolve17.f90 b/flang/test/Semantics/resolve17.f90
index 76b9cbed1d62f..784abd4a52864 100644
--- a/flang/test/Semantics/resolve17.f90
+++ b/flang/test/Semantics/resolve17.f90
@@ -11,7 +11,7 @@ module m2
   interface s
   end interface
 contains
-  !ERROR: 's' may not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic
+  !WARNING: 's' should not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic
   subroutine s
   end subroutine
 end module

diff  --git a/flang/test/Semantics/resolve18.f90 b/flang/test/Semantics/resolve18.f90
index 16f6ac5ff5f68..edb59e9e131eb 100644
--- a/flang/test/Semantics/resolve18.f90
+++ b/flang/test/Semantics/resolve18.f90
@@ -11,7 +11,7 @@ subroutine foo(x)
 module m2
   use m1
   implicit none
-  !ERROR: 'foo' may not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic
+  !WARNING: 'foo' should not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic
   interface foo
     module procedure s
   end interface


        


More information about the flang-commits mailing list