Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CodeGen / ubsan-bitfield-conversion.c
blob61d7634f9a336292c85115dc9e2066922c38df54
1 // RUN: %clang -fsanitize=implicit-bitfield-conversion -target x86_64-linux -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-BITFIELD-CONVERSION
2 // RUN: %clang -fsanitize=implicit-integer-conversion -target x86_64-linux -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK
3 // RUN: %clang -fsanitize=implicit-conversion -target x86_64-linux -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-BITFIELD-CONVERSION
5 typedef struct _xx {
6 int x1:3;
7 char x2:2;
8 } xx, *pxx;
10 xx vxx;
12 // CHECK-LABEL: define{{.*}} void @foo1
13 void foo1(int x) {
14 vxx.x1 = x;
15 // CHECK: store i8 %{{.*}}
16 // CHECK-NEXT: [[BFRESULTSHL:%.*]] = shl i8 {{.*}}, 5
17 // CHECK-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 [[BFRESULTSHL]], 5
18 // CHECK-NEXT: [[BFRESULTCAST:%.*]] = sext i8 [[BFRESULTASHR]] to i32
19 // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
20 // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
21 // CHECK-BITFIELD-CONVERSION: [[CONT]]:
22 // CHECK-NEXT: ret void
25 // CHECK-LABEL: define{{.*}} void @foo2
26 void foo2(int x) {
27 vxx.x2 = x;
28 // CHECK: store i8 %{{.*}}
29 // CHECK-NEXT: [[BFRESULTSHL:%.*]] = shl i8 {{.*}}, 6
30 // CHECK-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 [[BFRESULTSHL]], 6
31 // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
32 // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
33 // CHECK-BITFIELD-CONVERSION: [[CONT]]:
34 // CHECK-NEXT: ret void
37 // CHECK-LABEL: define{{.*}} void @foo3
38 void foo3() {
39 vxx.x1++;
40 // CHECK: store i8 %{{.*}}
41 // CHECK-NEXT: [[BFRESULTSHL:%.*]] = shl i8 {{.*}}, 5
42 // CHECK-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 [[BFRESULTSHL]], 5
43 // CHECK-NEXT: [[BFRESULTCAST:%.*]] = sext i8 [[BFRESULTASHR]] to i32
44 // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
45 // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
46 // CHECK-BITFIELD-CONVERSION: [[CONT]]:
47 // CHECK-NEXT: ret void
50 // CHECK-LABEL: define{{.*}} void @foo4
51 void foo4(int x) {
52 vxx.x1 += x;
53 // CHECK: store i8 %{{.*}}
54 // CHECK-NEXT: [[BFRESULTSHL:%.*]] = shl i8 {{.*}}, 5
55 // CHECK-NEXT: [[BFRESULTASHR:%.*]] = ashr i8 [[BFRESULTSHL]], 5
56 // CHECK-NEXT: [[BFRESULTCAST:%.*]] = sext i8 [[BFRESULTASHR]] to i32
57 // CHECK-BITFIELD-CONVERSION: call void @__ubsan_handle_implicit_conversion
58 // CHECK-BITFIELD-CONVERSION-NEXT: br label %[[CONT:.*]], !nosanitize
59 // CHECK-BITFIELD-CONVERSION: [[CONT]]:
60 // CHECK-NEXT: ret void