blob: 795e50bf614ee4dd4dbe5466ad563070193ef224 [file] [log] [blame]
Alexey Samsonov4f319cc2014-07-02 16:54:41 +00001// 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
11struct C {
12 static int array[10];
13};
14
15int 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
17int 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
20int 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];
Alexey Samsonov15c96692014-07-12 00:42:52 +000027 // 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
Alexey Samsonov4f319cc2014-07-02 16:54:41 +000028 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