[libc-commits] [libc] Fix load64_aligned (PR #71391)

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Mon Nov 6 05:28:50 PST 2023


https://github.com/gchatelet created https://github.com/llvm/llvm-project/pull/71391

Fix #64758 `load64_aligned` was missing a case for `alignment == 6`.


>From bfe9abfa9b5db76bbdaa2f5a5b18f01a71eec18c Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet at google.com>
Date: Mon, 6 Nov 2023 13:18:57 +0000
Subject: [PATCH] [libc] Fix UB in inline_memcpy_aligned_access_64bit

---
 libc/src/string/memory_utils/generic/aligned_access.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libc/src/string/memory_utils/generic/aligned_access.h b/libc/src/string/memory_utils/generic/aligned_access.h
index 4238167e54d644d..65bc63f6cbe5571 100644
--- a/libc/src/string/memory_utils/generic/aligned_access.h
+++ b/libc/src/string/memory_utils/generic/aligned_access.h
@@ -28,7 +28,7 @@ namespace LIBC_NAMESPACE {
     return load32_aligned<uint32_t>(ptr, offset);
   else if (alignment == 2)
     return load32_aligned<uint16_t, uint16_t>(ptr, offset);
-  else
+  else // 1, 3
     return load32_aligned<uint8_t, uint16_t, uint8_t>(ptr, offset);
 }
 
@@ -38,9 +38,11 @@ namespace LIBC_NAMESPACE {
     return load64_aligned<uint64_t>(ptr, offset);
   else if (alignment == 4)
     return load64_aligned<uint32_t, uint32_t>(ptr, offset);
+  else if (alignment == 6)
+    return load64_aligned<uint16_t, uint32_t, uint16_t>(ptr, offset);
   else if (alignment == 2)
     return load64_aligned<uint16_t, uint16_t, uint16_t, uint16_t>(ptr, offset);
-  else
+  else // 1, 3, 5, 7
     return load64_aligned<uint8_t, uint16_t, uint16_t, uint16_t, uint8_t>(
         ptr, offset);
 }



More information about the libc-commits mailing list