aboutsummaryrefslogtreecommitdiff
path: root/test/CodeGen/bounds-checking.c
blob: fa7541f8141e7e0133c2349fca5aaee5172ad616 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// RUN: %clang_cc1 -fsanitize=bounds -emit-llvm -triple x86_64-apple-darwin10 < %s | FileCheck %s

// CHECK: @f
double f(int b, int i) {
  double a[b];
  // CHECK: trap
  return a[i];
}

// CHECK: @f2
void f2() {
  // everything is constant; no trap possible
  // CHECK-NOT: trap
  int a[2];
  a[1] = 42;
  
  short *b = malloc(64);
  b[5] = *a + a[1] + 2;
}

// CHECK: @f3
void f3() {
  int a[1];
  // CHECK: trap
  a[2] = 1;
}