1// RUN: rm -rf %t; mkdir %t
2// RUN: %clang_hwasan -Wl,--build-id -g %s -o %t/hwasan_overflow
3// RUN: %env_hwasan_opts=symbolize=0 not %run %t/hwasan_overflow 16 2>&1 | hwasan_symbolize --symbols %t --index | FileCheck %s --check-prefixes=CHECK,AFTER0
4// RUN: %env_hwasan_opts=symbolize=0 not %run %t/hwasan_overflow 17 2>&1 | hwasan_symbolize --symbols %t --index | FileCheck %s --check-prefixes=CHECK,AFTER1
5// RUN: %env_hwasan_opts=symbolize=0 not %run %t/hwasan_overflow -1 2>&1 | hwasan_symbolize --symbols %t --index | FileCheck %s --check-prefixes=CHECK,BEFORE1
6// RUN: %env_hwasan_opts=symbolize=0 not %run %t/hwasan_overflow -17 2>&1 | hwasan_symbolize --symbols %t --index | FileCheck %s --check-prefixes=CHECK,BEFORE17
7// RUN: %env_hwasan_opts=symbolize=0 not %run %t/hwasan_overflow 1016 2>&1 | hwasan_symbolize --symbols %t --index | FileCheck %s --check-prefixes=CHECK,AFTER1000
8// RUN: %env_hwasan_opts=symbolize=0 not %run %t/hwasan_overflow -1000 2>&1 | hwasan_symbolize --symbols %t --index | FileCheck %s --check-prefixes=CHECK,BEFORE1000
9// RUN: %env_hwasan_opts=symbolize=0 not %run %t/hwasan_overflow 1000000 2>&1 | hwasan_symbolize --symbols %t --index | FileCheck %s --check-prefixes=TOOFAR
10
11// REQUIRES: aarch64-target-arch
12
13#include <stdlib.h>
14
15static volatile char sink;
16
17int main(int argc, char **argv) {
18 volatile char x[16];
19 sink = x[atoi(nptr: argv[1])];
20 // TOOFAR-NOT: Potentially referenced stack object:
21 // CHECK: Potentially referenced stack object:
22 // AFTER0: 0 bytes after a variable "x" in stack frame of function "main"
23 // AFTER1: 1 bytes after a variable "x" in stack frame of function "main"
24 // BEFORE1: 1 bytes before a variable "x" in stack frame of function "main"
25 // BEFORE17: 17 bytes before a variable "x" in stack frame of function "main"
26 // BEFORE1000: 1000 bytes before a variable "x" in stack frame of function "main"
27 // AFTER1000: 1000 bytes after a variable "x" in stack frame of function "main"
28 // CHECK: at {{.*}}hwasan_symbolize_stack_overflow.cpp:[[@LINE-10]]
29 return 0;
30}
31

source code of compiler-rt/test/hwasan/TestCases/hwasan_symbolize_stack_overflow.cpp