1 // RUN: export ASAN_OPTIONS=detect_stack_use_after_return=1
2 // RUN: %clangxx_asan -O0 %s -o %t && \
3 // RUN: not %t 2>&1 | FileCheck %s
4 // RUN: %clangxx_asan -O1 %s -o %t && \
5 // RUN: not %t 2>&1 | FileCheck %s
6 // RUN: %clangxx_asan -O2 %s -o %t && \
7 // RUN: not %t 2>&1 | FileCheck %s
8 // RUN: %clangxx_asan -O3 %s -o %t && \
9 // RUN: not %t 2>&1 | FileCheck %s
10 // RUN: ASAN_OPTIONS=detect_stack_use_after_return=0 %t
11 // Regression test for a CHECK failure with small stack size and large frame.
12 // RUN: %clangxx_asan -O3 %s -o %t -DkSize=10000 && \
13 // RUN: (ulimit -s 65; not %t) 2>&1 | FileCheck %s
15 // Test that we can find UAR in a thread other than main:
16 // RUN: %clangxx_asan -DUseThread -O2 %s -o %t && \
17 // RUN: not %t 2>&1 | FileCheck --check-prefix=THREAD %s
19 // Test the max_uar_stack_size_log/min_uar_stack_size_log flag.
21 // RUN: ASAN_OPTIONS=$ASAN_OPTIONS:max_uar_stack_size_log=20:verbosity=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-20 %s
22 // RUN: ASAN_OPTIONS=$ASAN_OPTIONS:min_uar_stack_size_log=24:max_uar_stack_size_log=24:verbosity=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-24 %s
35 __attribute__((noinline
))
36 char *Ident(char *x
) {
37 fprintf(stderr
, "1: %p\n", x
);
41 __attribute__((noinline
))
47 __attribute__((noinline
))
49 fprintf(stderr
, "2: %p\n", x
);
51 // CHECK: WRITE of size 1 {{.*}} thread T0
52 // CHECK: #0{{.*}}Func2{{.*}}stack-use-after-return.cc:[[@LINE-2]]
53 // CHECK: is located in stack of thread T0 at offset
54 // CHECK: 'local' <== Memory access at offset {{16|32}} is inside this variable
55 // THREAD: WRITE of size 1 {{.*}} thread T{{[1-9]}}
56 // THREAD: #0{{.*}}Func2{{.*}}stack-use-after-return.cc:[[@LINE-6]]
57 // THREAD: is located in stack of thread T{{[1-9]}} at offset
58 // THREAD: 'local' <== Memory access at offset {{16|32}} is inside this variable
59 // CHECK-20: T0: FakeStack created:{{.*}} stack_size_log: 20
60 // CHECK-24: T0: FakeStack created:{{.*}} stack_size_log: 24
63 void *Thread(void *unused
) {
68 int main(int argc
, char **argv
) {
71 pthread_create(&t
, 0, Thread
, 0);