[compiler-rt] Fix 16-byte alignment for vec allocators on AIX (PR #184967)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 31 00:12:02 PDT 2026
================
@@ -0,0 +1,108 @@
+// Verify vec_malloc, vec_calloc and vec_realloc interceptors, and that all
+// vec/plain allocators return 16-byte aligned memory on AIX.
+
+// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: not %run %t vec_malloc 2>&1 | FileCheck %s --check-prefix=CHECK-MALLOC
+// RUN: not %run %t vec_calloc 2>&1 | FileCheck %s --check-prefix=CHECK-CALLOC
+// RUN: not %run %t vec_realloc 2>&1 | FileCheck %s --check-prefix=CHECK-REALLOC
+// RUN: %run %t align 2>&1 | FileCheck %s --check-prefix=CHECK-ALIGN
+
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+// Helper used by the "align" sub-test: prints OK/FAIL to stderr.
+static void check_align(const char *label, void *ptr) {
+ if (((size_t)ptr & 15) != 0) {
+ fprintf(stderr, "FAIL: %s ptr %p not 16-byte aligned\n", label, ptr);
+ exit(1);
+ }
+ fprintf(stderr, "OK: %s\n", label);
+}
+
+int main(int argc, char **argv) {
+ if (argc != 2)
+ return 1;
+
+ // --- overflow detection (existing) ---
+
+ char *p;
+ if (strcmp(argv[1], "vec_malloc") == 0)
+ p = (char *)vec_malloc(10);
+ // CHECK-MALLOC: {{READ of size 1 at 0x.* thread T0}}
+ // CHECK-MALLOC: {{0x.* is located 0 bytes after 10-byte region}}
+ // CHECK-MALLOC: {{0x.* in .vec_malloc}}
+ else if (strcmp(argv[1], "vec_calloc") == 0)
+ p = (char *)vec_calloc(10, 1);
+ // CHECK-CALLOC: {{READ of size 1 at 0x.* thread T0}}
+ // CHECK-CALLOC: {{0x.* is located 0 bytes after 10-byte region}}
+ // CHECK-CALLOC: {{0x.* in .vec_calloc}}
+ else if (strcmp(argv[1], "vec_realloc") == 0)
+ p = (char *)vec_realloc(NULL, 10);
+ // CHECK-REALLOC: {{READ of size 1 at 0x.* thread T0}}
+ // CHECK-REALLOC: {{0x.* is located 0 bytes after 10-byte region}}
+ // On AIX 32-bit vec_realloc resolves to the realloc symbol; match both.
+ // CHECK-REALLOC: {{0x.* in .*realloc}}
+
+ // --- 16-byte alignment checks ---
+
+ else if (strcmp(argv[1], "align") == 0) {
----------------
midhuncodes7 wrote:
perturbed memory layout to advance the allocator's per-size-class pointer by a non-16-byte amount
https://github.com/llvm/llvm-project/pull/184967
More information about the llvm-commits
mailing list