| 1 |
// Check that we can store lots of stack frames if asked to. |
| 2 |
|
| 3 |
// { dg-do run } |
| 4 |
// { dg-skip-if "" { *-*-* } { "-flto" } { "" } } |
| 5 |
// { dg-set-target-env-var ASAN_OPTIONS "malloc_context_size=120:redzone=512" } |
| 6 |
// { dg-options "-fno-omit-frame-pointer -fno-optimize-sibling-calls" } |
| 7 |
// { dg-additional-options "-mno-omit-leaf-frame-pointer" { target { i?86-*-* x86_64-*-* } } } |
| 8 |
// { dg-additional-options "-mbackchain" { target { s390*-*-* } } } |
| 9 |
// { dg-shouldfail "asan" } |
| 10 |
|
| 11 |
#include <stdlib.h> |
| 12 |
#include <stdio.h> |
| 13 |
|
| 14 |
template <int depth> |
| 15 |
struct DeepFree { |
| 16 |
static void __attribute__((noinline)) |
| 17 |
free(char *x) { |
| 18 |
DeepFree<depth - 1>::free(x); |
| 19 |
} |
| 20 |
}; |
| 21 |
|
| 22 |
template<> |
| 23 |
struct DeepFree<0> { |
| 24 |
static void __attribute__((noinline)) |
| 25 |
free(char *x) { |
| 26 |
::free(x); |
| 27 |
} |
| 28 |
}; |
| 29 |
|
| 30 |
int main() { |
| 31 |
char *x = (char*)malloc(10); |
| 32 |
// deep_free(x); |
| 33 |
DeepFree<200>::free(x); |
| 34 |
return x[5]; |
| 35 |
} |
| 36 |
|
| 37 |
// { dg-output "ERROR: AddressSanitizer:? heap-use-after-free on address.*(\n|\r\n|\r)" } |
| 38 |
// { dg-output " #37 0x\[0-9a-f\]+ +(in \[^\n\r]*DeepFree\[^\n\r]*36|\[(\]).*(\n|\r\n|\r)" } |
| 39 |
// { dg-output " #99 0x\[0-9a-f\]+ +(in \[^\n\r]*DeepFree\[^\n\r]*98|\[(\]).*(\n|\r\n|\r)" } |
| 40 |
// { dg-output " #116 0x\[0-9a-f\]+ +(in \[^\n\r]*DeepFree\[^\n\r]*115|\[(\])\[^\n\r]*(\n|\r\n|\r)" } |