[flang-commits] [flang] 1ac31a0 - [flang][runtime] Fix padding in CHARACTER(4) assignments.

Jean Perier via flang-commits flang-commits at lists.llvm.org
Tue Apr 25 00:06:30 PDT 2023


Author: Jean Perier
Date: 2023-04-25T09:05:46+02:00
New Revision: 1ac31a0bfa285c403555f8251a8885e817295ef3

URL: https://github.com/llvm/llvm-project/commit/1ac31a0bfa285c403555f8251a8885e817295ef3
DIFF: https://github.com/llvm/llvm-project/commit/1ac31a0bfa285c403555f8251a8885e817295ef3.diff

LOG: [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

Added: 
    

Modified: 
    flang/runtime/assign.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/assign.cpp b/flang/runtime/assign.cpp
index 095c4d3b9eefd..0b64020811bca 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<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{' '};
     }


        


More information about the flang-commits mailing list