xref: /llvm-project/compiler-rt/test/hwasan/TestCases/stack-oob.c (revision fdac98a7f3bbe0cb553df60df8cca2e8f407fa51)
1 // RUN: %clang_hwasan_oldrt -DSIZE=2 -O0 %s -o %t && %run %t
2 // RUN: %clang_hwasan -DSIZE=2 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
3 // RUN: %clang_hwasan_oldrt -DSIZE=15 -O0 %s -o %t && %run %t
4 // RUN: %clang_hwasan -DSIZE=15 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
5 // RUN: %clang_hwasan_oldrt -DSIZE=16 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
6 // RUN: %clang_hwasan -DSIZE=16 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
7 // RUN: %clang_hwasan -DSIZE=64 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
8 // RUN: %clang_hwasan -DSIZE=0x1000 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
9 
10 // Stack short granules are currently not implemented on x86.
11 // RISC-V target doesn't support oldrt
12 // XFAIL: target={{(x86_64|riscv64).*}}
13 
14 #include <stdlib.h>
15 #include <sanitizer/hwasan_interface.h>
16 
17 __attribute__((noinline))
f()18 int f() {
19   char z[SIZE];
20   char *volatile p = z;
21   return p[SIZE];
22 }
23 
main()24 int main() {
25   f();
26   // CHECK: READ of size 1 at
27   // CHECK: #0 {{.*}} in f{{.*}}stack-oob.c:[[@LINE-6]]
28 
29   // CHECK-NOT: Cause: global-overflow
30   // CHECK: Cause: stack tag-mismatch
31   // CHECK: is located in stack of threa
32   // CHECK-NOT: Cause: global-overflow
33 
34   // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in f
35 }
36