Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / cfi-icall-cross-dso.c
blob4e9e565a7db7772c10bf549ea19398cf7bede8c4
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 -fno-inline \
2 // RUN: -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \
3 // RUN: -fsanitize-cfi-canonical-jump-tables -emit-llvm -o - %s | FileCheck \
4 // RUN: --check-prefix=CHECK --check-prefix=CHECK-DIAG \
5 // RUN: --check-prefix=ITANIUM --check-prefix=ITANIUM-DIAG \
6 // RUN: %s
8 // RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 -fno-inline \
9 // RUN: -fsanitize=cfi-icall -fsanitize-cfi-cross-dso -fsanitize-trap=cfi-icall \
10 // RUN: -fsanitize-cfi-canonical-jump-tables -emit-llvm -o - %s | FileCheck \
11 // RUN: --check-prefix=CHECK \
12 // RUN: --check-prefix=ITANIUM --check-prefix=ITANIUM-TRAP \
13 // RUN: %s
15 // RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -O1 -fno-inline \
16 // RUN: -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \
17 // RUN: -fsanitize-cfi-canonical-jump-tables -emit-llvm -o - %s | FileCheck \
18 // RUN: --check-prefix=CHECK --check-prefix=CHECK-DIAG \
19 // RUN: --check-prefix=MS --check-prefix=MS-DIAG \
20 // RUN: %s
22 // RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -O1 -fno-inline \
23 // RUN: -fsanitize=cfi-icall -fsanitize-cfi-cross-dso -fsanitize-trap=cfi-icall \
24 // RUN: -fsanitize-cfi-canonical-jump-tables -emit-llvm -o - %s | FileCheck \
25 // RUN: --check-prefix=CHECK \
26 // RUN: --check-prefix=MS --check-prefix=MS-TRAP \
27 // RUN: %s
29 // CHECK-DIAG: @[[SRC:.*]] = private unnamed_addr constant {{.*}}cfi-icall-cross-dso.c\00
30 // CHECK-DIAG: @[[TYPE:.*]] = private unnamed_addr constant { i16, i16, [{{.*}} x i8] } { i16 -1, i16 0, [{{.*}} x i8] c"'void ()'\00"
31 // CHECK-DIAG: @[[DATA:.*]] = private unnamed_addr global {{.*}}@[[SRC]]{{.*}}@[[TYPE]]
34 // ITANIUM: call i1 @llvm.type.test(ptr %{{.*}}, metadata !"_ZTSFvE"), !nosanitize
35 // ITANIUM-DIAG: call void @__cfi_slowpath_diag(i64 6588678392271548388, ptr %{{.*}}, {{.*}}@[[DATA]]{{.*}}) {{.*}}, !nosanitize
36 // ITANIUM-TRAP: call void @__cfi_slowpath(i64 6588678392271548388, ptr %{{.*}}) {{.*}}, !nosanitize
38 // MS: call i1 @llvm.type.test(ptr %{{.*}}, metadata !"?6AX@Z"), !nosanitize
39 // MS-DIAG: call void @__cfi_slowpath_diag(i64 4195979634929632483, ptr %{{.*}}, {{.*}}@[[DATA]]{{.*}}) {{.*}}, !nosanitize
40 // MS-TRAP: call void @__cfi_slowpath(i64 4195979634929632483, ptr %{{.*}}) {{.*}}, !nosanitize
42 // ITANIUM-DIAG: declare void @__cfi_slowpath_diag(
43 // ITANIUM-TRAP: declare void @__cfi_slowpath(
44 // MS-DIAG: declare dso_local void @__cfi_slowpath_diag(
45 // MS-TRAP: declare dso_local void @__cfi_slowpath(
47 void caller(void (*f)()) {
48 f();
51 // Check that we emit both string and hash based type entries for static void g(),
52 // and don't emit them for the declaration of h().
54 // CHECK: define internal void @g({{.*}} !type [[TVOID:![0-9]+]] !type [[TVOID_GENERALIZED:![0-9]+]] !type [[TVOID_ID:![0-9]+]]
55 static void g(void) {}
57 // CHECK: declare {{(dso_local )?}}void @h({{[^!]*$}}
58 void h(void);
60 typedef void (*Fn)(void);
61 Fn g1() {
62 return &g;
64 Fn h1() {
65 return &h;
68 // CHECK: define {{(dso_local )?}}void @bar({{.*}} !type [[TNOPROTO:![0-9]+]] !type [[TNOPROTO_GENERALIZED:![0-9]+]] !type [[TNOPROTO_ID:![0-9]+]]
69 // ITANIUM: declare void @foo({{[^!]*$}}
70 // MS: define linkonce_odr dso_local void @foo({{.*}} !type [[TNOPROTO]] !type [[TNOPROTO_GENERALIZED:![0-9]+]] !type [[TNOPROTO_ID]]
71 inline void foo() {}
72 void bar() { foo(); }
74 // ITANIUM: define weak void @__cfi_check
75 // MS: define weak dso_local void @__cfi_check
77 // CHECK: !{i32 4, !"Cross-DSO CFI", i32 1}
79 // Check that the type entries are correct.
81 // ITANIUM: [[TVOID]] = !{i64 0, !"_ZTSFvvE"}
82 // ITANIUM: [[TVOID_GENERALIZED]] = !{i64 0, !"_ZTSFvvE.generalized"}
83 // ITANIUM: [[TVOID_ID]] = !{i64 0, i64 9080559750644022485}
84 // ITANIUM: [[TNOPROTO]] = !{i64 0, !"_ZTSFvE"}
85 // ITANIUM: [[TNOPROTO_GENERALIZED]] = !{i64 0, !"_ZTSFvE.generalized"}
86 // ITANIUM: [[TNOPROTO_ID]] = !{i64 0, i64 6588678392271548388}
88 // MS: [[TVOID]] = !{i64 0, !"?6AXXZ"}
89 // MS: [[TVOID_GENERALIZED]] = !{i64 0, !"?6AXXZ.generalized"}
90 // MS: [[TVOID_ID]] = !{i64 0, i64 5113650790573562461}
91 // MS: [[TNOPROTO]] = !{i64 0, !"?6AX@Z"}
92 // MS: [[TNOPROTO_GENERALIZED]] = !{i64 0, !"?6AX@Z.generalized"}
93 // MS: [[TNOPROTO_ID]] = !{i64 0, i64 4195979634929632483}