[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / compiler-rt / test / asan / TestCases / leaks.cpp
blobd148adf728afe5918bcf4868366b7ad712b592d3
1 // Test for LeakSanitizer+AddressSanitizer of different sizes.
2 // REQUIRES: leak-detection
3 //
4 // RUN: %clangxx_asan -O0 %s -o %t
5 // RUN: not %run %t 0 2>&1 | FileCheck %s
6 // RUN: not %run %t 1 2>&1 | FileCheck %s
7 // RUN: not %run %t 1000 2>&1 | FileCheck %s
8 // RUN: not %run %t 1000000 2>&1 | FileCheck %s
10 #include <cstdlib>
11 #include <thread>
13 __attribute__((noopt)) void leak(int n) {
14 #if defined(__ANDROID__) || defined(__BIONIC__)
15 // Bionic does not acutally allocate when n==0, hence
16 // there would not be a leak.
17 // Re-adjust n so the test can pass.
18 if (n == 0)
19 n = 1;
20 #endif
22 // Repeat few times to make sure that at least one pointer is
23 // not somewhere on the stack.
24 for (int i = 0; i < 10; ++i) {
25 volatile int *t = new int[n];
26 t = nullptr;
30 int main(int argc, char **argv) {
31 leak(atoi(argv[1]));
33 // CHECK: LeakSanitizer: detected memory leaks