Skip to content

Commit eddfce5

Browse files
committedJul 3, 2023
abi: avoid ice for non-ffi-safe fn ptrs
Remove an `unwrap` that assumed FFI-safe types in foreign fn-ptr types. Signed-off-by: David Wood <david.wood@huawei.com>
1 parent e3f90bc commit eddfce5

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed
 

‎compiler/rustc_target/src/abi/call/x86_64.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ fn reg_component(cls: &[Option<Class>], i: &mut usize, size: Size) -> Option<Reg
153153
}
154154
}
155155

156-
fn cast_target(cls: &[Option<Class>], size: Size) -> CastTarget {
156+
fn cast_target(cls: &[Option<Class>], size: Size) -> Option<CastTarget> {
157157
let mut i = 0;
158-
let lo = reg_component(cls, &mut i, size).unwrap();
158+
let lo = reg_component(cls, &mut i, size)?;
159159
let offset = Size::from_bytes(8) * (i as u64);
160160
let mut target = CastTarget::from(lo);
161161
if size > offset {
@@ -164,7 +164,7 @@ fn cast_target(cls: &[Option<Class>], size: Size) -> CastTarget {
164164
}
165165
}
166166
assert_eq!(reg_component(cls, &mut i, Size::ZERO), None);
167-
target
167+
Some(target)
168168
}
169169

170170
const MAX_INT_REGS: usize = 6; // RDI, RSI, RDX, RCX, R8, R9
@@ -227,7 +227,9 @@ where
227227
// split into sized chunks passed individually
228228
if arg.layout.is_aggregate() {
229229
let size = arg.layout.size;
230-
arg.cast_to(cast_target(cls, size))
230+
if let Some(cast_target) = cast_target(cls, size) {
231+
arg.cast_to(cast_target);
232+
}
231233
} else {
232234
arg.extend_integer_width_to(32);
233235
}

‎tests/ui/abi/issue-94223.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// check-pass
2+
#![allow(improper_ctypes_definitions)]
3+
#![crate_type = "lib"]
4+
5+
// Check that computing the fn abi for `bad`, with a external ABI fn ptr that is not FFI-safe, does
6+
// not ICE.
7+
8+
pub fn bad(f: extern "C" fn([u8])) {}

0 commit comments

Comments
 (0)
Please sign in to comment.