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>
This commit is contained in:
parent
e3f90bca50
commit
eddfce53c1
@ -153,9 +153,9 @@ fn reg_component(cls: &[Option<Class>], i: &mut usize, size: Size) -> Option<Reg
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cast_target(cls: &[Option<Class>], size: Size) -> CastTarget {
|
fn cast_target(cls: &[Option<Class>], size: Size) -> Option<CastTarget> {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let lo = reg_component(cls, &mut i, size).unwrap();
|
let lo = reg_component(cls, &mut i, size)?;
|
||||||
let offset = Size::from_bytes(8) * (i as u64);
|
let offset = Size::from_bytes(8) * (i as u64);
|
||||||
let mut target = CastTarget::from(lo);
|
let mut target = CastTarget::from(lo);
|
||||||
if size > offset {
|
if size > offset {
|
||||||
@ -164,7 +164,7 @@ fn cast_target(cls: &[Option<Class>], size: Size) -> CastTarget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert_eq!(reg_component(cls, &mut i, Size::ZERO), None);
|
assert_eq!(reg_component(cls, &mut i, Size::ZERO), None);
|
||||||
target
|
Some(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_INT_REGS: usize = 6; // RDI, RSI, RDX, RCX, R8, R9
|
const MAX_INT_REGS: usize = 6; // RDI, RSI, RDX, RCX, R8, R9
|
||||||
@ -227,7 +227,9 @@ where
|
|||||||
// split into sized chunks passed individually
|
// split into sized chunks passed individually
|
||||||
if arg.layout.is_aggregate() {
|
if arg.layout.is_aggregate() {
|
||||||
let size = arg.layout.size;
|
let size = arg.layout.size;
|
||||||
arg.cast_to(cast_target(cls, size))
|
if let Some(cast_target) = cast_target(cls, size) {
|
||||||
|
arg.cast_to(cast_target);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
arg.extend_integer_width_to(32);
|
arg.extend_integer_width_to(32);
|
||||||
}
|
}
|
||||||
|
8
tests/ui/abi/issue-94223.rs
Normal file
8
tests/ui/abi/issue-94223.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// check-pass
|
||||||
|
#![allow(improper_ctypes_definitions)]
|
||||||
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
|
// Check that computing the fn abi for `bad`, with a external ABI fn ptr that is not FFI-safe, does
|
||||||
|
// not ICE.
|
||||||
|
|
||||||
|
pub fn bad(f: extern "C" fn([u8])) {}
|
Loading…
x
Reference in New Issue
Block a user