Skip to content

Commit c704050

Browse files
authored
[flang] Reduce implicit interface compatibility warnings due to length (#69385)
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.
1 parent 7fe4025 commit c704050

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

flang/lib/Evaluate/characteristics.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,15 @@ bool DummyDataObject::IsCompatibleWith(
300300
}
301301
return false;
302302
}
303-
if (!type.type().IsTkLenCompatibleWith(actual.type.type())) {
303+
// Treat deduced dummy character type as if it were assumed-length character
304+
// to avoid useless "implicit interfaces have distinct type" warnings from
305+
// CALL FOO('abc'); CALL FOO('abcd').
306+
bool deducedAssumedLength{type.type().category() == TypeCategory::Character &&
307+
attrs.test(Attr::DeducedFromActual)};
308+
bool compatibleTypes{deducedAssumedLength
309+
? type.type().IsTkCompatibleWith(actual.type.type())
310+
: type.type().IsTkLenCompatibleWith(actual.type.type())};
311+
if (!compatibleTypes) {
304312
if (whyNot) {
305313
*whyNot = "incompatible dummy data object types: "s +
306314
type.type().AsFortran() + " vs " + actual.type.type().AsFortran();
@@ -314,7 +322,8 @@ bool DummyDataObject::IsCompatibleWith(
314322
}
315323
return false;
316324
}
317-
if (type.type().category() == TypeCategory::Character) {
325+
if (type.type().category() == TypeCategory::Character &&
326+
!deducedAssumedLength) {
318327
if (actual.type.type().IsAssumedLengthCharacter() !=
319328
type.type().IsAssumedLengthCharacter()) {
320329
if (whyNot) {

flang/test/Semantics/call35.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
! RUN: %python %S/test_errors.py %s %flang_fc1 -Werror
22
subroutine s1
33
call ext(1, 2)
4+
call myerror('abc')
45
end
56

67
subroutine s2
78
!WARNING: Reference to the procedure 'ext' has an implicit interface that is distinct from another reference: distinct numbers of dummy arguments
89
call ext(1.)
10+
call myerror('abcd') ! don't warn about distinct lengths
911
end
1012

1113
subroutine s3

0 commit comments

Comments
 (0)