[flang-commits] [flang] [flang] Turn error case into warning for USE-associated generic (PR #79621)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Jan 26 09:16:21 PST 2024


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/79621

When two USE-associated generic interfaces are merged, we emit an error message if their combination has two or more specific procedures that are not distinguishable by their interfaces. This case doesn't have to be a hard error if none of those specific procedures are ever candidates for any particular procedure reference.

>From b8d27f9e4a2c52059388659c016fb66ca57284a7 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Fri, 26 Jan 2024 09:12:49 -0800
Subject: [PATCH] [flang] Turn error case into warning for USE-associated
 generic

When two USE-associated generic interfaces are merged, we emit
an error message if their combination has two or more specific
procedures that are not distinguishable by their interfaces.
This case doesn't have to be a hard error if none of those specific
procedures are ever candidates for any particular procedure reference.
---
 flang/include/flang/Common/Fortran-features.h | 3 ++-
 flang/lib/Semantics/check-declarations.cpp    | 5 ++++-
 flang/lib/Semantics/expression.cpp            | 2 +-
 flang/test/Semantics/resolve17.f90            | 4 ++--
 flang/test/Semantics/resolve63.f90            | 4 ++--
 5 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/flang/include/flang/Common/Fortran-features.h b/flang/include/flang/Common/Fortran-features.h
index dc50aa7f5c559d..a469a704a24240 100644
--- a/flang/include/flang/Common/Fortran-features.h
+++ b/flang/include/flang/Common/Fortran-features.h
@@ -53,7 +53,8 @@ ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
     ShortCharacterActual, ExprPassedToVolatile, ImplicitInterfaceActual,
     PolymorphicTransferArg, PointerComponentTransferArg, TransferSizePresence,
     F202XAllocatableBreakingChange, DimMustBePresent, CommonBlockPadding,
-    LogicalVsCBool, BindCCharLength, ProcDummyArgShapes)
+    LogicalVsCBool, BindCCharLength, ProcDummyArgShapes,
+    ConflictingUseAssociatedGenerics)
 
 using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>;
 using UsageWarnings = EnumSet<UsageWarning, UsageWarning_enumSize>;
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index d2f0c839cb5eb9..b862bbc2310ef0 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -3548,9 +3548,12 @@ void DistinguishabilityHelper::SayNotDistinguishable(const Scope &scope,
     msg = &context_.Say(name,
         "Generic '%s' may not have specific procedures '%s' and '%s' as their interfaces are not distinguishable"_err_en_US,
         MakeOpName(name), name1, name2);
+  } else if (!context_.languageFeatures().ShouldWarn(
+                 common::UsageWarning::ConflictingUseAssociatedGenerics)) {
+    return;
   } else {
     msg = &context_.Say(*GetTopLevelUnitContaining(proc1).GetName(),
-        "USE-associated generic '%s' may not have specific procedures '%s' and '%s' as their interfaces are not distinguishable"_err_en_US,
+        "USE-associated generic '%s' should not have specific procedures '%s' and '%s' as their interfaces are not distinguishable"_warn_en_US,
         MakeOpName(name), name1, name2);
   }
   AttachDeclaration(*msg, scope, proc1);
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 0e200db5e6bd64..8d817f077880b9 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -2644,7 +2644,7 @@ const Symbol &ExpressionAnalyzer::AccessSpecific(
 void ExpressionAnalyzer::EmitGenericResolutionError(
     const Symbol &symbol, bool dueToAmbiguity, bool isSubroutine) {
   Say(dueToAmbiguity
-          ? "One or more actual arguments to the generic procedure '%s' matched multiple specific procedures, perhaps due to use of NULL() without MOLD= or an actual procedure with an implicit interface"_err_en_US
+          ? "The actual arguments to the generic procedure '%s' matched multiple specific procedures, perhaps due to use of NULL() without MOLD= or an actual procedure with an implicit interface"_err_en_US
           : semantics::IsGenericDefinedOp(symbol)
           ? "No specific procedure of generic operator '%s' matches the actual arguments"_err_en_US
           : isSubroutine
diff --git a/flang/test/Semantics/resolve17.f90 b/flang/test/Semantics/resolve17.f90
index a782a6a7ac3eb9..0975c62d72608c 100644
--- a/flang/test/Semantics/resolve17.f90
+++ b/flang/test/Semantics/resolve17.f90
@@ -1,4 +1,4 @@
-! RUN: %python %S/test_errors.py %s %flang_fc1
+! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
 module m
   integer :: foo
   !Note: PGI, Intel, and GNU allow this; NAG and Sun do not
@@ -180,7 +180,7 @@ subroutine g()
   end
 end module
 subroutine s9
-  !ERROR: USE-associated generic 'g' may not have specific procedures 'g' and 'g' as their interfaces are not distinguishable
+  !WARNING: USE-associated generic 'g' should not have specific procedures 'g' and 'g' as their interfaces are not distinguishable
   use m9a
   use m9b
 end
diff --git a/flang/test/Semantics/resolve63.f90 b/flang/test/Semantics/resolve63.f90
index 5c4d9c69cd85d8..1cb8a8584cc77a 100644
--- a/flang/test/Semantics/resolve63.f90
+++ b/flang/test/Semantics/resolve63.f90
@@ -340,7 +340,7 @@ subroutine test
     call generic(null(), ip) ! ok
     call generic(null(mold=ip), null()) ! ok
     call generic(null(), null(mold=ip)) ! ok
-    !ERROR: One or more actual arguments to the generic procedure 'generic' matched multiple specific procedures, perhaps due to use of NULL() without MOLD= or an actual procedure with an implicit interface
+    !ERROR: The actual arguments to the generic procedure 'generic' matched multiple specific procedures, perhaps due to use of NULL() without MOLD= or an actual procedure with an implicit interface
     call generic(null(), null())
   end subroutine
 end
@@ -358,7 +358,7 @@ subroutine s2(af)
   end subroutine
   subroutine test
     external underspecified
-    !ERROR: One or more actual arguments to the generic procedure 'generic' matched multiple specific procedures, perhaps due to use of NULL() without MOLD= or an actual procedure with an implicit interface
+    !ERROR: The actual arguments to the generic procedure 'generic' matched multiple specific procedures, perhaps due to use of NULL() without MOLD= or an actual procedure with an implicit interface
     call generic(underspecified)
   end subroutine
 end module



More information about the flang-commits mailing list