about summary refs log tree commit diff
path: root/compiler/rustc_mir/src/transform/const_prop.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-01-12 17:26:56 +0000
committerbors <bors@rust-lang.org>2021-01-12 17:26:56 +0000
commit704e47f78b4c8801a3c76f235a5a152e1b60b300 (patch)
tree867a118a9e4fd8490e80316fd699e8533a2c0815 /compiler/rustc_mir/src/transform/const_prop.rs
parent497c9a256b1c2961e91565ccc6e0dd3a87a031ed (diff)
parent53e3a23572b599844653fe8f4add4a02966dcd9b (diff)
Auto merge of #78407 - oli-obk:ub_checkable_ctfe, r=RalfJung,pnkfelix
Make CTFE able to check for UB...

... by not doing any optimizations on the `const fn` MIR used in CTFE. This means we duplicate all `const fn`'s MIR now, once for CTFE, once for runtime. This PR is for checking the perf effect, so we have some data when talking about https://github.com/rust-lang/const-eval/blob/master/rfcs/0000-const-ub.md

To do this, we now have two queries for obtaining mir: `optimized_mir` and `mir_for_ctfe`. It is now illegal to invoke `optimized_mir` to obtain the MIR of a const/static item's initializer, an array length, an inline const expression or an enum discriminant initializer. For `const fn`, both `optimized_mir` and `mir_for_ctfe` work, the former returning the MIR that LLVM should use if the function is called at runtime. Similarly it is illegal to invoke `mir_for_ctfe` on regular functions.

This is all checked via appropriate assertions and I don't think it is easy to get wrong, as there should be no `mir_for_ctfe` calls outside the const evaluator or metadata encoding. Almost all rustc devs should keep using `optimized_mir` (or `instance_mir` for that matter).
Diffstat (limited to 'compiler/rustc_mir/src/transform/const_prop.rs')
-rw-r--r--compiler/rustc_mir/src/transform/const_prop.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs
index 2d6d0adf3bc..a311e262dd4 100644
--- a/compiler/rustc_mir/src/transform/const_prop.rs
+++ b/compiler/rustc_mir/src/transform/const_prop.rs
@@ -185,6 +185,13 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
 
     type MemoryExtra = ();
 
+    fn load_mir(
+        _ecx: &InterpCx<'mir, 'tcx, Self>,
+        _instance: ty::InstanceDef<'tcx>,
+    ) -> InterpResult<'tcx, &'tcx Body<'tcx>> {
+        throw_machine_stop_str!("calling functions isn't supported in ConstProp")
+    }
+
     fn find_mir_or_eval_fn(
         _ecx: &mut InterpCx<'mir, 'tcx, Self>,
         _instance: ty::Instance<'tcx>,