• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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.
USE(void * x)13 void USE(void *x) { // pretend_to_do_something(void *x)
14   __asm__ __volatile__("" : : "r" (x) : "memory");
15 }
16 
17 volatile int four = 4;
18 
OOB()19 __attribute__((noinline)) void OOB() { int x[4]; x[four] = 0; USE(&x[0]); }
FUNC1()20 __attribute__((noinline)) void FUNC1() { int x; USE(&x); OOB(); }
FUNC2()21 __attribute__((noinline)) void FUNC2() { int x; USE(&x); FUNC1(); }
FUNC3()22 __attribute__((noinline)) void FUNC3() { int x; USE(&x); FUNC2(); }
FUNC4()23 __attribute__((noinline)) void FUNC4() { int x; USE(&x); FUNC3(); }
FUNC5()24 __attribute__((noinline)) void FUNC5() { int x; USE(&x); FUNC4(); }
FUNC6()25 __attribute__((noinline)) void FUNC6() { int x; USE(&x); FUNC5(); }
FUNC7()26 __attribute__((noinline)) void FUNC7() { int x; USE(&x); FUNC6(); }
FUNC8()27 __attribute__((noinline)) void FUNC8() { int x; USE(&x); FUNC7(); }
FUNC9()28 __attribute__((noinline)) void FUNC9() { int x; USE(&x); FUNC8(); }
FUNC10()29 __attribute__((noinline)) void FUNC10() { int x; USE(&x); FUNC9(); }
30 
main()31 int main() { FUNC10(); }
32 
33 // D1: Previously allocated frames
34 // D1: in OOB
35 // D1-NOT: in FUNC
36 // D1: Memory tags around the buggy address
37 
38 // D2: Previously allocated frames
39 // D2: in OOB
40 // D2: in FUNC1
41 // D2-NOT: in FUNC
42 // D2: Memory tags around the buggy address
43 
44 // D3: Previously allocated frames
45 // 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 
51 // D5: Previously allocated frames
52 // 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 
60 // DEFAULT: Previously allocated frames
61 // 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
74