[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / hwasan / TestCases / stack-history-length.c
blob2434299a84a41d11264c8292e81d99fae18a6223
1 // RUN: %clang_hwasan -O1 %s -o %t
2 // RUN: %env_hwasan_opts=stack_history_size=2048 not %run %t 2045 2>&1 | FileCheck %s --check-prefix=YES
3 // RUN: %env_hwasan_opts=stack_history_size=2048 not %run %t 2047 2>&1 | FileCheck %s --check-prefix=NO
5 // Run the same tests as above, but using the __hwasan_add_frame_record libcall.
6 // The output should be the exact same.
7 // RUN: %clang_hwasan -O1 %s -o %t -mllvm -hwasan-record-stack-history=libcall
8 // RUN: %env_hwasan_opts=stack_history_size=2048 not %run %t 2045 2>&1 | FileCheck %s --check-prefix=YES
9 // RUN: %env_hwasan_opts=stack_history_size=2048 not %run %t 2047 2>&1 | FileCheck %s --check-prefix=NO
11 // REQUIRES: stable-runtime
13 // Stack histories are currently not recorded on x86.
14 // XFAIL: x86_64
16 #include <stdlib.h>
18 void USE(void *x) { // pretend_to_do_something(void *x)
19 __asm__ __volatile__("" : : "r" (x) : "memory");
22 volatile int four = 4;
23 __attribute__((noinline)) void FUNC0() { int x[4]; USE(&x[0]); }
24 __attribute__((noinline)) void FUNC() { int x[4]; USE(&x[0]); }
25 __attribute__((noinline)) void OOB() { int x[4]; x[four] = 0; USE(&x[0]); }
27 int main(int argc, char **argv) {
28 int X = argc == 2 ? atoi(argv[1]) : 10;
29 // FUNC0 is X+2's element of the ring buffer.
30 // If runtime buffer size is less than it, FUNC0 record will be lost.
31 FUNC0();
32 for (int i = 0; i < X; ++i)
33 FUNC();
34 // Make at least one call to OOB where base tag != 0 so that the bug is caught
35 // at least once.
36 OOB();
37 OOB();
40 // YES: Previously allocated frames
41 // YES: OOB
42 // YES: FUNC
43 // YES: FUNC0
45 // NO: Previously allocated frames
46 // NO: OOB
47 // NO: FUNC
48 // NO-NOT: FUNC0