1 // RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-mfcall -fsanitize-trap=cfi-mfcall -fvisibility hidden -emit-llvm -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-mfcall -fsanitize-trap=cfi-mfcall -fvisibility default -emit-llvm -o - %s | FileCheck --check-prefix=DEFAULT %s
3 // With -fwhole-program-vtables we should get the member function pointer type
4 // test, even without hidden visibility.
5 // RUN: %clang_cc1 -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck %s --check-prefix=WPV
6
7 struct B1 {};
8 struct B2 {};
9 struct B3 : B2 {};
10 struct S : B1, B3 {};
11
12 // DEFAULT-NOT: llvm.type.test
13
f(S * s,void (S::* p)())14 void f(S *s, void (S::*p)()) {
15 // WPV: [[OFFSET:%.*]] = sub i64 {{.*}}, 1
16 // WPV: [[VFPTR:%.*]] = getelementptr i8, i8* %{{.*}}, i64 [[OFFSET]]
17 // WPV: [[TT:%.*]] = call i1 @llvm.type.test(i8* [[VFPTR]], metadata !"_ZTSM1SFvvE.virtual")
18 // CHECK: [[OFFSET:%.*]] = sub i64 {{.*}}, 1
19 // CHECK: [[VFPTR:%.*]] = getelementptr i8, i8* %{{.*}}, i64 [[OFFSET]]
20 // CHECK: [[TT:%.*]] = call i1 @llvm.type.test(i8* [[VFPTR]], metadata !"_ZTSM1SFvvE.virtual")
21 // CHECK: br i1 [[TT]], label {{.*}}, label %[[TRAP1:[^,]*]]
22
23 // CHECK: [[TRAP1]]:
24 // CHECK-NEXT: llvm.ubsantrap
25
26 // CHECK: [[NVFPTR:%.*]] = bitcast void (%struct.S*)* {{.*}} to i8*
27 // CHECK: [[TT1:%.*]] = call i1 @llvm.type.test(i8* [[NVFPTR]], metadata !"_ZTSM2B1FvvE")
28 // CHECK: [[OR1:%.*]] = or i1 false, [[TT1]]
29 // CHECK: [[TT2:%.*]] = call i1 @llvm.type.test(i8* [[NVFPTR]], metadata !"_ZTSM2B2FvvE")
30 // CHECK: [[OR2:%.*]] = or i1 [[OR1]], [[TT2]]
31 // CHECK: br i1 [[OR2]], label {{.*}}, label %[[TRAP2:[^,]*]]
32
33 // CHECK: [[TRAP2]]:
34 // CHECK-NEXT: llvm.ubsantrap
35 (s->*p)();
36 }
37