@@ -244,7 +244,7 @@ static RT_API_ATTRS void BlankPadCharacterAssignment(Descriptor &to,
244244 for (; elements-- > 0 ;
245245 to.IncrementSubscripts (toAt), from.IncrementSubscripts (fromAt)) {
246246 CHAR *p{to.Element <CHAR>(toAt)};
247- Fortran:: runtime::memmove (
247+ runtime::memmove (
248248 p, from.Element <std::add_const_t <CHAR>>(fromAt), fromElementBytes);
249249 p += copiedCharacters;
250250 for (auto n{padding}; n-- > 0 ;) {
@@ -743,22 +743,35 @@ RT_API_ATTRS void DoFromSourceAssign(Descriptor &alloc,
743743 if (alloc.rank () > 0 && source.rank () == 0 ) {
744744 // The value of each element of allocate object becomes the value of source.
745745 DescriptorAddendum *allocAddendum{alloc.Addendum ()};
746- const typeInfo::DerivedType *allocDerived{
747- allocAddendum ? allocAddendum->derivedType () : nullptr };
748746 SubscriptValue allocAt[maxRank];
749747 alloc.GetLowerBounds (allocAt);
750- if (allocDerived) {
748+ std::size_t allocElementBytes{alloc.ElementBytes ()};
749+ if (const typeInfo::DerivedType *allocDerived{
750+ allocAddendum ? allocAddendum->derivedType () : nullptr }) {
751+ // Handle derived type or short character source
751752 for (std::size_t n{alloc.InlineElements ()}; n-- > 0 ;
752753 alloc.IncrementSubscripts (allocAt)) {
753- Descriptor allocElement{*Descriptor::Create (*allocDerived,
754- reinterpret_cast <void *>(alloc.Element <char >(allocAt)), 0 )};
754+ StaticDescriptor<maxRank, true , 8 /* ?*/ > statDesc;
755+ Descriptor &allocElement{statDesc.descriptor ()};
756+ allocElement.Establish (*allocDerived,
757+ reinterpret_cast <void *>(alloc.Element <char >(allocAt)), 0 );
755758 Assign (allocElement, source, terminator, NoAssignFlags, memmoveFct);
756759 }
757- } else { // intrinsic type
760+ } else if (allocElementBytes > source.ElementBytes ()) {
761+ // Scalar expansion of short character source
762+ for (std::size_t n{alloc.InlineElements ()}; n-- > 0 ;
763+ alloc.IncrementSubscripts (allocAt)) {
764+ StaticDescriptor<maxRank, true , 8 /* ?*/ > statDesc;
765+ Descriptor &allocElement{statDesc.descriptor ()};
766+ allocElement.Establish (source.type (), allocElementBytes,
767+ reinterpret_cast <void *>(alloc.Element <char >(allocAt)), 0 );
768+ Assign (allocElement, source, terminator, NoAssignFlags, memmoveFct);
769+ }
770+ } else { // intrinsic type scalar expansion, same data size
758771 for (std::size_t n{alloc.InlineElements ()}; n-- > 0 ;
759772 alloc.IncrementSubscripts (allocAt)) {
760773 memmoveFct (alloc.Element <char >(allocAt), source.raw ().base_addr ,
761- alloc. ElementBytes () );
774+ allocElementBytes );
762775 }
763776 }
764777 } else {
0 commit comments