1 // RUN: %clangxx_asan -O2 %s -o %t 2 // RUN: not %run %t g 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=GLOB 3 // RUN: not %run %t c 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CLASS_STATIC 4 // RUN: not %run %t f 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=FUNC_STATIC 5 // RUN: not %run %t l 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=LITERAL 6 7 // CHECK: AddressSanitizer: global-buffer-overflow 8 9 #include <string.h> 10 11 struct C { 12 static int array[10]; 13 }; 14 15 int global[10]; 16 // GLOB: 0x{{.*}} is located 4 bytes to the right of global variable 'global' defined in '{{.*}}global-location.cc:[[@LINE-1]]:5' {{.*}} of size 40 17 int C::array[10]; 18 // CLASS_STATIC: 0x{{.*}} is located 4 bytes to the right of global variable 'C::array' defined in '{{.*}}global-location.cc:[[@LINE-1]]:8' {{.*}} of size 40 19 20 int main(int argc, char **argv) { 21 int one = argc - 1; 22 switch (argv[1][0]) { 23 case 'g': return global[one * 11]; 24 case 'c': return C::array[one * 11]; 25 case 'f': 26 static int array[10]; 27 // FUNC_STATIC: 0x{{.*}} is located 4 bytes to the right of global variable 'array' defined in '{{.*}}global-location.cc:[[@LINE-1]]:16' {{.*}} of size 40 28 memset(array, 0, 10); 29 return array[one * 11]; 30 case 'l': 31 const char *str = "0123456789"; 32 // LITERAL: 0x{{.*}} is located 0 bytes to the right of global variable {{.*}} defined in '{{.*}}global-location.cc:[[@LINE-1]]:23' {{.*}} of size 11 33 return str[one * 11]; 34 } 35 return 0; 36 } 37 38 // CHECK: SUMMARY: AddressSanitizer: global-buffer-overflow 39