70 lines · c
1// RUN: %clang_cc1 %s -emit-llvm -w -triple x86_64-apple-darwin10 -fsanitize=array-bounds -o - | FileCheck %s2 3// CHECK-LABEL: define{{.*}} i32 @foo(4int foo(int *const p __attribute__((pass_object_size(0))), int n) {5 int x = (p)[n];6 7 // CHECK: [[SIZE_ALLOCA:%.*]] = alloca i64, align 88 // CHECK: store i64 %{{.*}}, ptr [[SIZE_ALLOCA]], align 89 // CHECK: [[LOAD_SIZE:%.*]] = load i64, ptr [[SIZE_ALLOCA]], align 8, !nosanitize10 // CHECK-NEXT: [[SCALED_SIZE:%.*]] = udiv i64 [[LOAD_SIZE]], 4, !nosanitize11 // CHECK-NEXT: [[SEXT_N:%.*]] = sext i32 %{{.*}} to i64, !nosanitize12 // CHECK-NEXT: [[ICMP:%.*]] = icmp ult i64 [[SEXT_N]], [[SCALED_SIZE]], !nosanitize13 // CHECK-NEXT: br i1 [[ICMP]], {{.*}} !nosanitize14 // CHECK: __ubsan_handle_out_of_bounds15 16 {17 int **q = &p;18 int **p = q; // Shadow the parameter. The pass_object_size info is lost.19 // CHECK-NOT: __ubsan_handle_out_of_bounds20 x = *p[n];21 }22 23 // CHECK: ret i3224 return x;25}26 27typedef struct {} ZeroSizedType;28 29// CHECK-LABEL: define{{.*}} void @bar(30ZeroSizedType bar(ZeroSizedType *const p __attribute__((pass_object_size(0))), int n) {31 // CHECK-NOT: __ubsan_handle_out_of_bounds32 // CHECK: ret void33 return p[n];34}35 36// CHECK-LABEL: define{{.*}} i32 @baz(37int baz(int *const p __attribute__((pass_object_size(1))), int n) {38 // CHECK: __ubsan_handle_out_of_bounds39 // CHECK: ret i3240 return p[n];41}42 43// CHECK-LABEL: define{{.*}} i32 @mat(44int mat(int *const p __attribute__((pass_object_size(2))), int n) {45 // CHECK-NOT: __ubsan_handle_out_of_bounds46 // CHECK: ret i3247 return p[n];48}49 50// CHECK-LABEL: define{{.*}} i32 @pat(51int pat(int *const p __attribute__((pass_object_size(3))), int n) {52 // CHECK-NOT: __ubsan_handle_out_of_bounds53 // CHECK: ret i3254 return p[n];55}56 57// CHECK-LABEL: define{{.*}} i32 @cat(58int cat(int p[static 10], int n) {59 // CHECK-NOT: __ubsan_handle_out_of_bounds60 // CHECK: ret i3261 return p[n];62}63 64// CHECK-LABEL: define{{.*}} i32 @bat(65int bat(int n, int p[n]) {66 // CHECK-NOT: __ubsan_handle_out_of_bounds67 // CHECK: ret i3268 return p[n];69}70