Clang Project

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