1 // Test malloc alignment.
2 // RUN: %clang_hwasan -mllvm -hwasan-globals=0 %s -o %t
6 #include <sanitizer/allocator_interface.h>
7 #include <sanitizer/hwasan_interface.h>
11 static const size_t sizes
[] = {
12 1, 3, 7, 8, 9, 16, 17, 31, 32, 33,
13 63, 64, 65, 127, 128, 129, 511, 512, 513, 2047,
14 2048, 2049, 65535, 65536, 65537, 1048575, 1048576, 1048577};
15 static const size_t alignments
[] = {8, 16, 64, 256, 1024, 4096, 65536, 131072};
17 __attribute__((no_sanitize("hwaddress"))) int main() {
18 for (unsigned i
= 0; i
< sizeof(sizes
) / sizeof(*sizes
); ++i
) {
19 for (unsigned j
= 0; j
< sizeof(alignments
) / sizeof(*alignments
); ++j
) {
20 size_t size
= sizes
[i
];
21 size_t alignment
= alignments
[j
];
22 fprintf(stderr
, "size %zu, alignment %zu (0x%zx)\n", size
, alignment
,
26 for (int k
= 0; k
< cnt
; ++k
) {
27 int res
= posix_memalign(&ptrs
[k
], alignment
, size
);
29 fprintf(stderr
, "... addr 0x%zx\n", (size_t)ptrs
[k
]);
30 assert(((size_t)ptrs
[k
] & (alignment
- 1)) == 0);
32 for (int k
= 0; k
< cnt
; ++k
)