1 // RUN: %clang_cc1 %s -emit-llvm -w -triple x86_64-apple-darwin10 -fsanitize=array-bounds -o - | FileCheck %s
3 // CHECK-LABEL: define{{.*}} i32 @foo(
4 int foo(int *const p
__attribute__((pass_object_size(0))), int n
) {
7 // CHECK: [[SIZE_ALLOCA:%.*]] = alloca i64, align 8
8 // CHECK: store i64 %{{.*}}, ptr [[SIZE_ALLOCA]], align 8
9 // CHECK: [[LOAD_SIZE:%.*]] = load i64, ptr [[SIZE_ALLOCA]], align 8, !nosanitize
10 // CHECK-NEXT: [[SCALED_SIZE:%.*]] = udiv i64 [[LOAD_SIZE]], 4, !nosanitize
11 // CHECK-NEXT: [[SEXT_N:%.*]] = sext i32 %{{.*}} to i64, !nosanitize
12 // CHECK-NEXT: [[ICMP:%.*]] = icmp ult i64 [[SEXT_N]], [[SCALED_SIZE]], !nosanitize
13 // CHECK-NEXT: br i1 [[ICMP]], {{.*}} !nosanitize
14 // CHECK: __ubsan_handle_out_of_bounds
17 int **p
= &p
; // Shadow the parameter. The pass_object_size info is lost.
18 // CHECK-NOT: __ubsan_handle_out_of_bounds
26 typedef struct {} ZeroSizedType
;
28 // CHECK-LABEL: define{{.*}} void @bar(
29 ZeroSizedType
bar(ZeroSizedType
*const p
__attribute__((pass_object_size(0))), int n
) {
30 // CHECK-NOT: __ubsan_handle_out_of_bounds
35 // CHECK-LABEL: define{{.*}} i32 @baz(
36 int baz(int *const p
__attribute__((pass_object_size(1))), int n
) {
37 // CHECK: __ubsan_handle_out_of_bounds
42 // CHECK-LABEL: define{{.*}} i32 @mat(
43 int mat(int *const p
__attribute__((pass_object_size(2))), int n
) {
44 // CHECK-NOT: __ubsan_handle_out_of_bounds
49 // CHECK-LABEL: define{{.*}} i32 @pat(
50 int pat(int *const p
__attribute__((pass_object_size(3))), int n
) {
51 // CHECK-NOT: __ubsan_handle_out_of_bounds
56 // CHECK-LABEL: define{{.*}} i32 @cat(
57 int cat(int p
[static 10], int n
) {
58 // CHECK-NOT: __ubsan_handle_out_of_bounds
63 // CHECK-LABEL: define{{.*}} i32 @bat(
64 int bat(int n
, int p
[n
]) {
65 // CHECK-NOT: __ubsan_handle_out_of_bounds