Skip to content

Commit f6fc29d

Browse files
authored
[flang] Check coranks on MOVE_ALLOC (#129944)
The FROM= and TO= arguments in a reference to the MOVE_ALLOC intrinsic subroutine must have the same corank.
1 parent d530790 commit f6fc29d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

flang/lib/Semantics/check-call.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,13 @@ static void CheckMove_Alloc(evaluate::ActualArguments &arguments,
18401840
if (arguments.size() >= 2) {
18411841
evaluate::CheckForCoindexedObject(
18421842
messages, arguments[1], "move_alloc", "to");
1843+
int fromCR{GetCorank(arguments[0])};
1844+
int toCR{GetCorank(arguments[1])};
1845+
if (fromCR != toCR) {
1846+
messages.Say(*arguments[0]->sourceLocation(),
1847+
"FROM= argument to MOVE_ALLOC has corank %d, but TO= argument has corank %d"_err_en_US,
1848+
fromCR, toCR);
1849+
}
18431850
}
18441851
if (arguments.size() >= 3) {
18451852
evaluate::CheckForCoindexedObject(

flang/test/Semantics/move_alloc.f90

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
! RUN: %python %S/test_errors.py %s %flang_fc1
22
! Check for semantic errors in move_alloc() subroutine calls
33
program main
4-
integer, allocatable :: a(:)[:], b(:)[:], f(:), g(:)
4+
integer, allocatable :: a(:)[:], b(:)[:], f(:), g(:), h(:)[:,:]
55
type alloc_component
66
integer, allocatable :: a(:)
77
end type
@@ -73,4 +73,7 @@ program main
7373
!ERROR: Argument #2 to MOVE_ALLOC must be allocatable
7474
call move_alloc(f, g(::2))
7575

76+
!ERROR: FROM= argument to MOVE_ALLOC has corank 1, but TO= argument has corank 2
77+
call move_alloc(a, h)
78+
7679
end program main

0 commit comments

Comments
 (0)