Skip to content

Conversation

gchatelet
Copy link
Contributor

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

@llvmbot
Copy link
Member

llvmbot commented Nov 6, 2023

@llvm/pr-subscribers-libc

Author: Guillaume Chatelet (gchatelet)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/71391.diff

1 Files Affected:

  • (modified) libc/src/string/memory_utils/generic/aligned_access.h (+4-2)
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);
 }

@gchatelet gchatelet requested review from petrhosek and lntue November 6, 2023 13:29
@gchatelet
Copy link
Contributor Author

Thx for the quick review @lntue !

@gchatelet gchatelet merged commit bdac972 into llvm:main Nov 6, 2023
@gchatelet gchatelet deleted the fix_64758 branch November 6, 2023 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[libc] UB in llvm-project/libc/src/string/memory_utils/utils.h:assume_aligned
3 participants