[flang-commits] [flang] [flang] Turn error case into warning for USE-associated generic (PR #79621)
via flang-commits
flang-commits at lists.llvm.org
Fri Jan 26 09:16:52 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/79621.diff
5 Files Affected:
- (modified) flang/include/flang/Common/Fortran-features.h (+2-1)
- (modified) flang/lib/Semantics/check-declarations.cpp (+4-1)
- (modified) flang/lib/Semantics/expression.cpp (+1-1)
- (modified) flang/test/Semantics/resolve17.f90 (+2-2)
- (modified) flang/test/Semantics/resolve63.f90 (+2-2)
``````````diff
diff --git a/flang/include/flang/Common/Fortran-features.h b/flang/include/flang/Common/Fortran-features.h
index dc50aa7f5c559d4..a469a704a242401 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 d2f0c839cb5eb9f..b862bbc2310ef00 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 0e200db5e6bd64d..8d817f077880b9e 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 a782a6a7ac3eb95..0975c62d72608c3 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 5c4d9c69cd85d83..1cb8a8584cc77a2 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
``````````
</details>
https://github.com/llvm/llvm-project/pull/79621
More information about the flang-commits
mailing list