llvm-project/clang/test/CodeGenCXX/cfi-vcall.cpp

91 lines
2.2 KiB
C++
Raw Normal View History

// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck %s
struct A {
A();
virtual void f();
};
struct B : virtual A {
B();
};
struct C : virtual A {
C();
};
namespace {
struct D : B, C {
D();
virtual void f();
};
}
A::A() {}
B::B() {}
C::C() {}
D::D() {}
void A::f() {
}
void D::f() {
}
// CHECK: define void @_Z2afP1A
void af(A *a) {
// CHECK: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1A")
// CHECK-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ]*]]
// CHECK: [[TRAPBB]]
// CHECK-NEXT: call void @llvm.trap()
// CHECK-NEXT: unreachable
// CHECK: [[CONTBB]]
// CHECK: call void %
a->f();
}
// CHECK: define internal void @_Z3df1PN12_GLOBAL__N_11DE
void df1(D *d) {
// CHECK: {{%[^ ]*}} = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"[{{.*}}cfi-vcall.cpp]N12_GLOBAL__N_11DE")
d->f();
}
// CHECK: define internal void @_Z3df2PN12_GLOBAL__N_11DE
__attribute__((no_sanitize("cfi")))
void df2(D *d) {
// CHECK-NOT: call i1 @llvm.bitset.test
d->f();
}
// CHECK: define internal void @_Z3df3PN12_GLOBAL__N_11DE
__attribute__((no_sanitize("address"))) __attribute__((no_sanitize("cfi-vcall")))
void df3(D *d) {
// CHECK-NOT: call i1 @llvm.bitset.test
d->f();
}
D d;
void foo() {
df1(&d);
df2(&d);
df3(&d);
}
// CHECK-DAG: !{!"1A", [3 x i8*]* @_ZTV1A, i64 16}
// CHECK-DAG: !{!"1A", [5 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32}
// CHECK-DAG: !{!"1B", [5 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32}
// CHECK-DAG: !{!"1A", [9 x i8*]* @_ZTCN12_GLOBAL__N_11DE8_1C, i64 64}
// CHECK-DAG: !{!"1C", [9 x i8*]* @_ZTCN12_GLOBAL__N_11DE8_1C, i64 32}
// CHECK-DAG: !{!"1A", [10 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32}
// CHECK-DAG: !{!"1B", [10 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32}
// CHECK-DAG: !{!"1C", [10 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 72}
// CHECK-DAG: !{!"[{{.*}}cfi-vcall.cpp]N12_GLOBAL__N_11DE", [10 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32}
// CHECK-DAG: !{!"1A", [5 x i8*]* @_ZTV1B, i64 32}
// CHECK-DAG: !{!"1B", [5 x i8*]* @_ZTV1B, i64 32}
// CHECK-DAG: !{!"1A", [5 x i8*]* @_ZTV1C, i64 32}
// CHECK-DAG: !{!"1C", [5 x i8*]* @_ZTV1C, i64 32}