]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/sanitizer-kcfi-emit-kcfi-operand-bundle-itanium-cxx-abi.rs
Add LLVM KCFI support to the Rust compiler
[rust.git] / src / test / codegen / sanitizer-kcfi-emit-kcfi-operand-bundle-itanium-cxx-abi.rs
1 // Verifies that KCFI type metadata for functions are emitted.
2 //
3 // revisions: aarch64 x86_64
4 // [aarch64] compile-flags: --target aarch64-unknown-none
5 // [aarch64] needs-llvm-components: aarch64
6 // [x86_64] compile-flags: --target x86_64-unknown-none
7 // [x86_64] needs-llvm-components:
8 // compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi
9
10 #![crate_type="lib"]
11 #![feature(no_core, lang_items)]
12 #![no_core]
13
14 #[lang="sized"]
15 trait Sized { }
16 #[lang="copy"]
17 trait Copy { }
18
19 impl Copy for i32 {}
20
21 pub fn foo(f: fn(i32) -> i32, arg: i32) -> i32 {
22     // CHECK-LABEL: define{{.*}}foo
23     // FIXME(rcvalle): Change <unknown kind #36> to !kcfi_type when Rust is updated to LLVM 16
24     // CHECK-SAME: {{.*}}!<unknown kind #36> ![[TYPE1:[0-9]+]]
25     // CHECK: call i32 %f(i32 %arg){{.*}}[ "kcfi"(i32 -1666898348) ]
26     f(arg)
27 }
28
29 pub fn bar(f: fn(i32, i32) -> i32, arg1: i32, arg2: i32) -> i32 {
30     // CHECK-LABEL: define{{.*}}bar
31     // FIXME(rcvalle): Change <unknown kind #36> to !kcfi_type when Rust is updated to LLVM 16
32     // CHECK-SAME: {{.*}}!<unknown kind #36> ![[TYPE2:[0-9]+]]
33     // CHECK: call i32 %f(i32 %arg1, i32 %arg2){{.*}}[ "kcfi"(i32 -1789026986) ]
34     f(arg1, arg2)
35 }
36
37 pub fn baz(f: fn(i32, i32, i32) -> i32, arg1: i32, arg2: i32, arg3: i32) -> i32 {
38     // CHECK-LABEL: define{{.*}}baz
39     // FIXME(rcvalle): Change <unknown kind #36> to !kcfi_type when Rust is updated to LLVM 16
40     // CHECK-SAME: {{.*}}!<unknown kind #36> ![[TYPE3:[0-9]+]]
41     // CHECK: call i32 %f(i32 %arg1, i32 %arg2, i32 %arg3){{.*}}[ "kcfi"(i32 1248878270) ]
42     f(arg1, arg2, arg3)
43 }
44
45 // CHECK: ![[TYPE1]] = !{i32 653723426}
46 // CHECK: ![[TYPE2]] = !{i32 412174924}
47 // CHECK: ![[TYPE3]] = !{i32 -636668840}