@@ -1493,6 +1493,25 @@ class CopyInOutExplicitInterface {
14931493 return !actualTreatAsContiguous && dummyNeedsContiguity;
14941494 }
14951495
1496+ bool HavePolymorphicDifferences () const {
1497+ // These cases require temporary of non-polymorphic type. (For example,
1498+ // the actual argument could be polymorphic array of child type,
1499+ // while the dummy argument could be non-polymorphic array of parent
1500+ // type.)
1501+ if (dummyObj_.ignoreTKR .test (common::IgnoreTKR::Type)) {
1502+ return false ;
1503+ }
1504+ auto actualType{characteristics::TypeAndShape::Characterize (actual_, fc_)};
1505+ bool actualIsPolymorphic{
1506+ actualType && actualType->type ().IsPolymorphic ()};
1507+ if (actualIsPolymorphic && !dummyObj_.IsPassedByDescriptor (/* isBindC*/ false )) {
1508+ // Not passing a descriptor, so will need to make a copy of the data
1509+ // with a proper type.
1510+ return true ;
1511+ }
1512+ return false ;
1513+ }
1514+
14961515 bool HaveArrayOrAssumedRankArgs () const {
14971516 bool dummyTreatAsArray{dummyObj_.ignoreTKR .test (common::IgnoreTKR::Rank)};
14981517 return IsArrayOrAssumedRank (actual_) &&
@@ -1581,6 +1600,9 @@ bool MayNeedCopy(const ActualArgument *actual,
15811600 if (check.HaveContiguityDifferences ()) {
15821601 return true ;
15831602 }
1603+ if (check.HavePolymorphicDifferences ()) {
1604+ return true ;
1605+ }
15841606 } else { // Implicit interface
15851607 if (ExtractCoarrayRef (*actual)) {
15861608 // Coindexed actual args may need copy-in and copy-out with implicit
0 commit comments