Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / ubsan-pass-object-size.c
blobb36b8bb409aef9c90087c6f67e654dc56831a934
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) {
5 int x = (p)[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
19 x = *p[n];
22 // CHECK: ret i32
23 return x;
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
31 // CHECK: ret void
32 return p[n];
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
38 // CHECK: ret i32
39 return p[n];
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
45 // CHECK: ret i32
46 return p[n];
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
52 // CHECK: ret i32
53 return p[n];
56 // CHECK-LABEL: define{{.*}} i32 @cat(
57 int cat(int p[static 10], int n) {
58 // CHECK-NOT: __ubsan_handle_out_of_bounds
59 // CHECK: ret i32
60 return p[n];
63 // CHECK-LABEL: define{{.*}} i32 @bat(
64 int bat(int n, int p[n]) {
65 // CHECK-NOT: __ubsan_handle_out_of_bounds
66 // CHECK: ret i32
67 return p[n];