1// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 -fsanitize=cfi-icall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ITANIUM %s
2// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -O1 -fsanitize=cfi-icall  -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=MS %s
3
4void caller(void (*f)()) {
5  f();
6}
7
8static void g(void) {}
9void h(void);
10
11typedef void (*Fn)(void);
12Fn g1() {
13  return &g;
14}
15Fn h1() {
16  return &h;
17}
18
19inline void foo() {}
20void bar() { foo(); }
21
22// ITANIUM: call i1 @llvm.bitset.test(i8* %{{.*}}, metadata !"_ZTSFvE"), !nosanitize
23// ITANIUM: call void @__cfi_slowpath(i64 6588678392271548388, i8* %{{.*}}) {{.*}}, !nosanitize
24
25// MS: call i1 @llvm.bitset.test(i8* %{{.*}}, metadata !"?6AX@Z"), !nosanitize
26// MS: call void @__cfi_slowpath(i64 4195979634929632483, i8* %{{.*}}) {{.*}}, !nosanitize
27
28// ITANIUM: define available_externally void @foo()
29// MS: define linkonce_odr void @foo()
30
31// Check that we emit both string and hash based bit set entries for static void g(),
32// and don't emit them for the declaration of h().
33
34// CHECK-NOT: !{!"{{.*}}", void ()* @h, i64 0}
35// CHECK: !{!"{{.*}}", void ()* @g, i64 0}
36// CHECK-NOT: !{!"{{.*}}", void ()* @h, i64 0}
37// CHECK: !{i64 {{.*}}, void ()* @g, i64 0}
38// CHECK-NOT: !{!"{{.*}}", void ()* @h, i64 0}
39
40// ITANIUM-NOT: !{!{{.*}}, void ()* @foo,
41// ITANIUM: !{!"_ZTSFvE", void ()* @bar, i64 0}
42// ITANIUM-NOT: !{!{{.*}}, void ()* @foo,
43// ITANIUM: !{i64 6588678392271548388, void ()* @bar, i64 0}
44// ITANIUM-NOT: !{!{{.*}}, void ()* @foo,
45
46// MS: !{!"?6AX@Z", void ()* @foo, i64 0}
47// MS: !{i64 4195979634929632483, void ()* @foo, i64 0}
48
49// CHECK: !{i32 4, !"Cross-DSO CFI", i32 1}
50