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 // REQUIRES: stable-runtime
11 
12 // Stack short granules are currently not implemented on x86.
13 // XFAIL: x86_64
14 
15 #include <stdlib.h>
16 #include <sanitizer/hwasan_interface.h>
17 
18 __attribute__((noinline))
f()19 int f() {
20   char z[SIZE];
21   char *volatile p = z;
22   return p[SIZE];
23 }
24 
main()25 int main() {
26   f();
27   // CHECK: READ of size 1 at
28   // CHECK: #0 {{.*}} in f{{.*}}stack-oob.c:[[@LINE-6]]
29 
30   // CHECK-NOT: Cause: global-overflow
31   // CHECK: Cause: stack tag-mismatch
32   // CHECK: is located in stack of threa
33   // CHECK-NOT: Cause: global-overflow
34 
35   // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in f
36 }
37