Skip to content
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
14 changes: 12 additions & 2 deletions flang/lib/Evaluate/variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,11 @@ int BaseObject::Corank() const {
int Component::Corank() const {
if (int corank{symbol_->Corank()}; corank > 0) {
return corank;
} else if (semantics::IsAllocatableOrObjectPointer(&*symbol_)) {
return 0; // coarray subobjects ca%a or ca%p are not coarrays
} else {
return base().Corank();
}
return base().Corank();
}

int NamedEntity::Corank() const {
Expand All @@ -489,7 +492,14 @@ int NamedEntity::Corank() const {
u_);
}

int ArrayRef::Corank() const { return base().Corank(); }
int ArrayRef::Corank() const {
for (const Subscript &subs : subscript_) {
if (!std::holds_alternative<Triplet>(subs.u) && subs.Rank() > 0) {
return 0; // vector-valued subscript - subobject is not a coarray
}
}
return base().Corank();
}

int DataRef::Corank() const {
return common::visit(common::visitors{
Expand Down
22 changes: 22 additions & 0 deletions flang/test/Semantics/coarrays02.f90
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,25 @@ function func2()
!ERROR: Local variable 'local' without the SAVE or ALLOCATABLE attribute may not have a coarray potential subobject component '%comp'
type(t) :: local
end

module m3
type t
real, allocatable :: a(:)
real, pointer :: p(:)
real arr(2)
end type
contains
subroutine sub(ca)
real, intent(in) :: ca(:)[*]
end
subroutine test(cat)
type(t), intent(in) :: cat[*]
call sub(cat%arr(1:2)) ! ok
!ERROR: Actual argument associated with coarray dummy argument 'ca=' must be a coarray
call sub(cat%arr([1]))
!ERROR: Actual argument associated with coarray dummy argument 'ca=' must be a coarray
call sub(cat%a)
!ERROR: Actual argument associated with coarray dummy argument 'ca=' must be a coarray
call sub(cat%p)
end
end