diff options
| author | bors <bors@rust-lang.org> | 2023-02-19 18:17:26 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-02-19 18:17:26 +0000 |
| commit | 7aa413d59206fd511137728df3d9e0fd377429bd (patch) | |
| tree | a65a0c418211c9e35c42d07245bbf42d5f1469c1 /tests/codegen | |
| parent | dc89a803d64fb6172c8406996831353bee18c3a7 (diff) | |
| parent | 9f6c1df8723504d7d468c87af02670dd0067cc7b (diff) | |
| download | rust-7aa413d59206fd511137728df3d9e0fd377429bd.tar.gz rust-7aa413d59206fd511137728df3d9e0fd377429bd.zip | |
Auto merge of #107921 - cjgillot:codegen-overflow-check, r=tmiasko
Make codegen choose whether to emit overflow checks ConstProp and DataflowConstProp currently have a specific code path not to propagate constants when they overflow. This is meant to have the correct behaviour when inlining from a crate with overflow checks (like `core`) into a crate compiled without. This PR shifts the behaviour change to the `Assert(Overflow*)` MIR terminators: if the crate is compiled without overflow checks, just skip emitting the assertions. This is already what happens with `OverflowNeg`. This allows ConstProp and DataflowConstProp to transform `CheckedBinaryOp(Add, u8::MAX, 1)` into `const (0, true)`, and let codegen ignore the `true`. The interpreter is modified to conform to this behaviour. Fixes #35310
Diffstat (limited to 'tests/codegen')
| -rw-r--r-- | tests/codegen/inherit_overflow.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/codegen/inherit_overflow.rs b/tests/codegen/inherit_overflow.rs new file mode 100644 index 00000000000..0b0b890b2c9 --- /dev/null +++ b/tests/codegen/inherit_overflow.rs @@ -0,0 +1,14 @@ +// compile-flags: -Zmir-enable-passes=+Inline,+ConstProp --crate-type lib +// revisions: ASSERT NOASSERT +//[ASSERT] compile-flags: -Coverflow-checks=on +//[NOASSERT] compile-flags: -Coverflow-checks=off + +// CHECK-LABEL: define{{.*}} @assertion +// ASSERT: call void @_ZN4core9panicking5panic17h +// NOASSERT: ret i8 0 +#[no_mangle] +pub fn assertion() -> u8 { + // Optimized MIR will replace this `CheckedBinaryOp` by `const (0, true)`. + // Verify that codegen does or does not emit the panic. + <u8 as std::ops::Add>::add(255, 1) +} |
