|
1 |
| -// skip-filecheck |
2 | 1 | //@ compile-flags: -O -Zmir-opt-level=2
|
3 | 2 | // EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
4 | 3 |
|
|
8 | 7 | // EMIT_MIR checked_ops.step_forward.PreCodegen.after.mir
|
9 | 8 | pub fn step_forward(x: u16, n: usize) -> u16 {
|
10 | 9 | // This uses `u16` so that the conversion to usize is always widening.
|
| 10 | + |
| 11 | + // CHECK-LABEL: fn step_forward |
| 12 | + // CHECK: inlined{{.+}}forward |
11 | 13 | std::iter::Step::forward(x, n)
|
12 | 14 | }
|
13 | 15 |
|
14 | 16 | // EMIT_MIR checked_ops.checked_shl.PreCodegen.after.mir
|
15 | 17 | pub fn checked_shl(x: u32, rhs: u32) -> Option<u32> {
|
| 18 | + // CHECK-LABEL: fn checked_shl |
| 19 | + // CHECK: [[TEMP:_[0-9]+]] = ShlUnchecked(copy _1, copy _2) |
| 20 | + // CHECK: _0 = Option::<u32>::Some({{move|copy}} [[TEMP]]) |
16 | 21 | x.checked_shl(rhs)
|
17 | 22 | }
|
| 23 | + |
| 24 | +// EMIT_MIR checked_ops.use_checked_sub.PreCodegen.after.mir |
| 25 | +// EMIT_MIR checked_ops.use_checked_sub.GVN.diff |
| 26 | +pub fn use_checked_sub(x: u32, rhs: u32) { |
| 27 | + // We want this to be equivalent to open-coding it, leaving no `Option`s around. |
| 28 | + |
| 29 | + // CHECK-LABEL: fn use_checked_sub |
| 30 | + // FIXME-CHECK-NOT: let{{.+}}Option |
| 31 | + // CHECK: inlined{{.+}}u32{{.+}}checked_sub |
| 32 | + // CHECK: [[DELTA:_[0-9]+]] = SubUnchecked(copy _1, copy _2) |
| 33 | + // FIXME-CHECK: do_something({{move|copy}} [[DELTA]]) |
| 34 | + if let Some(delta) = x.checked_sub(rhs) { |
| 35 | + do_something(delta); |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +unsafe extern "Rust" { |
| 40 | + safe fn do_something(_: u32); |
| 41 | +} |
0 commit comments