• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
4 
5 // REQUIRES: stable-runtime
6 
7 #include <stdlib.h>
8 
USE(void * x)9 void USE(void *x) { // pretend_to_do_something(void *x)
10   __asm__ __volatile__("" : : "r" (x) : "memory");
11 }
12 
13 volatile int four = 4;
FUNC0()14 __attribute__((noinline)) void FUNC0() { int x[4]; USE(&x[0]); }
FUNC()15 __attribute__((noinline)) void FUNC() { int x[4]; USE(&x[0]); }
OOB()16 __attribute__((noinline)) void OOB() { int x[4]; x[four] = 0; USE(&x[0]); }
17 
main(int argc,char ** argv)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   // Make at least one call to OOB where base tag != 0 so that the bug is caught
26   // at least once.
27   OOB();
28   OOB();
29 }
30 
31 // YES: Previously allocated frames
32 // YES: OOB
33 // YES: FUNC
34 // YES: FUNC0
35 
36 // NO: Previously allocated frames
37 // NO: OOB
38 // NO: FUNC
39 // NO-NOT: FUNC0
40