Do not assert in op_to_const.

This commit is contained in:
Camille GILLOT 2023-10-31 11:31:08 +00:00
parent 146dafa262
commit c2f49e9edf
2 changed files with 13 additions and 2 deletions

View File

@ -132,8 +132,8 @@ pub(super) fn op_to_const<'tcx>(
// functionality.)
_ => false,
};
let immediate = if force_as_immediate {
Right(ecx.read_immediate(op).expect("normalization works on validated constants"))
let immediate = if force_as_immediate && let Ok(imm) = ecx.read_immediate(op) {
Right(imm)
} else {
op.as_mplace_or_imm()
};

View File

@ -0,0 +1,11 @@
// build-pass
// compile-flags:-Zmir-opt-level=4 --emit=mir
#![feature(allocator_api)]
use std::alloc::{Allocator, Global, Layout};
fn main() {
let layout: Layout = None.unwrap();
let ptr: *mut u8 = Global.allocate(layout).unwrap().as_ptr() as _;
}