]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/scudo/realloc.cpp
1 // RUN: %clang_scudo %s -o %t
2 // RUN: %run %t pointers 2>&1
3 // RUN: %run %t contents 2>&1
4 // RUN: not %run %t memalign 2>&1 | FileCheck %s
6 // Tests that our reallocation function returns the same pointer when the
7 // requested size can fit into the previously allocated chunk. Also tests that
8 // a new chunk is returned if the size is greater, and that the contents of the
9 // chunk are left unchanged.
10 // As a final test, make sure that a chunk allocated by memalign cannot be
17 int main(int argc
, char **argv
)
23 if (!strcmp(argv
[1], "pointers")) {
24 old_p
= p
= realloc(nullptr, size
);
27 size
= malloc_usable_size(p
);
28 // Our realloc implementation will return the same pointer if the size
29 // requested is lower or equal to the usable size of the associated chunk.
30 p
= realloc(p
, size
- 1);
36 // And a new one if the size is greater.
37 p
= realloc(p
, size
+ 1);
40 // A size of 0 will free the chunk and return nullptr.
46 if (!strcmp(argv
[1], "contents")) {
47 p
= realloc(nullptr, size
);
50 for (int i
= 0; i
< size
; i
++)
51 reinterpret_cast<char *>(p
)[i
] = 'A';
52 p
= realloc(p
, size
+ 1);
53 // The contents of the reallocated chunk must match the original one.
54 for (int i
= 0; i
< size
; i
++)
55 if (reinterpret_cast<char *>(p
)[i
] != 'A')
58 if (!strcmp(argv
[1], "memalign")) {
59 // A chunk coming from memalign cannot be reallocated.
60 p
= memalign(16, size
);
69 // CHECK: ERROR: invalid chunk type when reallocating address