Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / Linux / calloc-preload.c
blobe1f33192b57c620cff1eae0eae36c12418adcbbd
1 // Test that initially callocked memory is properly freed
2 // (see https://github.com/google/sanitizers/issues/626).
3 //
4 // RUN: %clang %s -o %t
5 // RUN: env LD_PRELOAD=%shared_libasan %run %t
6 //
7 // REQUIRES: asan-dynamic-runtime
8 //
9 // This way of setting LD_PRELOAD does not work with Android test runner.
10 // REQUIRES: !android
12 #include <stdio.h>
13 #include <stdlib.h>
15 static void *ptr;
17 // This constructor will run before __asan_init
18 // so calloc will allocate memory from special pool.
19 static void init() {
20 ptr = calloc(10, 1);
23 __attribute__((section(".preinit_array"), used))
24 void *dummy = init;
26 void free_memory() {
27 // This used to abort because
28 // Asan's free didn't recognize ptr.
29 free(ptr);
32 int main() {
33 free_memory();
34 return 0;