[Openmp-commits] [openmp] [OpenMP] Fix various alignment issues (PR #142376)
Rainer Orth via Openmp-commits
openmp-commits at lists.llvm.org
Wed Jun 25 04:23:14 PDT 2025
================
@@ -73,7 +73,7 @@ static void bectl(kmp_info_t *th, bget_compact_t compact,
/* On IA-32 architecture with Linux* OS, malloc() does not
ensure 16 byte alignment */
-#if KMP_ARCH_X86 || !KMP_HAVE_QUAD
+#if KMP_ARCH_X86 || KMP_ARCH_SPARC || !KMP_HAVE_QUAD
----------------
rorth wrote:
I've updated this comment now, removing the incorrect Linux reference.
As it turns out, `malloc` alignment is a total can of worms:
- In theory, the address returned should be aligned to `alignof(max_align_t)`.
- However, implementations often differ. E.g. Solaris 32-bit `libc` `malloc` only uses 8-byte alignment. At the time this was introduced, `__float128` didn't exist on x86 yet and it was considered too risky to raise this later for fear of breaking binary compatiblity. Similarly, SPARC uses 8-byte alignment, too, although one could argue that this should be 16 bytes due to the use of 128-bit long double.
- Many platforms have different `malloc` implementions that often differ from the one in `libc`.
- The actual alignment cannot be queried at build or runtime, unfortunately.
That said, it might be prudent to switch to one of `memalign`, `posix_memalign`, or `_aligned_malloc`. GCC's `libgomp` (in `libgomp/alloc.c`:`gomp_aligned_alloc`) went that route, e.g.
https://github.com/llvm/llvm-project/pull/142376
More information about the Openmp-commits
mailing list