xref: /aosp_15_r20/external/compiler-rt/test/scudo/alignment.cpp (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clang_scudo %s -o %t
2*7c3d14c8STreehugger Robot // RUN: not %run %t pointers 2>&1 | FileCheck %s
3*7c3d14c8STreehugger Robot 
4*7c3d14c8STreehugger Robot // Tests that a non-16-byte aligned pointer will trigger the associated error
5*7c3d14c8STreehugger Robot // on deallocation.
6*7c3d14c8STreehugger Robot 
7*7c3d14c8STreehugger Robot #include <assert.h>
8*7c3d14c8STreehugger Robot #include <malloc.h>
9*7c3d14c8STreehugger Robot #include <stdint.h>
10*7c3d14c8STreehugger Robot #include <stdlib.h>
11*7c3d14c8STreehugger Robot #include <string.h>
12*7c3d14c8STreehugger Robot 
main(int argc,char ** argv)13*7c3d14c8STreehugger Robot int main(int argc, char **argv)
14*7c3d14c8STreehugger Robot {
15*7c3d14c8STreehugger Robot   assert(argc == 2);
16*7c3d14c8STreehugger Robot   if (!strcmp(argv[1], "pointers")) {
17*7c3d14c8STreehugger Robot     void *p = malloc(1U << 16);
18*7c3d14c8STreehugger Robot     if (!p)
19*7c3d14c8STreehugger Robot       return 1;
20*7c3d14c8STreehugger Robot     free(reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(p) | 8));
21*7c3d14c8STreehugger Robot   }
22*7c3d14c8STreehugger Robot   return 0;
23*7c3d14c8STreehugger Robot }
24*7c3d14c8STreehugger Robot 
25*7c3d14c8STreehugger Robot // CHECK: ERROR: attempted to deallocate a chunk not properly aligned
26