Skip to content

Commit

Permalink
[flang][runtime] Fix padding in CHARACTER(4) assignments.
Browse files Browse the repository at this point in the history
One piece of pointer arithmetic was adding the number of bytes instead
of the number of characters. This caused failures in CHARACTER(KIND>1)
that required padding.
This was caught using HLFIR that currently uses the runtime for array
assignment where the current lowering does everything inline.

Reviewed By: vzakhari, klausler

Differential Revision: https://reviews.llvm.org/D149062
  • Loading branch information
jeanPerier committed Apr 25, 2023
1 parent c203850 commit 1ac31a0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion flang/runtime/assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,13 @@ static void BlankPadCharacterAssignment(Descriptor &to, const Descriptor &from,
SubscriptValue toAt[], SubscriptValue fromAt[], std::size_t elements,
std::size_t toElementBytes, std::size_t fromElementBytes) {
std::size_t padding{(toElementBytes - fromElementBytes) / sizeof(CHAR)};
std::size_t copiedCharacters{fromElementBytes / sizeof(CHAR)};
for (; elements-- > 0;
to.IncrementSubscripts(toAt), from.IncrementSubscripts(fromAt)) {
CHAR *p{to.Element<CHAR>(toAt)};
std::memmove(
p, from.Element<std::add_const_t<CHAR>>(fromAt), fromElementBytes);
p += fromElementBytes;
p += copiedCharacters;
for (auto n{padding}; n-- > 0;) {
*p++ = CHAR{' '};
}
Expand Down

0 comments on commit 1ac31a0

Please sign in to comment.