48 lines · cpp
1// RUN: %clangxx_asan -g -O2 %s -o %t2// RUN: not %run %t g 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=GLOB3// RUN: not %run %t c 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CLASS_STATIC4// RUN: not %run %t f 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=FUNC_STATIC5// RUN: not %run %t l 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=LITERAL6 7// COFF doesn't support debuginfo for globals. For the non-debuginfo tests, see global-location-nodebug.cpp.8// XFAIL: target={{.*windows-msvc.*}}9 10// FIXME: Investigate failure on MinGW11// XFAIL: target={{.*-windows-gnu}}12 13// atos doesn't show source line numbers for global variables.14// UNSUPPORTED: darwin15 16// CHECK: AddressSanitizer: global-buffer-overflow17 18#include <string.h>19 20struct C {21 static int array[10];22 // CLASS_STATIC: 0x{{.*}} is located 4 bytes after global variable 'C::array' defined in '{{.*}}global-location.cpp:[[@LINE-1]]' {{.*}} of size 4023};24 25int global[10];26// GLOB: 0x{{.*}} is located 4 bytes after global variable 'global' defined in '{{.*}}global-location.cpp:[[@LINE-1]]' {{.*}} of size 4027int C::array[10];28 29int main(int argc, char **argv) {30 int one = argc - 1;31 switch (argv[1][0]) {32 case 'g': return global[one * 11];33 case 'c': return C::array[one * 11];34 case 'f':35 static int array[10];36 // FUNC_STATIC: 0x{{.*}} is located 4 bytes after global variable 'main::array' defined in '{{.*}}global-location.cpp:[[@LINE-1]]' {{.*}} of size 4037 memset(array, 0, 10);38 return array[one * 11];39 case 'l':40 const char *str = "0123456789";41 // LITERAL: 0x{{.*}} is located 0 bytes after global variable {{.*}} defined in '{{.*}}global-location.cpp:[[@LINE-1]]' {{.*}} of size 1142 return str[one * 11];43 }44 return 0;45}46 47// CHECK: SUMMARY: AddressSanitizer: global-buffer-overflow48