2013-10-23 06:51:04 +08:00
|
|
|
// RUN: %clang_cc1 -fsanitize=local-bounds -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s
|
2015-06-19 07:59:22 +08:00
|
|
|
// RUN: %clang_cc1 -fsanitize=array-bounds -O -fsanitize-trap=array-bounds -emit-llvm -triple x86_64-apple-darwin10 -DNO_DYNAMIC %s -o - | FileCheck %s
|
2012-05-09 23:53:34 +08:00
|
|
|
|
2013-10-23 06:51:04 +08:00
|
|
|
// CHECK-LABEL: @f
|
2012-05-09 23:53:34 +08:00
|
|
|
double f(int b, int i) {
|
|
|
|
double a[b];
|
2013-10-23 06:51:04 +08:00
|
|
|
// CHECK: call {{.*}} @llvm.trap
|
2012-05-09 23:53:34 +08:00
|
|
|
return a[i];
|
|
|
|
}
|
|
|
|
|
2013-10-23 06:51:04 +08:00
|
|
|
// CHECK-LABEL: @f2
|
2012-05-09 23:53:34 +08:00
|
|
|
void f2() {
|
2012-05-23 01:19:45 +08:00
|
|
|
// everything is constant; no trap possible
|
2013-10-23 06:51:04 +08:00
|
|
|
// CHECK-NOT: call {{.*}} @llvm.trap
|
2012-05-09 23:53:34 +08:00
|
|
|
int a[2];
|
|
|
|
a[1] = 42;
|
2013-10-23 06:51:04 +08:00
|
|
|
|
|
|
|
#ifndef NO_DYNAMIC
|
2012-05-09 23:53:34 +08:00
|
|
|
short *b = malloc(64);
|
2012-05-23 01:19:45 +08:00
|
|
|
b[5] = *a + a[1] + 2;
|
2013-10-23 06:51:04 +08:00
|
|
|
#endif
|
2012-05-23 01:19:45 +08:00
|
|
|
}
|
|
|
|
|
2013-10-23 06:51:04 +08:00
|
|
|
// CHECK-LABEL: @f3
|
2012-05-23 01:19:45 +08:00
|
|
|
void f3() {
|
|
|
|
int a[1];
|
2013-10-23 06:51:04 +08:00
|
|
|
// CHECK: call {{.*}} @llvm.trap
|
2012-05-23 01:19:45 +08:00
|
|
|
a[2] = 1;
|
2012-05-09 23:53:34 +08:00
|
|
|
}
|