[libc-commits] [libc] 431c300 - [ARM][Libc] Fix ARM big-endian low-end inline_memset byte fills (#198777)

via libc-commits libc-commits at lists.llvm.org
Wed Jun 17 06:25:43 PDT 2026


Author: Simi Pallipurath
Date: 2026-06-17T14:25:38+01:00
New Revision: 431c300137c9b6b1f481eb3347ec49e3c52a1596

URL: https://github.com/llvm/llvm-project/commit/431c300137c9b6b1f481eb3347ec49e3c52a1596
DIFF: https://github.com/llvm/llvm-project/commit/431c300137c9b6b1f481eb3347ec49e3c52a1596.diff

LOG: [ARM][Libc] Fix ARM big-endian low-end inline_memset byte fills (#198777)

Fix inline_memset_arm_low_end to use the splatted 32-bit fill value for
all byte stores. This ensures that all stores, including unaligned and
trailing byte fills, write the requested repeated byte value on
big-endian ARM.

The low-end ARM memset path already builds value32 as value 0x01010101U
for aligned word/block stores, but its byte-wise prefix and tail
handling still passed the raw 8-bit value * widened to uint32_t. Use
value32 for the byte-wise alignment prefix and final tail loop as well.
This makes the low-end path endian-safe and consistent with
inline_memset_arm_mid_end, fixing incorrect NUL/truncated output in
printf-family formatting and direct memset tests on big-endian ARM
no-unaligned-access targets.

Added: 
    

Modified: 
    libc/src/string/memory_utils/arm/inline_memset.h

Removed: 
    


################################################################################
diff  --git a/libc/src/string/memory_utils/arm/inline_memset.h b/libc/src/string/memory_utils/arm/inline_memset.h
index ce36e40617bb1..5bcf28a2a4978 100644
--- a/libc/src/string/memory_utils/arm/inline_memset.h
+++ b/libc/src/string/memory_utils/arm/inline_memset.h
@@ -79,20 +79,20 @@ set_bytes_and_bump_pointers(Ptr &dst, uint32_t value, size_t size) {
 // not allow unaligned stores so all accesses are aligned.
 [[maybe_unused]] LIBC_INLINE void
 inline_memset_arm_low_end(Ptr dst, uint8_t value, size_t size) {
+  const uint32_t value32 = value * 0x01010101U; // splat value in each byte
   if (size >= 8)
     LIBC_ATTR_LIKELY {
       // Align `dst` to word boundary.
       if (const size_t offset = distance_to_align_up<kWordSize>(dst))
         LIBC_ATTR_UNLIKELY {
-          set_bytes_and_bump_pointers(dst, value, offset);
+          set_bytes_and_bump_pointers(dst, value32, offset);
           size -= offset;
         }
-      const uint32_t value32 = value * 0x01010101U; // splat value in each byte
       consume_by_block<64, AssumeAccess::kAligned>(dst, value32, size);
       consume_by_block<16, AssumeAccess::kAligned>(dst, value32, size);
       consume_by_block<4, AssumeAccess::kAligned>(dst, value32, size);
     }
-  set_bytes_and_bump_pointers(dst, value, size);
+  set_bytes_and_bump_pointers(dst, value32, size);
 }
 
 // Implementation for Cortex-M3, M4, M7, M23, M33, M35P, M52 with hardware


        


More information about the libc-commits mailing list