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