]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/hwasan/TestCases/stack-history-length.c
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / hwasan / TestCases / stack-history-length.c
1 // RUN: %clang_hwasan -O1 %s -o %t
2 // RUN: %env_hwasan_opts=stack_history_size=2048 not %run %t 2046 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
4
5 // REQUIRES: stable-runtime
6
7 #include <stdlib.h>
8
9 void USE(void *x) { // pretend_to_do_something(void *x)
10   __asm__ __volatile__("" : : "r" (x) : "memory");
11 }
12
13 volatile int four = 4;
14 __attribute__((noinline)) void FUNC0() { int x[4]; USE(&x[0]); }
15 __attribute__((noinline)) void FUNC() { int x[4]; USE(&x[0]); }
16 __attribute__((noinline)) void OOB() { int x[4]; x[four] = 0; USE(&x[0]); }
17
18 int main(int argc, char **argv) {
19   int X = argc == 2 ? atoi(argv[1]) : 10;
20   // FUNC0 is X+2's element of the ring buffer.
21   // If runtime buffer size is less than it, FUNC0 record will be lost.
22   FUNC0();
23   for (int i = 0; i < X; ++i)
24     FUNC();
25   OOB();
26 }
27
28 // YES: Previously allocated frames
29 // YES: OOB
30 // YES: FUNC
31 // YES: FUNC0
32
33 // NO: Previously allocated frames
34 // NO: OOB
35 // NO: FUNC
36 // NO-NOT: FUNC0