Skip to content

[flang] Check coranks on MOVE_ALLOC #129944

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
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions flang/lib/Semantics/check-call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,13 @@ static void CheckMove_Alloc(evaluate::ActualArguments &arguments,
if (arguments.size() >= 2) {
evaluate::CheckForCoindexedObject(
messages, arguments[1], "move_alloc", "to");
int fromCR{GetCorank(arguments[0])};
int toCR{GetCorank(arguments[1])};
if (fromCR != toCR) {
messages.Say(*arguments[0]->sourceLocation(),
"FROM= argument to MOVE_ALLOC has corank %d, but TO= argument has corank %d"_err_en_US,
fromCR, toCR);
}
}
if (arguments.size() >= 3) {
evaluate::CheckForCoindexedObject(
Expand Down
5 changes: 4 additions & 1 deletion flang/test/Semantics/move_alloc.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
! Check for semantic errors in move_alloc() subroutine calls
program main
integer, allocatable :: a(:)[:], b(:)[:], f(:), g(:)
integer, allocatable :: a(:)[:], b(:)[:], f(:), g(:), h(:)[:,:]
type alloc_component
integer, allocatable :: a(:)
end type
Expand Down Expand Up @@ -73,4 +73,7 @@ program main
!ERROR: Argument #2 to MOVE_ALLOC must be allocatable
call move_alloc(f, g(::2))

!ERROR: FROM= argument to MOVE_ALLOC has corank 1, but TO= argument has corank 2
call move_alloc(a, h)

end program main