51 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 27// GlobalOpt may replace the current GV with a new boolean-typed GV. Previously,28// this resulted in the "nosanitize" getting dropped because while the data/code29// references to the GV were updated, the old metadata references weren't.30int* f() {31#ifdef USE_NOSANITIZE32__attribute__((no_sanitize("hwaddress"))) static int x = 1;33#else // USE_NOSANITIZE34 static int x = 1;35#endif // USE_NOSANITIZE36 if (x == 1) x = 0;37 return &x;38}39 40int main(int argc, char **argv) {41 // CHECK: Cause: global-overflow42 // RSYM: is located 0 bytes after a 4-byte global variable f.x {{.*}} in {{.*}}global-with-reduction.c.tmp43 // RNOSYM: is located after a 4-byte global variable in44 // RNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global-with-reduction.c.tmp+{{.*}})45 // LSYM: is located 4 bytes before a 4-byte global variable f.x {{.*}} in {{.*}}global-with-reduction.c.tmp46 // LNOSYM: is located before a 4-byte global variable in47 // LNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global-with-reduction.c.tmp+{{.*}})48 // CHECK-NOT: can not describe49 f()[atoi(argv[1])] = 1;50}51