[libc-commits] [libc] [libc] Fix aligned_alloc used in hermetic tests. (PR #213041)
via libc-commits
libc-commits at lists.llvm.org
Thu Jul 30 08:20:21 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Alexey Samsonov (vonosmas)
<details>
<summary>Changes</summary>
Make sure to use provided alignment both for the pointer to the returned memory chunk and the size.
This fixes occasional segfaults in `hsearch` tests after ce62aab97e58c52e6bb0972c49d6fd1aaa6a08a0, since
hash-table bitmask implementation uses SSE2 intrinsics with 16-byte alignment.
---
Full diff: https://github.com/llvm/llvm-project/pull/213041.diff
1 Files Affected:
- (modified) libc/test/UnitTest/HermeticTestUtils.cpp (+3)
``````````diff
diff --git a/libc/test/UnitTest/HermeticTestUtils.cpp b/libc/test/UnitTest/HermeticTestUtils.cpp
index bcc42bed98eb5..05e2bbdde2603 100644
--- a/libc/test/UnitTest/HermeticTestUtils.cpp
+++ b/libc/test/UnitTest/HermeticTestUtils.cpp
@@ -73,6 +73,9 @@ int atexit(void (*func)(void)) { return LIBC_NAMESPACE::atexit(func); }
void *aligned_alloc(size_t align, size_t s) {
if (align & (align - 1)) // Must be power of 2
return nullptr;
+ uintptr_t ptr_val = reinterpret_cast<uintptr_t>(ptr);
+ uintptr_t aligned_ptr_val = ((ptr_val + align - 1) / align) * align;
+ ptr = reinterpret_cast<uint8_t *>(aligned_ptr_val);
s = ((s + align - 1) / align) * align;
void *mem = ptr;
ptr += s;
``````````
</details>
https://github.com/llvm/llvm-project/pull/213041
More information about the libc-commits
mailing list