blob: 2fe77a7bdaaf3f19845f02754434913346c55bdc [file] [log] [blame]
Evgeniy Stepanov090f0f92018-09-24 23:03:34 +00001// RUN: %clang_hwasan -O1 %s -o %t
2// RUN: %env_hwasan_opts=stack_history_size=1 not %run %t 2>&1 | FileCheck %s --check-prefix=D1
3// RUN: %env_hwasan_opts=stack_history_size=2 not %run %t 2>&1 | FileCheck %s --check-prefix=D2
4// RUN: %env_hwasan_opts=stack_history_size=3 not %run %t 2>&1 | FileCheck %s --check-prefix=D3
5// RUN: %env_hwasan_opts=stack_history_size=5 not %run %t 2>&1 | FileCheck %s --check-prefix=D5
6// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=DEFAULT
7
8// REQUIRES: stable-runtime
9
10#include <stdlib.h>
11// At least -O1 is needed for this function to not have a stack frame on
12// AArch64.
13void USE(void *x) { // pretend_to_do_something(void *x)
14 __asm__ __volatile__("" : : "r" (x) : "memory");
15}
16
17volatile int four = 4;
18
19__attribute__((noinline)) void OOB() { int x[4]; x[four] = 0; USE(&x[0]); }
20__attribute__((noinline)) void FUNC1() { int x; USE(&x); OOB(); }
21__attribute__((noinline)) void FUNC2() { int x; USE(&x); FUNC1(); }
22__attribute__((noinline)) void FUNC3() { int x; USE(&x); FUNC2(); }
23__attribute__((noinline)) void FUNC4() { int x; USE(&x); FUNC3(); }
24__attribute__((noinline)) void FUNC5() { int x; USE(&x); FUNC4(); }
25__attribute__((noinline)) void FUNC6() { int x; USE(&x); FUNC5(); }
26__attribute__((noinline)) void FUNC7() { int x; USE(&x); FUNC6(); }
27__attribute__((noinline)) void FUNC8() { int x; USE(&x); FUNC7(); }
28__attribute__((noinline)) void FUNC9() { int x; USE(&x); FUNC8(); }
29__attribute__((noinline)) void FUNC10() { int x; USE(&x); FUNC9(); }
30
31int main() { FUNC10(); }
32
Peter Collingbournea53bb3a2018-12-15 07:08:04 +000033// D1: Previously allocated frames
Evgeniy Stepanov090f0f92018-09-24 23:03:34 +000034// D1: in OOB
35// D1-NOT: in FUNC
36// D1: Memory tags around the buggy address
37
Peter Collingbournea53bb3a2018-12-15 07:08:04 +000038// D2: Previously allocated frames
Evgeniy Stepanov090f0f92018-09-24 23:03:34 +000039// D2: in OOB
40// D2: in FUNC1
41// D2-NOT: in FUNC
42// D2: Memory tags around the buggy address
43
Peter Collingbournea53bb3a2018-12-15 07:08:04 +000044// D3: Previously allocated frames
Evgeniy Stepanov090f0f92018-09-24 23:03:34 +000045// D3: in OOB
46// D3: in FUNC1
47// D3: in FUNC2
48// D3-NOT: in FUNC
49// D3: Memory tags around the buggy address
50
Peter Collingbournea53bb3a2018-12-15 07:08:04 +000051// D5: Previously allocated frames
Evgeniy Stepanov090f0f92018-09-24 23:03:34 +000052// D5: in OOB
53// D5: in FUNC1
54// D5: in FUNC2
55// D5: in FUNC3
56// D5: in FUNC4
57// D5-NOT: in FUNC
58// D5: Memory tags around the buggy address
59
Peter Collingbournea53bb3a2018-12-15 07:08:04 +000060// DEFAULT: Previously allocated frames
Evgeniy Stepanov090f0f92018-09-24 23:03:34 +000061// DEFAULT: in OOB
62// DEFAULT: in FUNC1
63// DEFAULT: in FUNC2
64// DEFAULT: in FUNC3
65// DEFAULT: in FUNC4
66// DEFAULT: in FUNC5
67// DEFAULT: in FUNC6
68// DEFAULT: in FUNC7
69// DEFAULT: in FUNC8
70// DEFAULT: in FUNC9
71// DEFAULT: in FUNC10
72// DEFAULT-NOT: in FUNC
73// DEFAULT: Memory tags around the buggy address