Skip to content

[flang] Reduce implicit interface compatibility warnings due to length #69385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

klausler
Copy link
Contributor

When a procedure with an implicit interface is called from two call sites with distinct argument types, we emit a warning. This can lead to a lot of output when the actual argument types are differing-length character, and the warnings are less important since the procedure may well have been defined with assumed-length character dummy arguments. So let cases like CALL MYERROR('ab'); CALL MYERROR('abc') slide by without a warning.

@klausler klausler requested a review from clementval October 17, 2023 21:13
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Oct 17, 2023
@llvmbot
Copy link
Member

llvmbot commented Oct 17, 2023

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

When a procedure with an implicit interface is called from two call sites with distinct argument types, we emit a warning. This can lead to a lot of output when the actual argument types are differing-length character, and the warnings are less important since the procedure may well have been defined with assumed-length character dummy arguments. So let cases like CALL MYERROR('ab'); CALL MYERROR('abc') slide by without a warning.


Full diff: https://github.com/llvm/llvm-project/pull/69385.diff

2 Files Affected:

  • (modified) flang/lib/Evaluate/characteristics.cpp (+11-2)
  • (modified) flang/test/Semantics/call35.f90 (+2)
diff --git a/flang/lib/Evaluate/characteristics.cpp b/flang/lib/Evaluate/characteristics.cpp
index ac61e72f428a97e..3074fc0516b46af 100644
--- a/flang/lib/Evaluate/characteristics.cpp
+++ b/flang/lib/Evaluate/characteristics.cpp
@@ -300,7 +300,15 @@ bool DummyDataObject::IsCompatibleWith(
     }
     return false;
   }
-  if (!type.type().IsTkLenCompatibleWith(actual.type.type())) {
+  // Treat deduced dummy character type as if it were assumed-length character
+  // to avoid useless "implicit interfaces have distinct type" warnings from
+  // CALL FOO('abc'); CALL FOO('abcd').
+  bool deducedAssumedLength{type.type().category() == TypeCategory::Character &&
+      attrs.test(Attr::DeducedFromActual)};
+  bool compatibleTypes{deducedAssumedLength
+          ? type.type().IsTkCompatibleWith(actual.type.type())
+          : type.type().IsTkLenCompatibleWith(actual.type.type())};
+  if (!compatibleTypes) {
     if (whyNot) {
       *whyNot = "incompatible dummy data object types: "s +
           type.type().AsFortran() + " vs " + actual.type.type().AsFortran();
@@ -314,7 +322,8 @@ bool DummyDataObject::IsCompatibleWith(
     }
     return false;
   }
-  if (type.type().category() == TypeCategory::Character) {
+  if (type.type().category() == TypeCategory::Character &&
+      !deducedAssumedLength) {
     if (actual.type.type().IsAssumedLengthCharacter() !=
         type.type().IsAssumedLengthCharacter()) {
       if (whyNot) {
diff --git a/flang/test/Semantics/call35.f90 b/flang/test/Semantics/call35.f90
index ddcd64cec6c4341..ff819481226d628 100644
--- a/flang/test/Semantics/call35.f90
+++ b/flang/test/Semantics/call35.f90
@@ -1,11 +1,13 @@
 ! RUN: %python %S/test_errors.py %s %flang_fc1 -Werror
 subroutine s1
   call ext(1, 2)
+  call myerror('abc')
 end
 
 subroutine s2
   !WARNING: Reference to the procedure 'ext' has an implicit interface that is distinct from another reference: distinct numbers of dummy arguments
   call ext(1.)
+  call myerror('abcd') ! don't warn about distinct lengths
 end
 
 subroutine s3

When a procedure with an implicit interface is called from two call
sites with distinct argument types, we emit a warning.  This can lead
to a lot of output when the actual argument types are differing-length
character, and the warnings are less important since the procedure may
well have been defined with assumed-length character dummy arguments.
So let cases like CALL MYERROR('ab'); CALL MYERROR('abc') slide by
without a warning.
@klausler klausler merged commit c704050 into llvm:main Oct 31, 2023
@klausler klausler deleted the jeff-warnings branch October 31, 2023 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants