mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 06:22:00 +00:00
Rollup merge of #121039 - cjgillot:gvn-adjust, r=compiler-errors
Correctly compute adjustment casts in GVN Fixes https://github.com/rust-lang/rust/issues/120925 r? `@oli-obk`
This commit is contained in:
commit
93bc34073e
@ -561,9 +561,14 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
||||
.ok()?;
|
||||
dest.into()
|
||||
}
|
||||
CastKind::FnPtrToPtr
|
||||
| CastKind::PtrToPtr
|
||||
| CastKind::PointerCoercion(
|
||||
CastKind::FnPtrToPtr | CastKind::PtrToPtr => {
|
||||
let src = self.evaluated[value].as_ref()?;
|
||||
let src = self.ecx.read_immediate(src).ok()?;
|
||||
let to = self.ecx.layout_of(to).ok()?;
|
||||
let ret = self.ecx.ptr_to_ptr(&src, to).ok()?;
|
||||
ret.into()
|
||||
}
|
||||
CastKind::PointerCoercion(
|
||||
ty::adjustment::PointerCoercion::MutToConstPointer
|
||||
| ty::adjustment::PointerCoercion::ArrayToPointer
|
||||
| ty::adjustment::PointerCoercion::UnsafeFnPointer,
|
||||
@ -571,8 +576,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
||||
let src = self.evaluated[value].as_ref()?;
|
||||
let src = self.ecx.read_immediate(src).ok()?;
|
||||
let to = self.ecx.layout_of(to).ok()?;
|
||||
let ret = self.ecx.ptr_to_ptr(&src, to).ok()?;
|
||||
ret.into()
|
||||
ImmTy::from_immediate(*src, to).into()
|
||||
}
|
||||
_ => return None,
|
||||
},
|
||||
|
25
tests/mir-opt/issue_120925_unsafefncast.rs
Normal file
25
tests/mir-opt/issue_120925_unsafefncast.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// Verify that we do not ICE when attempting to interpret casts between fn types.
|
||||
// skip-filecheck
|
||||
|
||||
static FOO: fn() = || assert_ne!(42, 43);
|
||||
static BAR: fn(i32, i32) = |a, b| assert_ne!(a, b);
|
||||
|
||||
fn main() {
|
||||
FOO();
|
||||
|
||||
let bar: unsafe fn(i32, i32) = BAR;
|
||||
|
||||
let f: fn() = || {};
|
||||
f();
|
||||
|
||||
f();
|
||||
|
||||
f();
|
||||
|
||||
let g: fn(i32) = |i| assert_eq!(i, 2);
|
||||
g(2);
|
||||
|
||||
g(2);
|
||||
|
||||
g(2);
|
||||
}
|
Loading…
Reference in New Issue
Block a user