[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / cfi-check-fail.c
blob15f6c77abf2b20a86154abfa11e67abc6f435b8b
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux -O0 -fsanitize-cfi-cross-dso \
2 // RUN: -fsanitize=cfi-icall,cfi-nvcall,cfi-vcall,cfi-unrelated-cast,cfi-derived-cast \
3 // RUN: -fsanitize-trap=cfi-icall,cfi-nvcall -fsanitize-recover=cfi-vcall,cfi-unrelated-cast \
4 // RUN: -emit-llvm -o - %s | FileCheck %s
6 void caller(void (*f)(void)) {
7 f();
10 // CHECK: define weak_odr hidden void @__cfi_check_fail(ptr noundef %0, ptr noundef %1)
11 // CHECK: store ptr %0, ptr %[[ALLOCA0:.*]], align 8
12 // CHECK: store ptr %1, ptr %[[ALLOCA1:.*]], align 8
13 // CHECK: %[[DATA:.*]] = load ptr, ptr %[[ALLOCA0]], align 8
14 // CHECK: %[[ADDR:.*]] = load ptr, ptr %[[ALLOCA1]], align 8
15 // CHECK: %[[ICMP_NOT_NULL:.*]] = icmp ne ptr %[[DATA]], null
16 // CHECK: br i1 %[[ICMP_NOT_NULL]], label %[[CONT0:.*]], label %[[TRAP:.*]],
18 // CHECK: [[TRAP]]:
19 // CHECK-NEXT: call void @llvm.ubsantrap(i8 2)
20 // CHECK-NEXT: unreachable
22 // CHECK: [[CONT0]]:
23 // CHECK: %[[KINDPTR:.*]] = getelementptr {{.*}} %[[DATA]], i32 0, i32 0
24 // CHECK: %[[KIND:.*]] = load i8, ptr %[[KINDPTR]], align 4
25 // CHECK: %[[VTVALID0:.*]] = call i1 @llvm.type.test(ptr %[[ADDR]], metadata !"all-vtables")
26 // CHECK: %[[VTVALID:.*]] = zext i1 %[[VTVALID0]] to i64
27 // CHECK: %[[NOT_0:.*]] = icmp ne i8 %[[KIND]], 0
28 // CHECK: br i1 %[[NOT_0]], label %[[CONT1:.*]], label %[[HANDLE0:.*]], !prof
30 // CHECK: [[HANDLE0]]:
31 // CHECK: %[[DATA0:.*]] = ptrtoint ptr %[[DATA]] to i64,
32 // CHECK: %[[ADDR0:.*]] = ptrtoint ptr %[[ADDR]] to i64,
33 // CHECK: call void @__ubsan_handle_cfi_check_fail(i64 %[[DATA0]], i64 %[[ADDR0]], i64 %[[VTVALID]])
34 // CHECK: br label %[[CONT1]]
36 // CHECK: [[CONT1]]:
37 // CHECK: %[[NOT_1:.*]] = icmp ne i8 %[[KIND]], 1
38 // CHECK: br i1 %[[NOT_1]], label %[[CONT2:.*]], label %[[HANDLE1:.*]], !nosanitize
40 // CHECK: [[HANDLE1]]:
41 // CHECK-NEXT: call void @llvm.ubsantrap(i8 2)
42 // CHECK-NEXT: unreachable
44 // CHECK: [[CONT2]]:
45 // CHECK: %[[NOT_2:.*]] = icmp ne i8 %[[KIND]], 2
46 // CHECK: br i1 %[[NOT_2]], label %[[CONT3:.*]], label %[[HANDLE2:.*]], !prof
48 // CHECK: [[HANDLE2]]:
49 // CHECK: %[[DATA2:.*]] = ptrtoint ptr %[[DATA]] to i64,
50 // CHECK: %[[ADDR2:.*]] = ptrtoint ptr %[[ADDR]] to i64,
51 // CHECK: call void @__ubsan_handle_cfi_check_fail_abort(i64 %[[DATA2]], i64 %[[ADDR2]], i64 %[[VTVALID]])
52 // CHECK: unreachable
54 // CHECK: [[CONT3]]:
55 // CHECK: %[[NOT_3:.*]] = icmp ne i8 %[[KIND]], 3
56 // CHECK: br i1 %[[NOT_3]], label %[[CONT4:.*]], label %[[HANDLE3:.*]], !prof
58 // CHECK: [[HANDLE3]]:
59 // CHECK: %[[DATA3:.*]] = ptrtoint ptr %[[DATA]] to i64,
60 // CHECK: %[[ADDR3:.*]] = ptrtoint ptr %[[ADDR]] to i64,
61 // CHECK: call void @__ubsan_handle_cfi_check_fail(i64 %[[DATA3]], i64 %[[ADDR3]], i64 %[[VTVALID]])
62 // CHECK: br label %[[CONT4]]
64 // CHECK: [[CONT4]]:
65 // CHECK: %[[NOT_4:.*]] = icmp ne i8 %[[KIND]], 4
66 // CHECK: br i1 %[[NOT_4]], label %[[CONT5:.*]], label %[[HANDLE4:.*]], !nosanitize
68 // CHECK: [[HANDLE4]]:
69 // CHECK-NEXT: call void @llvm.ubsantrap(i8 2)
70 // CHECK-NEXT: unreachable
72 // CHECK: [[CONT5]]:
73 // CHECK: ret void
75 // CHECK: define weak void @__cfi_check(i64 noundef %[[TYPE:.*]], ptr noundef %[[ADDR:.*]], ptr noundef %[[DATA:.*]]){{.*}} align 4096
76 // CHECK-NOT: }
77 // CHECK: call void @__cfi_check_fail(ptr %[[DATA]], ptr %[[ADDR]])
78 // CHECK-NEXT: ret void