parent
65e0ca1bde
commit
9f8d091ea9
|
|
@ -1,8 +1,6 @@
|
||||||
// RUN: export ASAN_OPTIONS=detect_stack_use_after_return=1
|
// RUN: export ASAN_OPTIONS=detect_stack_use_after_return=1
|
||||||
// RUN: %clangxx_asan -O0 %s -o %t && \
|
// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
|
||||||
// RUN: not %run %t 2>&1 | FileCheck %s
|
// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
|
||||||
// RUN: %clangxx_asan -O2 %s -o %t && \
|
|
||||||
// RUN: not %run %t 2>&1 | FileCheck %s
|
|
||||||
// XFAIL: arm-linux-gnueabi
|
// XFAIL: arm-linux-gnueabi
|
||||||
|
|
||||||
// FIXME: Fix this test under GCC.
|
// FIXME: Fix this test under GCC.
|
||||||
|
|
@ -27,28 +25,28 @@ char *LeakStack() {
|
||||||
|
|
||||||
template<size_t kFrameSize>
|
template<size_t kFrameSize>
|
||||||
__attribute__((noinline))
|
__attribute__((noinline))
|
||||||
void RecuriveFunctionWithStackFrame(int depth) {
|
void RecursiveFunctionWithStackFrame(int depth) {
|
||||||
if (depth <= 0) return;
|
if (depth <= 0) return;
|
||||||
char x[kFrameSize];
|
char x[kFrameSize];
|
||||||
x[0] = depth;
|
x[0] = depth;
|
||||||
pretend_to_do_something(x);
|
pretend_to_do_something(x);
|
||||||
RecuriveFunctionWithStackFrame<kFrameSize>(depth - 1);
|
RecursiveFunctionWithStackFrame<kFrameSize>(depth - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int n_iter = argc >= 2 ? atoi(argv[1]) : 1000;
|
int n_iter = argc >= 2 ? atoi(argv[1]) : 1000;
|
||||||
int depth = argc >= 3 ? atoi(argv[2]) : 500;
|
int depth = argc >= 3 ? atoi(argv[2]) : 500;
|
||||||
for (int i = 0; i < n_iter; i++) {
|
for (int i = 0; i < n_iter; i++) {
|
||||||
RecuriveFunctionWithStackFrame<10>(depth);
|
RecursiveFunctionWithStackFrame<10>(depth);
|
||||||
RecuriveFunctionWithStackFrame<100>(depth);
|
RecursiveFunctionWithStackFrame<100>(depth);
|
||||||
RecuriveFunctionWithStackFrame<500>(depth);
|
RecursiveFunctionWithStackFrame<500>(depth);
|
||||||
RecuriveFunctionWithStackFrame<1024>(depth);
|
RecursiveFunctionWithStackFrame<1024>(depth);
|
||||||
RecuriveFunctionWithStackFrame<2000>(depth);
|
RecursiveFunctionWithStackFrame<2000>(depth);
|
||||||
RecuriveFunctionWithStackFrame<5000>(depth);
|
RecursiveFunctionWithStackFrame<5000>(depth);
|
||||||
RecuriveFunctionWithStackFrame<10000>(depth);
|
RecursiveFunctionWithStackFrame<10000>(depth);
|
||||||
}
|
}
|
||||||
char *stale_stack = LeakStack();
|
char *stale_stack = LeakStack();
|
||||||
RecuriveFunctionWithStackFrame<1024>(10);
|
RecursiveFunctionWithStackFrame<1024>(10);
|
||||||
stale_stack[100]++;
|
stale_stack[100]++;
|
||||||
// CHECK: ERROR: AddressSanitizer: stack-use-after-return on address
|
// CHECK: ERROR: AddressSanitizer: stack-use-after-return on address
|
||||||
// CHECK: is located in stack of thread T0 at offset {{116|132}} in frame
|
// CHECK: is located in stack of thread T0 at offset {{116|132}} in frame
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue