1 //! Handling of `static`s, `const`s and promoted allocations
2
3 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
4 use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
5 use rustc_middle::mir::interpret::{
6 read_target_uint, AllocId, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar,
7 };
8
9 use cranelift_module::*;
10
11 use crate::prelude::*;
12
13 pub(crate) struct ConstantCx {
14 todo: Vec<TodoItem>,
15 done: FxHashSet<DataId>,
16 anon_allocs: FxHashMap<AllocId, DataId>,
17 }
18
19 #[derive(Copy, Clone, Debug)]
20 enum TodoItem {
21 Alloc(AllocId),
22 Static(DefId),
23 }
24
25 impl ConstantCx {
new() -> Self26 pub(crate) fn new() -> Self {
27 ConstantCx { todo: vec![], done: FxHashSet::default(), anon_allocs: FxHashMap::default() }
28 }
29
finalize(mut self, tcx: TyCtxt<'_>, module: &mut dyn Module)30 pub(crate) fn finalize(mut self, tcx: TyCtxt<'_>, module: &mut dyn Module) {
31 define_all_allocs(tcx, module, &mut self);
32 self.done.clear();
33 }
34 }
35
check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool36 pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
37 let mut all_constants_ok = true;
38 for constant in &fx.mir.required_consts {
39 if eval_mir_constant(fx, constant).is_none() {
40 all_constants_ok = false;
41 }
42 }
43 all_constants_ok
44 }
45
codegen_static(tcx: TyCtxt<'_>, module: &mut dyn Module, def_id: DefId)46 pub(crate) fn codegen_static(tcx: TyCtxt<'_>, module: &mut dyn Module, def_id: DefId) {
47 let mut constants_cx = ConstantCx::new();
48 constants_cx.todo.push(TodoItem::Static(def_id));
49 constants_cx.finalize(tcx, module);
50 }
51
codegen_tls_ref<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, def_id: DefId, layout: TyAndLayout<'tcx>, ) -> CValue<'tcx>52 pub(crate) fn codegen_tls_ref<'tcx>(
53 fx: &mut FunctionCx<'_, '_, 'tcx>,
54 def_id: DefId,
55 layout: TyAndLayout<'tcx>,
56 ) -> CValue<'tcx> {
57 let tls_ptr = if !def_id.is_local() && fx.tcx.needs_thread_local_shim(def_id) {
58 let instance = ty::Instance {
59 def: ty::InstanceDef::ThreadLocalShim(def_id),
60 substs: ty::InternalSubsts::empty(),
61 };
62 let func_ref = fx.get_function_ref(instance);
63 let call = fx.bcx.ins().call(func_ref, &[]);
64 fx.bcx.func.dfg.first_result(call)
65 } else {
66 let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false);
67 let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
68 if fx.clif_comments.enabled() {
69 fx.add_comment(local_data_id, format!("tls {:?}", def_id));
70 }
71 fx.bcx.ins().tls_value(fx.pointer_type, local_data_id)
72 };
73 CValue::by_val(tls_ptr, layout)
74 }
75
eval_mir_constant<'tcx>( fx: &FunctionCx<'_, '_, 'tcx>, constant: &Constant<'tcx>, ) -> Option<(ConstValue<'tcx>, Ty<'tcx>)>76 pub(crate) fn eval_mir_constant<'tcx>(
77 fx: &FunctionCx<'_, '_, 'tcx>,
78 constant: &Constant<'tcx>,
79 ) -> Option<(ConstValue<'tcx>, Ty<'tcx>)> {
80 let constant_kind = fx.monomorphize(constant.literal);
81 let uv = match constant_kind {
82 ConstantKind::Ty(const_) => match const_.kind() {
83 ty::ConstKind::Unevaluated(uv) => uv.expand(),
84 ty::ConstKind::Value(val) => {
85 return Some((fx.tcx.valtree_to_const_val((const_.ty(), val)), const_.ty()));
86 }
87 err => span_bug!(
88 constant.span,
89 "encountered bad ConstKind after monomorphizing: {:?}",
90 err
91 ),
92 },
93 ConstantKind::Unevaluated(mir::UnevaluatedConst { def, .. }, _)
94 if fx.tcx.is_static(def) =>
95 {
96 span_bug!(constant.span, "MIR constant refers to static");
97 }
98 ConstantKind::Unevaluated(uv, _) => uv,
99 ConstantKind::Val(val, _) => return Some((val, constant_kind.ty())),
100 };
101
102 let val = fx
103 .tcx
104 .const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None)
105 .map_err(|err| match err {
106 ErrorHandled::Reported(_) => {
107 fx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
108 }
109 ErrorHandled::TooGeneric => {
110 span_bug!(constant.span, "codegen encountered polymorphic constant: {:?}", err);
111 }
112 })
113 .ok();
114 val.map(|val| (val, constant_kind.ty()))
115 }
116
codegen_constant_operand<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, constant: &Constant<'tcx>, ) -> CValue<'tcx>117 pub(crate) fn codegen_constant_operand<'tcx>(
118 fx: &mut FunctionCx<'_, '_, 'tcx>,
119 constant: &Constant<'tcx>,
120 ) -> CValue<'tcx> {
121 let (const_val, ty) = eval_mir_constant(fx, constant).unwrap_or_else(|| {
122 span_bug!(constant.span, "erroneous constant not captured by required_consts")
123 });
124
125 codegen_const_value(fx, const_val, ty)
126 }
127
codegen_const_value<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, const_val: ConstValue<'tcx>, ty: Ty<'tcx>, ) -> CValue<'tcx>128 pub(crate) fn codegen_const_value<'tcx>(
129 fx: &mut FunctionCx<'_, '_, 'tcx>,
130 const_val: ConstValue<'tcx>,
131 ty: Ty<'tcx>,
132 ) -> CValue<'tcx> {
133 let layout = fx.layout_of(ty);
134 assert!(layout.is_sized(), "unsized const value");
135
136 if layout.is_zst() {
137 return CValue::by_ref(crate::Pointer::dangling(layout.align.pref), layout);
138 }
139
140 match const_val {
141 ConstValue::ZeroSized => unreachable!(), // we already handles ZST above
142 ConstValue::Scalar(x) => match x {
143 Scalar::Int(int) => {
144 if fx.clif_type(layout.ty).is_some() {
145 return CValue::const_val(fx, layout, int);
146 } else {
147 let raw_val = int.to_bits(int.size()).unwrap();
148 let val = match int.size().bytes() {
149 1 => fx.bcx.ins().iconst(types::I8, raw_val as i64),
150 2 => fx.bcx.ins().iconst(types::I16, raw_val as i64),
151 4 => fx.bcx.ins().iconst(types::I32, raw_val as i64),
152 8 => fx.bcx.ins().iconst(types::I64, raw_val as i64),
153 16 => {
154 let lsb = fx.bcx.ins().iconst(types::I64, raw_val as u64 as i64);
155 let msb =
156 fx.bcx.ins().iconst(types::I64, (raw_val >> 64) as u64 as i64);
157 fx.bcx.ins().iconcat(lsb, msb)
158 }
159 _ => unreachable!(),
160 };
161
162 // FIXME avoid this extra copy to the stack and directly write to the final
163 // destination
164 let place = CPlace::new_stack_slot(fx, layout);
165 place.to_ptr().store(fx, val, MemFlags::trusted());
166 place.to_cvalue(fx)
167 }
168 }
169 Scalar::Ptr(ptr, _size) => {
170 let (alloc_id, offset) = ptr.into_parts(); // we know the `offset` is relative
171 let base_addr = match fx.tcx.global_alloc(alloc_id) {
172 GlobalAlloc::Memory(alloc) => {
173 let data_id = data_id_for_alloc_id(
174 &mut fx.constants_cx,
175 fx.module,
176 alloc_id,
177 alloc.inner().mutability,
178 );
179 let local_data_id =
180 fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
181 if fx.clif_comments.enabled() {
182 fx.add_comment(local_data_id, format!("{:?}", alloc_id));
183 }
184 fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
185 }
186 GlobalAlloc::Function(instance) => {
187 let func_id = crate::abi::import_function(fx.tcx, fx.module, instance);
188 let local_func_id =
189 fx.module.declare_func_in_func(func_id, &mut fx.bcx.func);
190 fx.bcx.ins().func_addr(fx.pointer_type, local_func_id)
191 }
192 GlobalAlloc::VTable(ty, trait_ref) => {
193 let alloc_id = fx.tcx.vtable_allocation((ty, trait_ref));
194 let alloc = fx.tcx.global_alloc(alloc_id).unwrap_memory();
195 // FIXME: factor this common code with the `Memory` arm into a function?
196 let data_id = data_id_for_alloc_id(
197 &mut fx.constants_cx,
198 fx.module,
199 alloc_id,
200 alloc.inner().mutability,
201 );
202 let local_data_id =
203 fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
204 fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
205 }
206 GlobalAlloc::Static(def_id) => {
207 assert!(fx.tcx.is_static(def_id));
208 let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false);
209 let local_data_id =
210 fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
211 if fx.clif_comments.enabled() {
212 fx.add_comment(local_data_id, format!("{:?}", def_id));
213 }
214 fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
215 }
216 };
217 let val = if offset.bytes() != 0 {
218 fx.bcx.ins().iadd_imm(base_addr, i64::try_from(offset.bytes()).unwrap())
219 } else {
220 base_addr
221 };
222 CValue::by_val(val, layout)
223 }
224 },
225 ConstValue::ByRef { alloc, offset } => CValue::by_ref(
226 pointer_for_allocation(fx, alloc)
227 .offset_i64(fx, i64::try_from(offset.bytes()).unwrap()),
228 layout,
229 ),
230 ConstValue::Slice { data, start, end } => {
231 let ptr = pointer_for_allocation(fx, data)
232 .offset_i64(fx, i64::try_from(start).unwrap())
233 .get_addr(fx);
234 let len = fx
235 .bcx
236 .ins()
237 .iconst(fx.pointer_type, i64::try_from(end.checked_sub(start).unwrap()).unwrap());
238 CValue::by_val_pair(ptr, len, layout)
239 }
240 }
241 }
242
pointer_for_allocation<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, alloc: ConstAllocation<'tcx>, ) -> crate::pointer::Pointer243 fn pointer_for_allocation<'tcx>(
244 fx: &mut FunctionCx<'_, '_, 'tcx>,
245 alloc: ConstAllocation<'tcx>,
246 ) -> crate::pointer::Pointer {
247 let alloc_id = fx.tcx.create_memory_alloc(alloc);
248 let data_id = data_id_for_alloc_id(
249 &mut fx.constants_cx,
250 &mut *fx.module,
251 alloc_id,
252 alloc.inner().mutability,
253 );
254
255 let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
256 if fx.clif_comments.enabled() {
257 fx.add_comment(local_data_id, format!("{:?}", alloc_id));
258 }
259 let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
260 crate::pointer::Pointer::new(global_ptr)
261 }
262
data_id_for_alloc_id( cx: &mut ConstantCx, module: &mut dyn Module, alloc_id: AllocId, mutability: rustc_hir::Mutability, ) -> DataId263 pub(crate) fn data_id_for_alloc_id(
264 cx: &mut ConstantCx,
265 module: &mut dyn Module,
266 alloc_id: AllocId,
267 mutability: rustc_hir::Mutability,
268 ) -> DataId {
269 cx.todo.push(TodoItem::Alloc(alloc_id));
270 *cx.anon_allocs
271 .entry(alloc_id)
272 .or_insert_with(|| module.declare_anonymous_data(mutability.is_mut(), false).unwrap())
273 }
274
data_id_for_static( tcx: TyCtxt<'_>, module: &mut dyn Module, def_id: DefId, definition: bool, ) -> DataId275 fn data_id_for_static(
276 tcx: TyCtxt<'_>,
277 module: &mut dyn Module,
278 def_id: DefId,
279 definition: bool,
280 ) -> DataId {
281 let attrs = tcx.codegen_fn_attrs(def_id);
282
283 let instance = Instance::mono(tcx, def_id).polymorphize(tcx);
284 let symbol_name = tcx.symbol_name(instance).name;
285 let ty = instance.ty(tcx, ParamEnv::reveal_all());
286 let is_mutable = if tcx.is_mutable_static(def_id) {
287 true
288 } else {
289 !ty.is_freeze(tcx, ParamEnv::reveal_all())
290 };
291 let align = tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap().align.pref.bytes();
292
293 if let Some(import_linkage) = attrs.import_linkage {
294 assert!(!definition);
295
296 let linkage = if import_linkage == rustc_middle::mir::mono::Linkage::ExternalWeak
297 || import_linkage == rustc_middle::mir::mono::Linkage::WeakAny
298 {
299 Linkage::Preemptible
300 } else {
301 Linkage::Import
302 };
303
304 let data_id = match module.declare_data(
305 symbol_name,
306 linkage,
307 is_mutable,
308 attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL),
309 ) {
310 Ok(data_id) => data_id,
311 Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(format!(
312 "attempt to declare `{symbol_name}` as static, but it was already declared as function"
313 )),
314 Err(err) => Err::<_, _>(err).unwrap(),
315 };
316
317 // Comment copied from https://github.com/rust-lang/rust/blob/45060c2a66dfd667f88bd8b94261b28a58d85bd5/src/librustc_codegen_llvm/consts.rs#L141
318 // Declare an internal global `extern_with_linkage_foo` which
319 // is initialized with the address of `foo`. If `foo` is
320 // discarded during linking (for example, if `foo` has weak
321 // linkage and there are no definitions), then
322 // `extern_with_linkage_foo` will instead be initialized to
323 // zero.
324
325 let ref_name = format!("_rust_extern_with_linkage_{}", symbol_name);
326 let ref_data_id = module.declare_data(&ref_name, Linkage::Local, false, false).unwrap();
327 let mut data = DataDescription::new();
328 data.set_align(align);
329 let data_gv = module.declare_data_in_data(data_id, &mut data);
330 data.define(std::iter::repeat(0).take(pointer_ty(tcx).bytes() as usize).collect());
331 data.write_data_addr(0, data_gv, 0);
332 match module.define_data(ref_data_id, &data) {
333 // Every time the static is referenced there will be another definition of this global,
334 // so duplicate definitions are expected and allowed.
335 Err(ModuleError::DuplicateDefinition(_)) => {}
336 res => res.unwrap(),
337 }
338
339 return ref_data_id;
340 }
341
342 let linkage = if definition {
343 crate::linkage::get_static_linkage(tcx, def_id)
344 } else if attrs.linkage == Some(rustc_middle::mir::mono::Linkage::ExternalWeak)
345 || attrs.linkage == Some(rustc_middle::mir::mono::Linkage::WeakAny)
346 {
347 Linkage::Preemptible
348 } else {
349 Linkage::Import
350 };
351
352 let data_id = match module.declare_data(
353 symbol_name,
354 linkage,
355 is_mutable,
356 attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL),
357 ) {
358 Ok(data_id) => data_id,
359 Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(format!(
360 "attempt to declare `{symbol_name}` as static, but it was already declared as function"
361 )),
362 Err(err) => Err::<_, _>(err).unwrap(),
363 };
364
365 data_id
366 }
367
define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut ConstantCx)368 fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut ConstantCx) {
369 while let Some(todo_item) = cx.todo.pop() {
370 let (data_id, alloc, section_name) = match todo_item {
371 TodoItem::Alloc(alloc_id) => {
372 let alloc = match tcx.global_alloc(alloc_id) {
373 GlobalAlloc::Memory(alloc) => alloc,
374 GlobalAlloc::Function(_) | GlobalAlloc::Static(_) | GlobalAlloc::VTable(..) => {
375 unreachable!()
376 }
377 };
378 let data_id = *cx.anon_allocs.entry(alloc_id).or_insert_with(|| {
379 module.declare_anonymous_data(alloc.inner().mutability.is_mut(), false).unwrap()
380 });
381 (data_id, alloc, None)
382 }
383 TodoItem::Static(def_id) => {
384 let section_name = tcx.codegen_fn_attrs(def_id).link_section;
385
386 let alloc = tcx.eval_static_initializer(def_id).unwrap();
387
388 let data_id = data_id_for_static(tcx, module, def_id, true);
389 (data_id, alloc, section_name)
390 }
391 };
392
393 if cx.done.contains(&data_id) {
394 continue;
395 }
396
397 let mut data = DataDescription::new();
398 let alloc = alloc.inner();
399 data.set_align(alloc.align.bytes());
400
401 if let Some(section_name) = section_name {
402 let (segment_name, section_name) = if tcx.sess.target.is_like_osx {
403 let section_name = section_name.as_str();
404 if let Some(names) = section_name.split_once(',') {
405 names
406 } else {
407 tcx.sess.fatal(format!(
408 "#[link_section = \"{}\"] is not valid for macos target: must be segment and section separated by comma",
409 section_name
410 ));
411 }
412 } else {
413 ("", section_name.as_str())
414 };
415 data.set_segment_section(segment_name, section_name);
416 }
417
418 let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()).to_vec();
419 data.define(bytes.into_boxed_slice());
420
421 for &(offset, alloc_id) in alloc.provenance().ptrs().iter() {
422 let addend = {
423 let endianness = tcx.data_layout.endian;
424 let offset = offset.bytes() as usize;
425 let ptr_size = tcx.data_layout.pointer_size;
426 let bytes = &alloc.inspect_with_uninit_and_ptr_outside_interpreter(
427 offset..offset + ptr_size.bytes() as usize,
428 );
429 read_target_uint(endianness, bytes).unwrap()
430 };
431
432 let reloc_target_alloc = tcx.global_alloc(alloc_id);
433 let data_id = match reloc_target_alloc {
434 GlobalAlloc::Function(instance) => {
435 assert_eq!(addend, 0);
436 let func_id =
437 crate::abi::import_function(tcx, module, instance.polymorphize(tcx));
438 let local_func_id = module.declare_func_in_data(func_id, &mut data);
439 data.write_function_addr(offset.bytes() as u32, local_func_id);
440 continue;
441 }
442 GlobalAlloc::Memory(target_alloc) => {
443 data_id_for_alloc_id(cx, module, alloc_id, target_alloc.inner().mutability)
444 }
445 GlobalAlloc::VTable(ty, trait_ref) => {
446 let alloc_id = tcx.vtable_allocation((ty, trait_ref));
447 data_id_for_alloc_id(cx, module, alloc_id, Mutability::Not)
448 }
449 GlobalAlloc::Static(def_id) => {
450 if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL)
451 {
452 tcx.sess.fatal(format!(
453 "Allocation {:?} contains reference to TLS value {:?}",
454 alloc_id, def_id
455 ));
456 }
457
458 // Don't push a `TodoItem::Static` here, as it will cause statics used by
459 // multiple crates to be duplicated between them. It isn't necessary anyway,
460 // as it will get pushed by `codegen_static` when necessary.
461 data_id_for_static(tcx, module, def_id, false)
462 }
463 };
464
465 let global_value = module.declare_data_in_data(data_id, &mut data);
466 data.write_data_addr(offset.bytes() as u32, global_value, addend as i64);
467 }
468
469 module.define_data(data_id, &data).unwrap();
470 cx.done.insert(data_id);
471 }
472
473 assert!(cx.todo.is_empty(), "{:?}", cx.todo);
474 }
475
476 /// Used only for intrinsic implementations that need a compile-time constant
mir_operand_get_const_val<'tcx>( fx: &FunctionCx<'_, '_, 'tcx>, operand: &Operand<'tcx>, ) -> Option<ConstValue<'tcx>>477 pub(crate) fn mir_operand_get_const_val<'tcx>(
478 fx: &FunctionCx<'_, '_, 'tcx>,
479 operand: &Operand<'tcx>,
480 ) -> Option<ConstValue<'tcx>> {
481 match operand {
482 Operand::Constant(const_) => Some(eval_mir_constant(fx, const_).unwrap().0),
483 // FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored
484 // inside a temporary before being passed to the intrinsic requiring the const argument.
485 // This code tries to find a single constant defining definition of the referenced local.
486 Operand::Copy(place) | Operand::Move(place) => {
487 if !place.projection.is_empty() {
488 return None;
489 }
490 let mut computed_const_val = None;
491 for bb_data in fx.mir.basic_blocks.iter() {
492 for stmt in &bb_data.statements {
493 match &stmt.kind {
494 StatementKind::Assign(local_and_rvalue) if &local_and_rvalue.0 == place => {
495 match &local_and_rvalue.1 {
496 Rvalue::Cast(
497 CastKind::IntToInt
498 | CastKind::FloatToFloat
499 | CastKind::FloatToInt
500 | CastKind::IntToFloat
501 | CastKind::FnPtrToPtr
502 | CastKind::PtrToPtr,
503 operand,
504 ty,
505 ) => {
506 if computed_const_val.is_some() {
507 return None; // local assigned twice
508 }
509 if !matches!(ty.kind(), ty::Uint(_) | ty::Int(_)) {
510 return None;
511 }
512 let const_val = mir_operand_get_const_val(fx, operand)?;
513 if fx.layout_of(*ty).size
514 != const_val.try_to_scalar_int()?.size()
515 {
516 return None;
517 }
518 computed_const_val = Some(const_val);
519 }
520 Rvalue::Use(operand) => {
521 computed_const_val = mir_operand_get_const_val(fx, operand)
522 }
523 _ => return None,
524 }
525 }
526 StatementKind::SetDiscriminant { place: stmt_place, variant_index: _ }
527 if &**stmt_place == place =>
528 {
529 return None;
530 }
531 StatementKind::Intrinsic(ref intrinsic) => match **intrinsic {
532 NonDivergingIntrinsic::CopyNonOverlapping(..) => return None,
533 NonDivergingIntrinsic::Assume(..) => {}
534 },
535 // conservative handling
536 StatementKind::Assign(_)
537 | StatementKind::FakeRead(_)
538 | StatementKind::SetDiscriminant { .. }
539 | StatementKind::Deinit(_)
540 | StatementKind::StorageLive(_)
541 | StatementKind::StorageDead(_)
542 | StatementKind::Retag(_, _)
543 | StatementKind::AscribeUserType(_, _)
544 | StatementKind::PlaceMention(..)
545 | StatementKind::Coverage(_)
546 | StatementKind::ConstEvalCounter
547 | StatementKind::Nop => {}
548 }
549 }
550 match &bb_data.terminator().kind {
551 TerminatorKind::Goto { .. }
552 | TerminatorKind::SwitchInt { .. }
553 | TerminatorKind::Resume
554 | TerminatorKind::Terminate
555 | TerminatorKind::Return
556 | TerminatorKind::Unreachable
557 | TerminatorKind::Drop { .. }
558 | TerminatorKind::Assert { .. } => {}
559 TerminatorKind::Yield { .. }
560 | TerminatorKind::GeneratorDrop
561 | TerminatorKind::FalseEdge { .. }
562 | TerminatorKind::FalseUnwind { .. } => unreachable!(),
563 TerminatorKind::InlineAsm { .. } => return None,
564 TerminatorKind::Call { destination, target: Some(_), .. }
565 if destination == place =>
566 {
567 return None;
568 }
569 TerminatorKind::Call { .. } => {}
570 }
571 }
572 computed_const_val
573 }
574 }
575 }
576