1 // RUN: %clang_cc1 -triple x86_64-unknown-linux -fvisibility=hidden -std=c++11 -fsanitize=cfi-derived-cast -fsanitize-trap=cfi-derived-cast -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-DCAST %s
2 // RUN: %clang_cc1 -triple x86_64-unknown-linux -fvisibility=hidden -std=c++11 -fsanitize=cfi-unrelated-cast -fsanitize-trap=cfi-unrelated-cast -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-UCAST %s
3 // RUN: %clang_cc1 -triple x86_64-unknown-linux -fvisibility=hidden -std=c++11 -fsanitize=cfi-unrelated-cast,cfi-cast-strict -fsanitize-trap=cfi-unrelated-cast,cfi-cast-strict -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-UCAST-STRICT %s
5 // In this test the main thing we are searching for is something like
6 // 'metadata !"1B"' where "1B" is the mangled name of the class we are
7 // casting to (or maybe its base class in non-strict mode).
20 // CHECK-DCAST-LABEL: define hidden void @_Z3abpP1A
22 // CHECK-DCAST: [[P:%[^ ]*]] = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1B")
23 // CHECK-DCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
25 // CHECK-DCAST: [[TRAPBB]]
26 // CHECK-DCAST-NEXT: call void @llvm.ubsantrap(i8 2)
27 // CHECK-DCAST-NEXT: unreachable
29 // CHECK-DCAST: [[CONTBB]]
31 (void)static_cast<B
*>(a
);
34 // CHECK-DCAST-LABEL: define hidden void @_Z3abrR1A
36 // CHECK-DCAST: [[P:%[^ ]*]] = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1B")
37 // CHECK-DCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
39 // CHECK-DCAST: [[TRAPBB]]
40 // CHECK-DCAST-NEXT: call void @llvm.ubsantrap(i8 2)
41 // CHECK-DCAST-NEXT: unreachable
43 // CHECK-DCAST: [[CONTBB]]
45 (void)static_cast<B
&>(a
);
48 // CHECK-DCAST-LABEL: define hidden void @_Z4abrrO1A
50 // CHECK-DCAST: [[P:%[^ ]*]] = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1B")
51 // CHECK-DCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
53 // CHECK-DCAST: [[TRAPBB]]
54 // CHECK-DCAST-NEXT: call void @llvm.ubsantrap(i8 2)
55 // CHECK-DCAST-NEXT: unreachable
57 // CHECK-DCAST: [[CONTBB]]
59 (void)static_cast<B
&&>(a
);
62 // CHECK-UCAST-LABEL: define hidden void @_Z3vbpPv
64 // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1B")
65 // CHECK-UCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
67 // CHECK-UCAST: [[TRAPBB]]
68 // CHECK-UCAST-NEXT: call void @llvm.ubsantrap(i8 2)
69 // CHECK-UCAST-NEXT: unreachable
71 // CHECK-UCAST: [[CONTBB]]
73 (void)static_cast<B
*>(p
);
76 // CHECK-UCAST-LABEL: define hidden void @_Z3vbrRc
78 // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1B")
79 // CHECK-UCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
81 // CHECK-UCAST: [[TRAPBB]]
82 // CHECK-UCAST-NEXT: call void @llvm.ubsantrap(i8 2)
83 // CHECK-UCAST-NEXT: unreachable
85 // CHECK-UCAST: [[CONTBB]]
87 (void)reinterpret_cast<B
&>(r
);
90 // CHECK-UCAST-LABEL: define hidden void @_Z4vbrrOc
92 // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1B")
93 // CHECK-UCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
95 // CHECK-UCAST: [[TRAPBB]]
96 // CHECK-UCAST-NEXT: call void @llvm.ubsantrap(i8 2)
97 // CHECK-UCAST-NEXT: unreachable
99 // CHECK-UCAST: [[CONTBB]]
101 (void)reinterpret_cast<B
&&>(r
);
104 // CHECK-UCAST-LABEL: define hidden void @_Z3vcpPv
105 // CHECK-UCAST-STRICT-LABEL: define hidden void @_Z3vcpPv
107 // CHECK-UCAST: call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1A")
108 // CHECK-UCAST-STRICT: call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1C")
109 (void)static_cast<C
*>(p
);
112 // CHECK-UCAST-LABEL: define hidden void @_Z3bcpP1B
113 // CHECK-UCAST-STRICT-LABEL: define hidden void @_Z3bcpP1B
115 // CHECK-UCAST: call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1A")
116 // CHECK-UCAST-STRICT: call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1C")
120 // CHECK-UCAST-LABEL: define hidden void @_Z8bcp_callP1B
121 // CHECK-UCAST-STRICT-LABEL: define hidden void @_Z8bcp_callP1B
122 void bcp_call(B
*p
) {
123 // CHECK-UCAST: call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1A")
124 // CHECK-UCAST-STRICT: call i1 @llvm.type.test(ptr {{%[^ ]*}}, metadata !"_ZTS1C")
128 // CHECK-UCAST-LABEL: define hidden noundef i32 @_Z6a_callP1A
129 // CHECK-UCAST-STRICT-LABEL: define hidden noundef i32 @_Z6a_callP1A
131 // CHECK-UCAST-NOT: @llvm.type.test
132 // CHECK-UCAST-STRICT-NOT: @llvm.type.test