Skip to content

Commit d3f55b1

Browse files
authored
Unrolled build for #159950
Rollup merge of #159950 - Darksonn:cfi-return-types, r=folkertdev Add CFI tests for return types and never type In a few different conversations, the CFI types of various functions has come up. First, the CFI type of returning `!` came up in #159446 (comment), where we found that it doesn't have the same CFI type as returning `()`, which it probably should. Then in #159935, I wanted to make sure that this does not change the CFI type of functions when `*mut c_void` appears as an argument. Luckily it does not since it's a lang item, but there's no test for this case. Thus, add tests for all of these cases and a few others. AI assistance was involved with writing the test.
2 parents dc3f851 + 8e0f2e9 commit d3f55b1

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Verifies that type metadata identifiers for functions are emitted correctly
2+
// for return types.
3+
//
4+
//@ needs-sanitizer-cfi
5+
//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static -Cunsafe-allow-abi-mismatch=sanitizer
6+
7+
#![crate_type = "lib"]
8+
9+
extern crate core;
10+
use core::ffi::*;
11+
12+
pub unsafe extern "C" fn foo1() {}
13+
// CHECK: define{{.*}}foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
14+
15+
// This should probably have the same CFI type as `foo1`, but it doesn't right now.
16+
pub unsafe extern "C" fn foo2() -> ! {
17+
loop {}
18+
}
19+
// CHECK: define{{.*}}foo2{{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
20+
21+
pub unsafe extern "C" fn foo3(arg: *mut c_void) -> *mut c_void {
22+
arg
23+
}
24+
// CHECK: define{{.*}}foo3{{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
25+
26+
pub unsafe extern "C" fn foo4(arg: *const c_void) -> *const c_void {
27+
arg
28+
}
29+
// CHECK: define{{.*}}foo4{{.*}}!type ![[TYPE4:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
30+
31+
// `*mut ()` has the same CFI type (`_ZTSFPvS_E`) as `*mut c_void` (`foo3`), so it reuses `TYPE3`.
32+
pub unsafe extern "C" fn foo5(arg: *mut ()) -> *mut () {
33+
arg
34+
}
35+
// CHECK: define{{.*}}foo5{{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
36+
37+
pub unsafe extern "C" fn foo6(arg: *mut u8) -> *mut u8 {
38+
arg
39+
}
40+
// CHECK: define{{.*}}foo6{{.*}}!type ![[TYPE6:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
41+
42+
pub unsafe extern "C" fn foo7(arg: *mut i8) -> *mut i8 {
43+
arg
44+
}
45+
// CHECK: define{{.*}}foo7{{.*}}!type ![[TYPE7:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
46+
47+
// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvvE"}
48+
// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFu5nevervE"}
49+
// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFPvS_E"}
50+
// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFPKvS0_E"}
51+
// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFPu2u8S0_E"}
52+
// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFPu2i8S0_E"}

0 commit comments

Comments
 (0)