Skip to content

Commit 73b96cf

Browse files
authored
[flang] Refine coarray subobjects (#130183)
A subobject of a coarray is not also a coarray if it involves an allocatable component, pointer component, or vector-valued subscript.
1 parent fd8de75 commit 73b96cf

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

flang/lib/Evaluate/variable.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,11 @@ int BaseObject::Corank() const {
477477
int Component::Corank() const {
478478
if (int corank{symbol_->Corank()}; corank > 0) {
479479
return corank;
480+
} else if (semantics::IsAllocatableOrObjectPointer(&*symbol_)) {
481+
return 0; // coarray subobjects ca%a or ca%p are not coarrays
482+
} else {
483+
return base().Corank();
480484
}
481-
return base().Corank();
482485
}
483486

484487
int NamedEntity::Corank() const {
@@ -489,7 +492,14 @@ int NamedEntity::Corank() const {
489492
u_);
490493
}
491494

492-
int ArrayRef::Corank() const { return base().Corank(); }
495+
int ArrayRef::Corank() const {
496+
for (const Subscript &subs : subscript_) {
497+
if (!std::holds_alternative<Triplet>(subs.u) && subs.Rank() > 0) {
498+
return 0; // vector-valued subscript - subobject is not a coarray
499+
}
500+
}
501+
return base().Corank();
502+
}
493503

494504
int DataRef::Corank() const {
495505
return common::visit(common::visitors{

flang/test/Semantics/coarrays02.f90

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,25 @@ function func2()
4848
!ERROR: Local variable 'local' without the SAVE or ALLOCATABLE attribute may not have a coarray potential subobject component '%comp'
4949
type(t) :: local
5050
end
51+
52+
module m3
53+
type t
54+
real, allocatable :: a(:)
55+
real, pointer :: p(:)
56+
real arr(2)
57+
end type
58+
contains
59+
subroutine sub(ca)
60+
real, intent(in) :: ca(:)[*]
61+
end
62+
subroutine test(cat)
63+
type(t), intent(in) :: cat[*]
64+
call sub(cat%arr(1:2)) ! ok
65+
!ERROR: Actual argument associated with coarray dummy argument 'ca=' must be a coarray
66+
call sub(cat%arr([1]))
67+
!ERROR: Actual argument associated with coarray dummy argument 'ca=' must be a coarray
68+
call sub(cat%a)
69+
!ERROR: Actual argument associated with coarray dummy argument 'ca=' must be a coarray
70+
call sub(cat%p)
71+
end
72+
end

0 commit comments

Comments
 (0)