1 // RUN: %clangxx %s -fsanitize-memory-track-origins=1 -o %t 2 // RUN: %env_tool_opts="compress_stack_depot=0:malloc_context_size=128:verbosity=1" %run %t 2>&1 | FileCheck %s --implicit-check-not="StackDepot released" 3 // RUN: %env_tool_opts="compress_stack_depot=-1:malloc_context_size=128:verbosity=1" %run %t 2>&1 | FileCheck %s --check-prefixes=COMPRESS 4 // RUN: %env_tool_opts="compress_stack_depot=-2:malloc_context_size=128:verbosity=1" %run %t 2>&1 | FileCheck %s --check-prefixes=COMPRESS 5 // RUN: %env_tool_opts="compress_stack_depot=1:malloc_context_size=128:verbosity=1" %run %t 2>&1 | FileCheck %s --check-prefixes=COMPRESS,THREAD 6 // RUN: %env_tool_opts="compress_stack_depot=2:malloc_context_size=128:verbosity=1" %run %t 2>&1 | FileCheck %s --check-prefixes=COMPRESS,THREAD 7 8 // Ubsan does not store stacks. 9 // UNSUPPORTED: ubsan 10 11 // FIXME: Fails for unknown reason. 12 // UNSUPPORTED: s390x 13 14 #include <sanitizer/common_interface_defs.h> 15 16 #include <memory> 17 18 __attribute__((noinline)) void a(unsigned v); 19 __attribute__((noinline)) void b(unsigned v); 20 21 std::unique_ptr<int[]> p; 22 23 __attribute__((noinline)) void a(unsigned v) { 24 int x; 25 v >>= 1; 26 if (!v) { 27 p.reset(new int[100]); 28 p[1] = x; 29 return; 30 } 31 if (v & 1) 32 b(v); 33 else 34 a(v); 35 } 36 37 __attribute__((noinline)) void b(unsigned v) { return a(v); } 38 39 int main(int argc, char *argv[]) { 40 for (unsigned i = 0; i < 100000; ++i) 41 a(i + (i << 16)); 42 43 __sanitizer_sandbox_arguments args = {0}; 44 __sanitizer_sandbox_on_notify(&args); 45 46 return 0; 47 } 48 49 // THREAD: StackDepot compression thread started 50 // COMPRESS: StackDepot released {{[0-9]+}} 51 // THREAD: StackDepot compression thread stopped 52