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