• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Check that we can store lots of stack frames if asked to.
2 
3 // RUN: %clangxx_asan -m64 -O0 %s -o %t 2>&1
4 // RUN: ASAN_OPTIONS=malloc_context_size=120:redzone=512 %t 2>&1 | \
5 // RUN: %symbolize | FileCheck %s
6 
7 // RUN: %clangxx_asan -m32 -O0 %s -o %t 2>&1
8 // RUN: ASAN_OPTIONS=malloc_context_size=120:redzone=512 %t 2>&1 | \
9 // RUN: %symbolize | FileCheck %s
10 #include <stdlib.h>
11 #include <stdio.h>
12 
13 template <int depth>
14 struct DeepFree {
freeDeepFree15   static void free(char *x) {
16     DeepFree<depth - 1>::free(x);
17   }
18 };
19 
20 template<>
21 struct DeepFree<0> {
freeDeepFree22   static void free(char *x) {
23     ::free(x);
24   }
25 };
26 
main()27 int main() {
28   char *x = (char*)malloc(10);
29   // deep_free(x);
30   DeepFree<200>::free(x);
31   return x[5];
32   // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
33   // CHECK: DeepFree<36>
34   // CHECK: DeepFree<98>
35   // CHECK: DeepFree<115>
36 }
37