]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/asan/TestCases/Posix/stack-use-after-return.cc
1 // RUN: %clangxx_asan -O0 %s -pthread -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s
2 // RUN: %clangxx_asan -O1 %s -pthread -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s
3 // RUN: %clangxx_asan -O2 %s -pthread -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s
4 // RUN: %clangxx_asan -O3 %s -pthread -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s
5 // RUN: %env_asan_opts=detect_stack_use_after_return=0 %run %t
6 // Regression test for a CHECK failure with small stack size and large frame.
7 // RUN: %clangxx_asan -O3 %s -pthread -o %t -DkSize=10000 -DUseThread -DkStackSize=65536 && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck --check-prefix=THREAD %s
9 // Test that we can find UAR in a thread other than main:
10 // RUN: %clangxx_asan -DUseThread -O2 %s -pthread -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck --check-prefix=THREAD %s
12 // Test the max_uar_stack_size_log/min_uar_stack_size_log flag.
14 // RUN: %env_asan_opts=detect_stack_use_after_return=1:max_uar_stack_size_log=20:verbosity=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-20 %s
15 // RUN: %env_asan_opts=detect_stack_use_after_return=1:min_uar_stack_size_log=24:max_uar_stack_size_log=24:verbosity=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-24 %s
32 __attribute__((noinline
))
33 char *Ident(char *x
) {
34 fprintf(stderr
, "1: %p\n", x
);
38 __attribute__((noinline
))
44 __attribute__((noinline
))
46 fprintf(stderr
, "2: %p\n", x
);
48 // CHECK: WRITE of size 1 {{.*}} thread T0
49 // CHECK: #0{{.*}}Func2{{.*}}stack-use-after-return.cc:[[@LINE-2]]
50 // CHECK: is located in stack of thread T0 at offset
51 // CHECK: 'local' <== Memory access at offset {{16|32}} is inside this variable
52 // THREAD: WRITE of size 1 {{.*}} thread T{{[1-9]}}
53 // THREAD: #0{{.*}}Func2{{.*}}stack-use-after-return.cc:[[@LINE-6]]
54 // THREAD: is located in stack of thread T{{[1-9]}} at offset
55 // THREAD: 'local' <== Memory access at offset {{16|32}} is inside this variable
56 // CHECK-20: T0: FakeStack created:{{.*}} stack_size_log: 20
57 // CHECK-24: T0: FakeStack created:{{.*}} stack_size_log: 24
60 void *Thread(void *unused
) {
65 int main(int argc
, char **argv
) {
68 pthread_attr_init(&attr
);
70 pthread_attr_setstacksize(&attr
, kStackSize
);
72 pthread_create(&t
, &attr
, Thread
, 0);
73 pthread_attr_destroy(&attr
);