1 // RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcall -emit-llvm -o - %s | FileCheck %s 2 3 struct A { 4 A(); 5 virtual void f(); 6 }; 7 8 struct B : virtual A { 9 B(); 10 }; 11 12 struct C : virtual A { 13 C(); 14 }; 15 16 namespace { 17 18 struct D : B, C { 19 D(); 20 virtual void f(); 21 }; 22 23 } 24 25 A::A() {} 26 B::B() {} 27 C::C() {} 28 D::D() {} 29 30 void A::f() { 31 } 32 33 void D::f() { 34 } 35 36 // CHECK: define void @_Z2afP1A 37 void af(A *a) { 38 // CHECK: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1A") 39 // CHECK-NEXT: br i1 [[P]], label %[[CONTBB:[^ ]*]], label %[[TRAPBB:[^ ]*]] 40 41 // CHECK: [[TRAPBB]] 42 // CHECK-NEXT: call void @llvm.trap() 43 // CHECK-NEXT: unreachable 44 45 // CHECK: [[CONTBB]] 46 // CHECK: call void % 47 a->f(); 48 } 49 50 // CHECK: define internal void @_Z2dfPN12_GLOBAL__N_11DE 51 void df(D *d) { 52 // CHECK: {{%[^ ]*}} = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"[{{.*}}cfi-vcall.cpp]N12_GLOBAL__N_11DE") 53 d->f(); 54 } 55 56 D d; 57 58 void foo() { 59 df(&d); 60 } 61 62 // CHECK-DAG: !{!"1A", [3 x i8*]* @_ZTV1A, i64 16} 63 // CHECK-DAG: !{!"1A", [5 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32} 64 // CHECK-DAG: !{!"1B", [5 x i8*]* @_ZTCN12_GLOBAL__N_11DE0_1B, i64 32} 65 // CHECK-DAG: !{!"1A", [9 x i8*]* @_ZTCN12_GLOBAL__N_11DE8_1C, i64 64} 66 // CHECK-DAG: !{!"1C", [9 x i8*]* @_ZTCN12_GLOBAL__N_11DE8_1C, i64 32} 67 // CHECK-DAG: !{!"1A", [10 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32} 68 // CHECK-DAG: !{!"1B", [10 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32} 69 // CHECK-DAG: !{!"1C", [10 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 72} 70 // CHECK-DAG: !{!"[{{.*}}cfi-vcall.cpp]N12_GLOBAL__N_11DE", [10 x i8*]* @_ZTVN12_GLOBAL__N_11DE, i64 32} 71 // CHECK-DAG: !{!"1A", [5 x i8*]* @_ZTV1B, i64 32} 72 // CHECK-DAG: !{!"1B", [5 x i8*]* @_ZTV1B, i64 32} 73 // CHECK-DAG: !{!"1A", [5 x i8*]* @_ZTV1C, i64 32} 74 // CHECK-DAG: !{!"1C", [5 x i8*]* @_ZTV1C, i64 32} 75