diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-11-19 16:26:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-19 16:26:27 +0100 |
| commit | 05ff58e6452bb8db4e2c929dec2419b37d9e45e1 (patch) | |
| tree | e41f24c0a01cc3464010649ece0da01ba975caaf | |
| parent | 552d8c5cb1371c7d3793e8907f9cbc868e509031 (diff) | |
| parent | 2b7ffecee0afedf9254e10b30f5af24498936207 (diff) | |
| download | rust-05ff58e6452bb8db4e2c929dec2419b37d9e45e1.tar.gz rust-05ff58e6452bb8db4e2c929dec2419b37d9e45e1.zip | |
Rollup merge of #79101 - tmiasko:lower-func-type, r=jonas-schievink
Don't special case constant operands when lowering intrinsics
| -rw-r--r-- | compiler/rustc_mir/src/transform/lower_intrinsics.rs | 12 | ||||
| -rw-r--r-- | src/test/mir-opt/lower_intrinsics.non_const.LowerIntrinsics.diff | 31 | ||||
| -rw-r--r-- | src/test/mir-opt/lower_intrinsics.rs | 7 |
3 files changed, 42 insertions, 8 deletions
diff --git a/compiler/rustc_mir/src/transform/lower_intrinsics.rs b/compiler/rustc_mir/src/transform/lower_intrinsics.rs index da937094c41..543acb74acb 100644 --- a/compiler/rustc_mir/src/transform/lower_intrinsics.rs +++ b/compiler/rustc_mir/src/transform/lower_intrinsics.rs @@ -11,15 +11,11 @@ pub struct LowerIntrinsics; impl<'tcx> MirPass<'tcx> for LowerIntrinsics { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - for block in body.basic_blocks_mut() { + let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); + for block in basic_blocks { let terminator = block.terminator.as_mut().unwrap(); - if let TerminatorKind::Call { - func: Operand::Constant(box Constant { literal: ty::Const { ty: func_ty, .. }, .. }), - args, - destination, - .. - } = &mut terminator.kind - { + if let TerminatorKind::Call { func, args, destination, .. } = &mut terminator.kind { + let func_ty = func.ty(local_decls, tcx); let (intrinsic_name, substs) = match resolve_rust_intrinsic(tcx, func_ty) { None => continue, Some(it) => it, diff --git a/src/test/mir-opt/lower_intrinsics.non_const.LowerIntrinsics.diff b/src/test/mir-opt/lower_intrinsics.non_const.LowerIntrinsics.diff new file mode 100644 index 00000000000..e973014c40d --- /dev/null +++ b/src/test/mir-opt/lower_intrinsics.non_const.LowerIntrinsics.diff @@ -0,0 +1,31 @@ +- // MIR for `non_const` before LowerIntrinsics ++ // MIR for `non_const` after LowerIntrinsics + + fn non_const() -> usize { + let mut _0: usize; // return place in scope 0 at $DIR/lower_intrinsics.rs:55:26: 55:31 + let _1: extern "rust-intrinsic" fn() -> usize {std::intrinsics::size_of::<T>}; // in scope 0 at $DIR/lower_intrinsics.rs:57:9: 57:18 + let mut _2: extern "rust-intrinsic" fn() -> usize {std::intrinsics::size_of::<T>}; // in scope 0 at $DIR/lower_intrinsics.rs:58:5: 58:14 + scope 1 { + debug size_of_t => _1; // in scope 1 at $DIR/lower_intrinsics.rs:57:9: 57:18 + } + + bb0: { + StorageLive(_1); // scope 0 at $DIR/lower_intrinsics.rs:57:9: 57:18 + _1 = std::intrinsics::size_of::<T>; // scope 0 at $DIR/lower_intrinsics.rs:57:21: 57:51 + // mir::Constant + // + span: $DIR/lower_intrinsics.rs:57:21: 57:51 + // + literal: Const { ty: extern "rust-intrinsic" fn() -> usize {std::intrinsics::size_of::<T>}, val: Value(Scalar(<ZST>)) } + StorageLive(_2); // scope 1 at $DIR/lower_intrinsics.rs:58:5: 58:14 + _2 = _1; // scope 1 at $DIR/lower_intrinsics.rs:58:5: 58:14 +- _0 = move _2() -> bb1; // scope 1 at $DIR/lower_intrinsics.rs:58:5: 58:16 ++ _0 = SizeOf(T); // scope 1 at $DIR/lower_intrinsics.rs:58:5: 58:16 ++ goto -> bb1; // scope 1 at $DIR/lower_intrinsics.rs:58:5: 58:16 + } + + bb1: { + StorageDead(_2); // scope 1 at $DIR/lower_intrinsics.rs:58:15: 58:16 + StorageDead(_1); // scope 0 at $DIR/lower_intrinsics.rs:59:1: 59:2 + return; // scope 0 at $DIR/lower_intrinsics.rs:59:2: 59:2 + } + } + diff --git a/src/test/mir-opt/lower_intrinsics.rs b/src/test/mir-opt/lower_intrinsics.rs index e08d620c4b1..de5f692b7da 100644 --- a/src/test/mir-opt/lower_intrinsics.rs +++ b/src/test/mir-opt/lower_intrinsics.rs @@ -50,3 +50,10 @@ pub fn f_zst<T>(t: T) { #[inline(never)] pub fn f_non_zst<T>(t: T) {} + +// EMIT_MIR lower_intrinsics.non_const.LowerIntrinsics.diff +pub fn non_const<T>() -> usize { + // Check that lowering works with non-const operand as a func. + let size_of_t = core::intrinsics::size_of::<T>; + size_of_t() +} |
