11402830dSGreg Fitzgerald // RUN: %clangxx -fsanitize=bounds %s -O3 -o %t 21402830dSGreg Fitzgerald // RUN: %run %t 0 0 0 31402830dSGreg Fitzgerald // RUN: %run %t 1 2 3 4a68d90faSPeter Collingbourne // RUN: %expect_crash %run %t 2 0 0 2>&1 | FileCheck %s --check-prefix=CHECK-A-2 51402830dSGreg Fitzgerald // RUN: %run %t 0 3 0 2>&1 | FileCheck %s --check-prefix=CHECK-B-3 61402830dSGreg Fitzgerald // RUN: %run %t 0 0 4 2>&1 | FileCheck %s --check-prefix=CHECK-C-4 7ba869e79SAlexey Samsonov get_int(int * const p,int i)8*75850f57SVedant Kumarint get_int(int *const p __attribute__((pass_object_size(0))), int i) { 9*75850f57SVedant Kumar // CHECK-A-2: bounds.cpp:[[@LINE+1]]:10: runtime error: index 2 out of bounds for type 'int *' 10*75850f57SVedant Kumar return p[i]; 11*75850f57SVedant Kumar } 12*75850f57SVedant Kumar get_double(double * const p,int i)13*75850f57SVedant Kumarint get_double(double *const p __attribute__((pass_object_size(0))), int i) { 14*75850f57SVedant Kumar // CHECK-A-2: bounds.cpp:[[@LINE+1]]:10: runtime error: index 2 out of bounds for type 'double *' 15*75850f57SVedant Kumar return p[i]; 16*75850f57SVedant Kumar } 17*75850f57SVedant Kumar main(int argc,char ** argv)18ba869e79SAlexey Samsonovint main(int argc, char **argv) { 19*75850f57SVedant Kumar int bar[2]; 20*75850f57SVedant Kumar get_int(bar, argv[1][0] - '0'); 21*75850f57SVedant Kumar 22*75850f57SVedant Kumar double baz[2]; 23*75850f57SVedant Kumar get_double(baz, argv[1][0] - '0'); 24*75850f57SVedant Kumar 25ba869e79SAlexey Samsonov int arr[2][3][4] = {}; 26ba869e79SAlexey Samsonov 27ba869e79SAlexey Samsonov return arr[argv[1][0] - '0'][argv[2][0] - '0'][argv[3][0] - '0']; 288b9d18e4SAlexey Samsonov // CHECK-A-2: bounds.cpp:[[@LINE-1]]:10: runtime error: index 2 out of bounds for type 'int[2][3][4]' 298b9d18e4SAlexey Samsonov // CHECK-B-3: bounds.cpp:[[@LINE-2]]:10: runtime error: index 3 out of bounds for type 'int[3][4]' 308b9d18e4SAlexey Samsonov // CHECK-C-4: bounds.cpp:[[@LINE-3]]:10: runtime error: index 4 out of bounds for type 'int[4]' 31ba869e79SAlexey Samsonov } 32