1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -x c++ -o - %s | FileCheck %s --check-prefixes=CHECK,MEMBER
3 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -fpatchable-function-entry-offset=3 -o - %s | FileCheck %s --check-prefixes=CHECK,OFFSET
4 #if !__has_feature(kcfi)
8 /// Must emit __kcfi_typeid symbols for address-taken function declarations
9 // CHECK: module asm ".weak __kcfi_typeid_[[F4:[a-zA-Z0-9_]+]]"
10 // CHECK: module asm ".set __kcfi_typeid_[[F4]], [[#%d,HASH:]]"
11 /// Must not __kcfi_typeid symbols for non-address-taken declarations
12 // CHECK-NOT: module asm ".weak __kcfi_typeid_{{f6|_Z2f6v}}"
13 typedef int (*fn_t
)(void);
15 // CHECK: define dso_local{{.*}} i32 @{{f1|_Z2f1v}}(){{.*}} !kcfi_type ![[#TYPE:]]
16 int f1(void) { return 0; }
18 // CHECK: define dso_local{{.*}} i32 @{{f2|_Z2f2v}}(){{.*}} !kcfi_type ![[#TYPE2:]]
19 unsigned int f2(void) { return 2; }
21 // CHECK-LABEL: define dso_local{{.*}} i32 @{{__call|_Z6__callPFivE}}(ptr{{.*}} %f)
22 int __call(fn_t f
) __attribute__((__no_sanitize__("kcfi"))) {
23 // CHECK-NOT: call{{.*}} i32 %{{.}}(){{.*}} [ "kcfi"
27 // CHECK: define dso_local{{.*}} i32 @{{call|_Z4callPFivE}}(ptr{{.*}} %f){{.*}}
29 // CHECK: call{{.*}} i32 %{{.}}(){{.*}} [ "kcfi"(i32 [[#HASH]]) ]
33 // CHECK-DAG: define internal{{.*}} i32 @{{f3|_ZL2f3v}}(){{.*}} !kcfi_type ![[#TYPE]]
34 static int f3(void) { return 1; }
36 // CHECK-DAG: declare !kcfi_type ![[#TYPE]]{{.*}} i32 @[[F4]]()
39 /// Must not emit !kcfi_type for non-address-taken local functions
40 // CHECK: define internal{{.*}} i32 @{{f5|_ZL2f5v}}()
41 // CHECK-NOT: !kcfi_type
43 static int f5(void) { return 2; }
45 // CHECK-DAG: declare !kcfi_type ![[#TYPE]]{{.*}} i32 @{{f6|_Z2f6v}}()
59 // MEMBER-DAG: define{{.*}} void @_ZN1A1fEv(ptr{{.*}} %this){{.*}} !kcfi_type ![[#TYPE3:]]
63 void test_member_call(void) {
64 void (A::* p
)() = &A::f
;
65 // MEMBER-DAG: call void %[[#]](ptr{{.*}} [ "kcfi"(i32 [[#%d,HASH3:]]) ]
70 // CHECK-DAG: ![[#]] = !{i32 4, !"kcfi", i32 1}
71 // OFFSET-DAG: ![[#]] = !{i32 4, !"kcfi-offset", i32 3}
72 // CHECK-DAG: ![[#TYPE]] = !{i32 [[#HASH]]}
73 // CHECK-DAG: ![[#TYPE2]] = !{i32 [[#%d,HASH2:]]}
74 // MEMBER-DAG: ![[#TYPE3]] = !{i32 [[#HASH3]]}