Skip to content

Commit 632ed7b

Browse files
[flang] Fixed regression in copy-in/copy-out
Removed incorrect polymprphic check, added regression test. Fixes #159149
1 parent f1b4a3b commit 632ed7b

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed

flang/lib/Evaluate/check-expression.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,36 +1493,6 @@ class CopyInOutExplicitInterface {
14931493
return !actualTreatAsContiguous && dummyNeedsContiguity;
14941494
}
14951495

1496-
// Returns true, if actual and dummy have polymorphic differences
1497-
bool HavePolymorphicDifferences() const {
1498-
bool dummyIsAssumedRank{dummyObj_.type.attrs().test(
1499-
characteristics::TypeAndShape::Attr::AssumedRank)};
1500-
bool actualIsAssumedRank{semantics::IsAssumedRank(actual_)};
1501-
bool dummyIsAssumedShape{dummyObj_.type.attrs().test(
1502-
characteristics::TypeAndShape::Attr::AssumedShape)};
1503-
bool actualIsAssumedShape{semantics::IsAssumedShape(actual_)};
1504-
if ((actualIsAssumedRank && dummyIsAssumedRank) ||
1505-
(actualIsAssumedShape && dummyIsAssumedShape)) {
1506-
// Assumed-rank and assumed-shape arrays are represented by descriptors,
1507-
// so don't need to do polymorphic check.
1508-
} else if (!dummyObj_.ignoreTKR.test(common::IgnoreTKR::Type)) {
1509-
// flang supports limited cases of passing polymorphic to non-polimorphic.
1510-
// These cases require temporary of non-polymorphic type. (For example,
1511-
// the actual argument could be polymorphic array of child type,
1512-
// while the dummy argument could be non-polymorphic array of parent
1513-
// type.)
1514-
bool dummyIsPolymorphic{dummyObj_.type.type().IsPolymorphic()};
1515-
auto actualType{
1516-
characteristics::TypeAndShape::Characterize(actual_, fc_)};
1517-
bool actualIsPolymorphic{
1518-
actualType && actualType->type().IsPolymorphic()};
1519-
if (actualIsPolymorphic && !dummyIsPolymorphic) {
1520-
return true;
1521-
}
1522-
}
1523-
return false;
1524-
}
1525-
15261496
bool HaveArrayOrAssumedRankArgs() const {
15271497
bool dummyTreatAsArray{dummyObj_.ignoreTKR.test(common::IgnoreTKR::Rank)};
15281498
return IsArrayOrAssumedRank(actual_) &&
@@ -1611,9 +1581,6 @@ bool MayNeedCopy(const ActualArgument *actual,
16111581
if (check.HaveContiguityDifferences()) {
16121582
return true;
16131583
}
1614-
if (check.HavePolymorphicDifferences()) {
1615-
return true;
1616-
}
16171584
} else { // Implicit interface
16181585
if (ExtractCoarrayRef(*actual)) {
16191586
// Coindexed actual args may need copy-in and copy-out with implicit

flang/test/Lower/force-temp.f90

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ subroutine pass_intent_out(buf)
2727
integer, intent(out) :: buf(5)
2828
end subroutine
2929
end interface
30+
31+
! Used by s6() and call_s6()
32+
type base
33+
integer :: i = -1
34+
end type
35+
type, extends (base) :: child
36+
real :: r = -2.0
37+
end type
3038
contains
3139
subroutine s1(buf)
3240
!CHECK-LABEL: func.func @_QMtestPs1
@@ -79,4 +87,20 @@ subroutine s5()
7987
p => x(::2) ! pointer to non-contiguous array section
8088
call pass_intent_out(p)
8189
end subroutine
90+
subroutine call_s6()
91+
!CHECK-LABEL: func.func @_QMtestPcall_s6
92+
!CHECK-NOT: hlfir.copy_in
93+
!CHECK: fir.call @_QMtestPs6
94+
!CHECK-NOT: hlfir.copy_out
95+
class(base), pointer :: pb(:)
96+
type(child), target :: c(2)
97+
98+
c = (/(child (i, real(i*2)), i=1,size(c))/)
99+
pb => c
100+
call s6(pb)
101+
end subroutine call_s6
102+
subroutine s6(b)
103+
type(base), intent(inout) :: b(:)
104+
b%i = 42
105+
end subroutine s6
82106
end module

0 commit comments

Comments
 (0)