1// RUN: %clang_cc1 -fsanitize=local-bounds -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s
2// RUN: %clang_cc1 -fsanitize=array-bounds -O -fsanitize-undefined-trap-on-error -emit-llvm -triple x86_64-apple-darwin10 -DNO_DYNAMIC %s -o - | FileCheck %s
3
4// CHECK-LABEL: @f
5double f(int b, int i) {
6  double a[b];
7  // CHECK: call {{.*}} @llvm.trap
8  return a[i];
9}
10
11// CHECK-LABEL: @f2
12void f2() {
13  // everything is constant; no trap possible
14  // CHECK-NOT: call {{.*}} @llvm.trap
15  int a[2];
16  a[1] = 42;
17
18#ifndef NO_DYNAMIC
19  short *b = malloc(64);
20  b[5] = *a + a[1] + 2;
21#endif
22}
23
24// CHECK-LABEL: @f3
25void f3() {
26  int a[1];
27  // CHECK: call {{.*}} @llvm.trap
28  a[2] = 1;
29}
30