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