Skip to content

Commit 2d22063

Browse files
committed
[const-prop] Handle MIR Rvalue::Box
1 parent 4d89031 commit 2d22063

File tree

2 files changed

+57
-18
lines changed

2 files changed

+57
-18
lines changed

src/librustc_mir/transform/const_prop.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc::hir::def::DefKind;
88
use rustc::hir::def_id::DefId;
99
use rustc::mir::{
1010
AggregateKind, Constant, Location, Place, PlaceBase, Body, Operand, Rvalue,
11-
Local, NullOp, UnOp, StatementKind, Statement, LocalKind,
11+
Local, UnOp, StatementKind, Statement, LocalKind,
1212
TerminatorKind, Terminator, ClearCrossCrate, SourceInfo, BinOp,
1313
SourceScope, SourceScopeLocalData, LocalDecl, BasicBlock,
1414
};
@@ -434,23 +434,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
434434
) -> Option<Const<'tcx>> {
435435
let span = source_info.span;
436436

437-
// if this isn't a supported operation, then return None
438-
match rvalue {
439-
Rvalue::NullaryOp(NullOp::Box, _) => return None,
440-
441-
Rvalue::Use(_) |
442-
Rvalue::Len(_) |
443-
Rvalue::Repeat(..) |
444-
Rvalue::Aggregate(..) |
445-
Rvalue::Discriminant(..) |
446-
Rvalue::Cast(..) |
447-
Rvalue::NullaryOp(..) |
448-
Rvalue::CheckedBinaryOp(..) |
449-
Rvalue::Ref(..) |
450-
Rvalue::UnaryOp(..) |
451-
Rvalue::BinaryOp(..) => { }
452-
}
453-
454437
// perform any special checking for specific Rvalue types
455438
if let Rvalue::UnaryOp(op, arg) = rvalue {
456439
trace!("checking UnaryOp(op = {:?}, arg = {:?})", op, arg);

src/test/mir-opt/const_prop/boxes.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// compile-flags: -O
2+
// ignore-emscripten compiled with panic=abort by default
3+
// ignore-wasm32
4+
// ignore-wasm64
5+
6+
#![feature(box_syntax)]
7+
8+
// Note: this test verifies that we, in fact, do not const prop `box`
9+
10+
fn main() {
11+
let x = *(box 42) + 0;
12+
}
13+
14+
// END RUST SOURCE
15+
// START rustc.main.ConstProp.before.mir
16+
// bb0: {
17+
// ...
18+
// _4 = Box(i32);
19+
// (*_4) = const 42i32;
20+
// _3 = move _4;
21+
// ...
22+
// _2 = (*_3);
23+
// _1 = Add(move _2, const 0i32);
24+
// ...
25+
// drop(_3) -> [return: bb2, unwind: bb1];
26+
// }
27+
// bb1 (cleanup): {
28+
// resume;
29+
// }
30+
// bb2: {
31+
// ...
32+
// _0 = ();
33+
// ...
34+
// }
35+
// END rustc.main.ConstProp.before.mir
36+
// START rustc.main.ConstProp.after.mir
37+
// bb0: {
38+
// ...
39+
// _4 = Box(i32);
40+
// (*_4) = const 42i32;
41+
// _3 = move _4;
42+
// ...
43+
// _2 = (*_3);
44+
// _1 = Add(move _2, const 0i32);
45+
// ...
46+
// drop(_3) -> [return: bb2, unwind: bb1];
47+
// }
48+
// bb1 (cleanup): {
49+
// resume;
50+
// }
51+
// bb2: {
52+
// ...
53+
// _0 = ();
54+
// ...
55+
// }
56+
// END rustc.main.ConstProp.after.mir

0 commit comments

Comments
 (0)