113e9c1d1SMitch Phillips // RUN: %clangxx_asan -g -O2 %s -o %t 2673dc3d4SNico Weber // RUN: not %run %t g 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=GLOB 3673dc3d4SNico Weber // RUN: not %run %t c 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CLASS_STATIC 4673dc3d4SNico Weber // RUN: not %run %t f 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=FUNC_STATIC 5673dc3d4SNico Weber // RUN: not %run %t l 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=LITERAL 6673dc3d4SNico Weber 713e9c1d1SMitch Phillips // COFF doesn't support debuginfo for globals. For the non-debuginfo tests, see global-location-nodebug.cpp. 838e9660eSPaul Robinson // XFAIL: target={{.*windows-msvc.*}} 913e9c1d1SMitch Phillips 10*5888a479SAlvin Wong // FIXME: Investigate failure on MinGW 11*5888a479SAlvin Wong // XFAIL: target={{.*-windows-gnu}} 12*5888a479SAlvin Wong 131bdbf137SJulian Lettner // atos doesn't show source line numbers for global variables. 141bdbf137SJulian Lettner // UNSUPPORTED: darwin 15f4a3df18SJulian Lettner 16673dc3d4SNico Weber // CHECK: AddressSanitizer: global-buffer-overflow 17673dc3d4SNico Weber 18673dc3d4SNico Weber #include <string.h> 19673dc3d4SNico Weber 20673dc3d4SNico Weber struct C { 21673dc3d4SNico Weber static int array[10]; 22be366041SFlorian Mayer // CLASS_STATIC: 0x{{.*}} is located 4 bytes after global variable 'C::array' defined in '{{.*}}global-location.cpp:[[@LINE-1]]' {{.*}} of size 40 23673dc3d4SNico Weber }; 24673dc3d4SNico Weber 25673dc3d4SNico Weber int global[10]; 26be366041SFlorian Mayer // GLOB: 0x{{.*}} is located 4 bytes after global variable 'global' defined in '{{.*}}global-location.cpp:[[@LINE-1]]' {{.*}} of size 40 27673dc3d4SNico Weber int C::array[10]; 28673dc3d4SNico Weber main(int argc,char ** argv)29673dc3d4SNico Weberint main(int argc, char **argv) { 30673dc3d4SNico Weber int one = argc - 1; 31673dc3d4SNico Weber switch (argv[1][0]) { 32673dc3d4SNico Weber case 'g': return global[one * 11]; 33673dc3d4SNico Weber case 'c': return C::array[one * 11]; 34673dc3d4SNico Weber case 'f': 35673dc3d4SNico Weber static int array[10]; 36be366041SFlorian Mayer // FUNC_STATIC: 0x{{.*}} is located 4 bytes after global variable 'main::array' defined in '{{.*}}global-location.cpp:[[@LINE-1]]' {{.*}} of size 40 37673dc3d4SNico Weber memset(array, 0, 10); 38673dc3d4SNico Weber return array[one * 11]; 39673dc3d4SNico Weber case 'l': 40673dc3d4SNico Weber const char *str = "0123456789"; 41be366041SFlorian Mayer // LITERAL: 0x{{.*}} is located 0 bytes after global variable {{.*}} defined in '{{.*}}global-location.cpp:[[@LINE-1]]' {{.*}} of size 11 42673dc3d4SNico Weber return str[one * 11]; 43673dc3d4SNico Weber } 44673dc3d4SNico Weber return 0; 45673dc3d4SNico Weber } 46673dc3d4SNico Weber 47673dc3d4SNico Weber // CHECK: SUMMARY: AddressSanitizer: global-buffer-overflow 48