Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / scudo / preinit.c
blobf3aaf42e1d605824d9a4696f45272817d42aa415
1 // RUN: %clang_scudo %s -o %t
2 // RUN: %run %t 2>&1
4 // Verifies that calling malloc in a preinit_array function succeeds, and that
5 // the resulting pointer can be freed at program termination.
7 // On some Android versions, calling mmap() from a preinit function segfaults.
8 // It looks like __mmap2.S ends up calling a NULL function pointer.
9 // UNSUPPORTED: android
11 #include <assert.h>
12 #include <stdlib.h>
13 #include <string.h>
15 static void *global_p = NULL;
17 void __init(void) {
18 global_p = malloc(1);
19 if (!global_p)
20 exit(1);
23 void __fini(void) {
24 if (global_p)
25 free(global_p);
28 int main(int argc, char **argv) {
29 void *p = malloc(1);
30 assert(p);
31 free(p);
33 return 0;
36 __attribute__((section(".preinit_array"), used)) void (*__local_preinit)(void) = __init;
37 __attribute__((section(".fini_array"), used)) void (*__local_fini)(void) = __fini;