From 1ac31a0bfa285c403555f8251a8885e817295ef3 Mon Sep 17 00:00:00 2001 From: Jean Perier Date: Tue, 25 Apr 2023 09:05:37 +0200 Subject: [PATCH] [flang][runtime] Fix padding in CHARACTER(4) assignments. 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 --- flang/runtime/assign.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flang/runtime/assign.cpp b/flang/runtime/assign.cpp index 095c4d3b..0b64020 100644 --- a/flang/runtime/assign.cpp +++ b/flang/runtime/assign.cpp @@ -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(toAt)}; std::memmove( p, from.Element>(fromAt), fromElementBytes); - p += fromElementBytes; + p += copiedCharacters; for (auto n{padding}; n-- > 0;) { *p++ = CHAR{' '}; } -- 2.7.4