diff --git a/compiler-rt/test/hwasan/TestCases/global-buffer-overflow.c b/compiler-rt/test/hwasan/TestCases/global-buffer-overflow.c new file mode 100644 --- /dev/null +++ b/compiler-rt/test/hwasan/TestCases/global-buffer-overflow.c @@ -0,0 +1,29 @@ +// RUN: %clang_hwasan %s -o %t +// RUN: not %run %t 40 2>&1 | FileCheck %s --check-prefixes=CHECK40 +// RUN: not %run %t 80 2>&1 | FileCheck %s --check-prefixes=CHECK80 +// RUN: not %run %t -30 2>&1 | FileCheck %s --check-prefixes=CHECKm30 + +// Global access faults do not get reported properly on x86. +// XFAIL: x86_64 + +// REQUIRES: stable-runtime + +#include +#include +#include + +static volatile char sink; + +int main(int argc, char **argv) { + __hwasan_enable_allocator_tagging(); + static char buf[30]; + int offset = argc < 2 ? 40 : atoi(argv[1]); + fprintf(stderr, "base: %p access: %p\n", buf, &buf[offset]); + sink = buf[offset]; + +// CHECK40: is located 10 bytes to the right of 30-byte global +// +// CHECK80: is located 50 bytes to the right of 30-byte global +// +// CHECKm30: is located 30 bytes to the left of 30-byte global +}