Skip to content

Commit fd8de75

Browse files
authored
[flang] Check actual/dummy coranks in more cases (#130167)
The check for equality of actual and dummy argument coranks was taking place only for ALLOCATABLE coarrays; perform the check for all cases, and refine the ALLOCATABLE check to apply only to cases that don't fail the new more general check.
1 parent bbc27fb commit fd8de75

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

flang/lib/Semantics/check-call.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,12 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
790790
"ALLOCATABLE %s must have INTENT(IN) to be associated with a coindexed actual argument"_err_en_US,
791791
dummyName);
792792
}
793+
if (!actualIsCoindexed && actualLastSymbol && dummy.type.corank() == 0 &&
794+
actualLastSymbol->Corank() > 0) {
795+
messages.Say(
796+
"ALLOCATABLE %s is not a coarray but actual argument has corank %d"_err_en_US,
797+
dummyName, actualLastSymbol->Corank());
798+
}
793799
} else if (evaluate::IsBareNullPointer(&actual)) {
794800
if (dummyIsOptional) {
795801
} else if (dummy.intent == common::Intent::Default &&
@@ -822,12 +828,6 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
822828
"ALLOCATABLE %s must be associated with an ALLOCATABLE actual argument"_err_en_US,
823829
dummyName);
824830
}
825-
if (!actualIsCoindexed && actualLastSymbol &&
826-
actualLastSymbol->Corank() != dummy.type.corank()) {
827-
messages.Say(
828-
"ALLOCATABLE %s has corank %d but actual argument has corank %d"_err_en_US,
829-
dummyName, dummy.type.corank(), actualLastSymbol->Corank());
830-
}
831831
}
832832

833833
// 15.5.2.7 -- dummy is POINTER
@@ -926,6 +926,11 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
926926
messages.Say(
927927
"Actual argument associated with coarray %s must be a coarray"_err_en_US,
928928
dummyName);
929+
} else if (actualType.corank() != dummy.type.corank() &&
930+
dummyIsAllocatableOrPointer) {
931+
messages.Say(
932+
"ALLOCATABLE or POINTER %s has corank %d but actual argument has corank %d"_err_en_US,
933+
dummyName, dummy.type.corank(), actualType.corank());
929934
}
930935
if (dummyIsVolatile) {
931936
if (!actualIsVolatile) {

flang/test/Semantics/call04.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ subroutine s01c(x)
2626
end subroutine
2727
subroutine s01b ! C846 - can only be caught at a call via explicit interface
2828
!ERROR: ALLOCATABLE coarray 'coarray' may not be associated with INTENT(OUT) dummy argument 'x='
29-
!ERROR: ALLOCATABLE dummy argument 'x=' has corank 0 but actual argument has corank 1
29+
!ERROR: ALLOCATABLE dummy argument 'x=' is not a coarray but actual argument has corank 1
3030
call s01a(coarray)
3131
call s01c(coarray) ! ok, dummy is not allocatable
3232
end subroutine

flang/test/Semantics/call06.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ subroutine test(x)
4141
call s01(allofunc()) ! subtle: ALLOCATABLE function result isn't
4242
call s02(cov) ! ok
4343
call s03(com) ! ok
44-
!ERROR: ALLOCATABLE dummy argument 'x=' has corank 1 but actual argument has corank 2
44+
!ERROR: ALLOCATABLE or POINTER dummy argument 'x=' has corank 1 but actual argument has corank 2
4545
call s02(com)
46-
!ERROR: ALLOCATABLE dummy argument 'x=' has corank 2 but actual argument has corank 1
46+
!ERROR: ALLOCATABLE or POINTER dummy argument 'x=' has corank 2 but actual argument has corank 1
4747
call s03(cov)
4848
call s04(cov[1]) ! ok
4949
!ERROR: ALLOCATABLE dummy argument 'x=' must have INTENT(IN) to be associated with a coindexed actual argument

0 commit comments

Comments
 (0)