llvm-project/compiler-rt/test/hwasan/TestCases/hwasan_symbolize_stack_overflow.cpp
Florian Mayer c478139613
Reapply "[HWASan] symbolize stack overflows" (#102951) (#104036)
This reverts commit d4f6fcf5aaa0911a91317c0b06779f13077d6b58.

Relanding with fixed obj_offset calculation (precedence of operations
was wrong),
and the suggestion in
https://github.com/llvm/llvm-project/pull/95308#discussion_r1714317539
2024-08-19 15:28:24 -07:00

31 lines
2.0 KiB
C++

// RUN: rm -rf %t; mkdir %t
// RUN: %clang_hwasan -Wl,--build-id -g %s -o %t/hwasan_overflow
// 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
// 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
// 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
// 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
// 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
// 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
// RUN: %env_hwasan_opts=symbolize=0 not %run %t/hwasan_overflow 1000000 2>&1 | hwasan_symbolize --symbols %t --index | FileCheck %s --check-prefixes=TOOFAR
// REQUIRES: aarch64-target-arch
#include <stdlib.h>
static volatile char sink;
int main(int argc, char **argv) {
volatile char x[16];
sink = x[atoi(argv[1])];
// TOOFAR-NOT: Potentially referenced stack object:
// CHECK: Potentially referenced stack object:
// AFTER0: 0 bytes after a variable "x" in stack frame of function "main"
// AFTER1: 1 bytes after a variable "x" in stack frame of function "main"
// BEFORE1: 1 bytes before a variable "x" in stack frame of function "main"
// BEFORE17: 17 bytes before a variable "x" in stack frame of function "main"
// BEFORE1000: 1000 bytes before a variable "x" in stack frame of function "main"
// AFTER1000: 1000 bytes after a variable "x" in stack frame of function "main"
// CHECK: at {{.*}}hwasan_symbolize_stack_overflow.cpp:[[@LINE-10]]
return 0;
}