2016-07-23 20:44:14 +00:00
|
|
|
// 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
|
|
|
|
// 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
|
|
|
|
// 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
|
2015-05-27 18:47:56 +00:00
|
|
|
|
|
|
|
// In this test the main thing we are searching for is something like
|
|
|
|
// 'metadata !"1B"' where "1B" is the mangled name of the class we are
|
|
|
|
// casting to (or maybe its base class in non-strict mode).
|
|
|
|
|
|
|
|
struct A {
|
|
|
|
virtual void f();
|
2016-07-23 20:44:14 +00:00
|
|
|
int i() const;
|
2015-05-27 18:47:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct B : A {
|
|
|
|
virtual void f();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct C : A {};
|
|
|
|
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-DCAST-LABEL: define hidden void @_Z3abpP1A
|
2015-05-27 18:47:56 +00:00
|
|
|
void abp(A *a) {
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-DCAST: [[P:%[^ ]*]] = call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"_ZTS1B")
|
2015-06-21 14:00:56 +00:00
|
|
|
// CHECK-DCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
|
2015-05-27 18:47:56 +00:00
|
|
|
|
|
|
|
// CHECK-DCAST: [[TRAPBB]]
|
|
|
|
// CHECK-DCAST-NEXT: call void @llvm.trap()
|
|
|
|
// CHECK-DCAST-NEXT: unreachable
|
|
|
|
|
|
|
|
// CHECK-DCAST: [[CONTBB]]
|
|
|
|
// CHECK-DCAST: ret
|
2016-07-23 20:44:14 +00:00
|
|
|
(void)static_cast<B*>(a);
|
2015-05-27 18:47:56 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-DCAST-LABEL: define hidden void @_Z3abrR1A
|
2015-05-27 18:47:56 +00:00
|
|
|
void abr(A &a) {
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-DCAST: [[P:%[^ ]*]] = call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"_ZTS1B")
|
2015-06-21 14:00:56 +00:00
|
|
|
// CHECK-DCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
|
2015-05-27 18:47:56 +00:00
|
|
|
|
|
|
|
// CHECK-DCAST: [[TRAPBB]]
|
|
|
|
// CHECK-DCAST-NEXT: call void @llvm.trap()
|
|
|
|
// CHECK-DCAST-NEXT: unreachable
|
|
|
|
|
|
|
|
// CHECK-DCAST: [[CONTBB]]
|
|
|
|
// CHECK-DCAST: ret
|
2016-07-23 20:44:14 +00:00
|
|
|
(void)static_cast<B&>(a);
|
2015-05-27 18:47:56 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-DCAST-LABEL: define hidden void @_Z4abrrO1A
|
2015-05-27 18:47:56 +00:00
|
|
|
void abrr(A &&a) {
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-DCAST: [[P:%[^ ]*]] = call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"_ZTS1B")
|
2015-06-21 14:00:56 +00:00
|
|
|
// CHECK-DCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
|
2015-05-27 18:47:56 +00:00
|
|
|
|
|
|
|
// CHECK-DCAST: [[TRAPBB]]
|
|
|
|
// CHECK-DCAST-NEXT: call void @llvm.trap()
|
|
|
|
// CHECK-DCAST-NEXT: unreachable
|
|
|
|
|
|
|
|
// CHECK-DCAST: [[CONTBB]]
|
|
|
|
// CHECK-DCAST: ret
|
2016-07-23 20:44:14 +00:00
|
|
|
(void)static_cast<B&&>(a);
|
2015-05-27 18:47:56 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-UCAST-LABEL: define hidden void @_Z3vbpPv
|
2015-05-27 18:47:56 +00:00
|
|
|
void vbp(void *p) {
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"_ZTS1B")
|
2015-06-21 14:00:56 +00:00
|
|
|
// CHECK-UCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
|
2015-05-27 18:47:56 +00:00
|
|
|
|
|
|
|
// CHECK-UCAST: [[TRAPBB]]
|
|
|
|
// CHECK-UCAST-NEXT: call void @llvm.trap()
|
|
|
|
// CHECK-UCAST-NEXT: unreachable
|
|
|
|
|
|
|
|
// CHECK-UCAST: [[CONTBB]]
|
|
|
|
// CHECK-UCAST: ret
|
2016-07-23 20:44:14 +00:00
|
|
|
(void)static_cast<B*>(p);
|
2015-05-27 18:47:56 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-UCAST-LABEL: define hidden void @_Z3vbrRc
|
2015-05-27 18:47:56 +00:00
|
|
|
void vbr(char &r) {
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"_ZTS1B")
|
2015-06-21 14:00:56 +00:00
|
|
|
// CHECK-UCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
|
2015-05-27 18:47:56 +00:00
|
|
|
|
|
|
|
// CHECK-UCAST: [[TRAPBB]]
|
|
|
|
// CHECK-UCAST-NEXT: call void @llvm.trap()
|
|
|
|
// CHECK-UCAST-NEXT: unreachable
|
|
|
|
|
|
|
|
// CHECK-UCAST: [[CONTBB]]
|
|
|
|
// CHECK-UCAST: ret
|
2016-07-23 20:44:14 +00:00
|
|
|
(void)reinterpret_cast<B&>(r);
|
2015-05-27 18:47:56 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-UCAST-LABEL: define hidden void @_Z4vbrrOc
|
2015-05-27 18:47:56 +00:00
|
|
|
void vbrr(char &&r) {
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"_ZTS1B")
|
2015-06-21 14:00:56 +00:00
|
|
|
// CHECK-UCAST-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ,]*]]
|
2015-05-27 18:47:56 +00:00
|
|
|
|
|
|
|
// CHECK-UCAST: [[TRAPBB]]
|
|
|
|
// CHECK-UCAST-NEXT: call void @llvm.trap()
|
|
|
|
// CHECK-UCAST-NEXT: unreachable
|
|
|
|
|
|
|
|
// CHECK-UCAST: [[CONTBB]]
|
|
|
|
// CHECK-UCAST: ret
|
2016-07-23 20:44:14 +00:00
|
|
|
(void)reinterpret_cast<B&&>(r);
|
2015-05-27 18:47:56 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-UCAST-LABEL: define hidden void @_Z3vcpPv
|
|
|
|
// CHECK-UCAST-STRICT-LABEL: define hidden void @_Z3vcpPv
|
2015-05-27 18:47:56 +00:00
|
|
|
void vcp(void *p) {
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-UCAST: call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"_ZTS1A")
|
|
|
|
// CHECK-UCAST-STRICT: call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"_ZTS1C")
|
|
|
|
(void)static_cast<C*>(p);
|
2015-05-27 18:47:56 +00:00
|
|
|
}
|
2015-12-30 11:49:41 +00:00
|
|
|
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-UCAST-LABEL: define hidden void @_Z3bcpP1B
|
|
|
|
// CHECK-UCAST-STRICT-LABEL: define hidden void @_Z3bcpP1B
|
2015-12-30 11:49:41 +00:00
|
|
|
void bcp(B *p) {
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-UCAST: call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"_ZTS1A")
|
|
|
|
// CHECK-UCAST-STRICT: call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"_ZTS1C")
|
|
|
|
(void)(C *)p;
|
2015-12-30 11:49:41 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-UCAST-LABEL: define hidden void @_Z8bcp_callP1B
|
|
|
|
// CHECK-UCAST-STRICT-LABEL: define hidden void @_Z8bcp_callP1B
|
2015-12-30 11:49:41 +00:00
|
|
|
void bcp_call(B *p) {
|
2016-07-23 20:44:14 +00:00
|
|
|
// CHECK-UCAST: call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"_ZTS1A")
|
|
|
|
// CHECK-UCAST-STRICT: call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"_ZTS1C")
|
2015-12-30 11:49:41 +00:00
|
|
|
((C *)p)->f();
|
|
|
|
}
|
2016-07-23 20:44:14 +00:00
|
|
|
|
|
|
|
// CHECK-UCAST-LABEL: define hidden i32 @_Z6a_callP1A
|
|
|
|
// CHECK-UCAST-STRICT-LABEL: define hidden i32 @_Z6a_callP1A
|
|
|
|
int a_call(A *a) {
|
|
|
|
// CHECK-UCAST-NOT: @llvm.type.test
|
|
|
|
// CHECK-UCAST-STRICT-NOT: @llvm.type.test
|
|
|
|
return a->i();
|
|
|
|
}
|