1 // RUN: %clang_hwasan %s -o %t
3 // RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
4 // RUN: not %env_hwasan_opts=symbolize=0 %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RNOSYM %s
5 // RUN: not %run %t -1 2>&1 | FileCheck --check-prefixes=CHECK,LSYM %s
6 // RUN: not %env_hwasan_opts=symbolize=0 %run %t -1 2>&1 | FileCheck --check-prefixes=CHECK,LNOSYM %s
8 // Test with and without optimizations, with and without PIC, since different
9 // backend passes run depending on these flags.
10 // RUN: %clang_hwasan -fno-pic %s -o %t
11 // RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
12 // RUN: %clang_hwasan -fno-pic -O2 %s -o %t
13 // RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
14 // RUN: %clang_hwasan -O2 %s -o %t
15 // RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
17 // RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 0
18 // RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 1
19 // RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic && %run %t 1
20 // RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -O2 && %run %t 1
21 // RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic -O2 && %run %t 1
23 // REQUIRES: pointer-tagging
29 __attribute__((no_sanitize("hwaddress"))) int x
= 1;
30 #else // USE_NOSANITIZE
32 #endif // USE_NOSANITIZE
35 int atoi(const char *);
37 int main(int argc
, char **argv
) {
38 // CHECK: Cause: global-overflow
39 // RSYM: is located 0 bytes after a 4-byte global variable x {{.*}} in {{.*}}global.c.tmp
40 // RNOSYM: is located after a 4-byte global variable in
41 // RNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})
42 // LSYM: is located 4 bytes before a 4-byte global variable x {{.*}} in {{.*}}global.c.tmp
43 // LNOSYM: is located before a 4-byte global variable in
44 // LNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})
45 // CHECK-NOT: can not describe
46 (&x
)[atoi(argv
[1])] = 1;