bounds.cpp revision a0b1e21d72429c3672115b3ddc85240e3b7ac88b
1a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smith// RUN: %clang -fsanitize=bounds %s -O3 -o %T/bounds.exe
2a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smith// RUN: %T/bounds.exe 0 0 0
3a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smith// RUN: %T/bounds.exe 1 2 3
4a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smith// RUN: %T/bounds.exe 2 0 0 2>&1 | FileCheck %s --check-prefix=CHECK-A-2
5a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smith// RUN: %T/bounds.exe 0 3 0 2>&1 | FileCheck %s --check-prefix=CHECK-B-3
6a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smith// RUN: %T/bounds.exe 0 0 4 2>&1 | FileCheck %s --check-prefix=CHECK-C-4
7a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smith
8a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smithint main(int argc, char **argv) {
9a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smith  int arr[2][3][4] = {};
10a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smith
11a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smith  return arr[argv[1][0] - '0'][argv[2][0] - '0'][argv[3][0] - '0'];
12a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smith  // CHECK-A-2: bounds.cpp:11:10: runtime error: index 2 out of bounds for type 'int [2][3][4]'
13a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smith  // CHECK-B-3: bounds.cpp:11:10: runtime error: index 3 out of bounds for type 'int [3][4]'
14a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smith  // CHECK-C-4: bounds.cpp:11:10: runtime error: index 4 out of bounds for type 'int [4]'
15a0b1e21d72429c3672115b3ddc85240e3b7ac88bRichard Smith}
16