2015-04-02 08:23:30 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck %s
|
2015-02-21 04:30:56 +08:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2015-05-16 02:33:32 +08:00
|
|
|
// CHECK: define internal void @_Z3df1PN12_GLOBAL__N_11DE
|
|
|
|
void df1(D *d) {
|
2015-04-02 08:23:30 +08:00
|
|
|
// CHECK: {{%[^ ]*}} = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"[{{.*}}cfi-vcall.cpp]N12_GLOBAL__N_11DE")
|
2015-02-21 04:30:56 +08:00
|
|
|
d->f();
|
|
|
|
}
|
|
|
|
|
2015-05-16 02:33:32 +08:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2015-02-21 04:30:56 +08:00
|
|
|
D d;
|
|
|
|
|
|
|
|
void foo() {
|
2015-05-16 02:33:32 +08:00
|
|
|
df1(&d);
|
|
|
|
df2(&d);
|
|
|
|
df3(&d);
|
2015-02-21 04:30:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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}
|
2015-04-02 08:23:30 +08:00
|
|
|
// CHECK-DAG: !{!"[{{.*}}cfi-vcall.cpp]N12_GLOBAL__N_11DE", [10 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32}
|
2015-02-21 04:30:56 +08:00
|
|
|
// 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}
|