48 lines · c
1// RUN: %clang_hwasan %s -o %t2// RUN: %run %t 03// RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s4// RUN: not %env_hwasan_opts=symbolize=0 %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RNOSYM %s5// RUN: not %run %t -1 2>&1 | FileCheck --check-prefixes=CHECK,LSYM %s6// RUN: not %env_hwasan_opts=symbolize=0 %run %t -1 2>&1 | FileCheck --check-prefixes=CHECK,LNOSYM %s7 8// Test with and without optimizations, with and without PIC, since different9// backend passes run depending on these flags.10// RUN: %clang_hwasan -fno-pic %s -o %t11// RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s12// RUN: %clang_hwasan -fno-pic -O2 %s -o %t13// RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s14// RUN: %clang_hwasan -O2 %s -o %t15// RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s16 17// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 018// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 119// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic && %run %t 120// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -O2 && %run %t 121// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic -O2 && %run %t 122 23// REQUIRES: pointer-tagging24 25#include <stdlib.h>26 27int a = 1;28#ifdef USE_NOSANITIZE29__attribute__((no_sanitize("hwaddress"))) int x = 1;30#else // USE_NOSANITIZE31int x = 1;32#endif // USE_NOSANITIZE33int b = 1;34 35int atoi(const char *);36 37int main(int argc, char **argv) {38 // CHECK: Cause: global-overflow39 // RSYM: is located 0 bytes after a 4-byte global variable x {{.*}} in {{.*}}global.c.tmp40 // RNOSYM: is located after a 4-byte global variable in41 // RNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})42 // LSYM: is located 4 bytes before a 4-byte global variable x {{.*}} in {{.*}}global.c.tmp43 // LNOSYM: is located before a 4-byte global variable in44 // LNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})45 // CHECK-NOT: can not describe46 (&x)[atoi(argv[1])] = 1;47}48