Skip to content

Commit ac7dd7a

Browse files
committed
Remove unsound-mir-opts for simplify_aggregate_to_copy
1 parent 1787789 commit ac7dd7a

11 files changed

+65
-71
lines changed

Diff for: compiler/rustc_mir_transform/src/gvn.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1098,9 +1098,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
10981098
}
10991099
}
11001100

1101-
// unsound: https://github.com/rust-lang/rust/issues/132353
1102-
if tcx.sess.opts.unstable_opts.unsound_mir_opts
1103-
&& let AggregateTy::Def(_, _) = ty
1101+
if let AggregateTy::Def(_, _) = ty
11041102
&& let Some(value) =
11051103
self.simplify_aggregate_to_copy(rvalue, location, &fields, variant_index)
11061104
{

Diff for: tests/codegen/clone_as_copy.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//@ revisions: DEBUGINFO NODEBUGINFO
2-
//@ compile-flags: -Zunsound-mir-opts
3-
// FIXME: see <https://github.com/rust-lang/rust/issues/132353>
42
//@ compile-flags: -Copt-level=3 -Cno-prepopulate-passes
53
//@ [DEBUGINFO] compile-flags: -Cdebuginfo=full
64

Diff for: tests/codegen/try_question_mark_nop.rs

+24-14
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ use std::ptr::NonNull;
1616
#[no_mangle]
1717
pub fn option_nop_match_32(x: Option<u32>) -> Option<u32> {
1818
// CHECK: start:
19-
// TWENTY-NEXT: %[[IS_SOME:.+]] = trunc nuw i32 %0 to i1
20-
// TWENTY-NEXT: %[[PAYLOAD:.+]] = select i1 %[[IS_SOME]], i32 %1, i32 undef
21-
// CHECK-NEXT: [[REG1:%.*]] = insertvalue { i32, i32 } poison, i32 %0, 0
22-
// NINETEEN-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } [[REG1]], i32 %1, 1
23-
// TWENTY-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } [[REG1]], i32 %[[PAYLOAD]], 1
24-
// CHECK-NEXT: ret { i32, i32 } [[REG2]]
19+
// CHECK-NEXT: [[TRUNC:%.*]] = trunc nuw i32 %0 to i1
20+
21+
// NINETEEN-NEXT: [[SELECT:%.*]] = select i1 [[TRUNC]], i32 %0, i32 0
22+
// NINETEEN-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } poison, i32 [[SELECT]], 0
23+
// NINETEEN-NEXT: [[REG3:%.*]] = insertvalue { i32, i32 } [[REG2]], i32 %1, 1
24+
25+
// TWENTY-NEXT: [[SELECT:%.*]] = select i1 [[TRUNC]], i32 %1, i32 undef
26+
// TWENTY-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } poison, i32 %0, 0
27+
// TWENTY-NEXT: [[REG3:%.*]] = insertvalue { i32, i32 } [[REG2]], i32 [[SELECT]], 1
28+
29+
// CHECK-NEXT: ret { i32, i32 } [[REG3]]
2530
match x {
2631
Some(x) => Some(x),
2732
None => None,
@@ -90,12 +95,17 @@ pub fn control_flow_nop_traits_32(x: ControlFlow<i32, u32>) -> ControlFlow<i32,
9095
#[no_mangle]
9196
pub fn option_nop_match_64(x: Option<u64>) -> Option<u64> {
9297
// CHECK: start:
93-
// TWENTY-NEXT: %[[TRUNC:[0-9]+]] = trunc nuw i64 %0 to i1
94-
// TWENTY-NEXT: %[[SEL:\.[0-9]+]] = select i1 %[[TRUNC]], i64 %1, i64 undef
95-
// CHECK-NEXT: [[REG1:%[0-9a-zA-Z_.]+]] = insertvalue { i64, i64 } poison, i64 %0, 0
96-
// NINETEEN-NEXT: [[REG2:%[0-9a-zA-Z_.]+]] = insertvalue { i64, i64 } [[REG1]], i64 %1, 1
97-
// TWENTY-NEXT: [[REG2:%[0-9a-zA-Z_.]+]] = insertvalue { i64, i64 } [[REG1]], i64 %[[SEL]], 1
98-
// CHECK-NEXT: ret { i64, i64 } [[REG2]]
98+
// CHECK-NEXT: [[TRUNC:%.*]] = trunc nuw i64 %0 to i1
99+
100+
// NINETEEN-NEXT: [[SELECT:%.*]] = select i1 [[TRUNC]], i64 %0, i64 0
101+
// NINETEEN-NEXT: [[REG2:%.*]] = insertvalue { i64, i64 } poison, i64 [[SELECT]], 0
102+
// NINETEEN-NEXT: [[REG3:%.*]] = insertvalue { i64, i64 } [[REG2]], i64 %1, 1
103+
104+
// TWENTY-NEXT: [[SELECT:%.*]] = select i1 [[TRUNC]], i64 %1, i64 undef
105+
// TWENTY-NEXT: [[REG2:%.*]] = insertvalue { i64, i64 } poison, i64 %0, 0
106+
// TWENTY-NEXT: [[REG3:%.*]] = insertvalue { i64, i64 } [[REG2]], i64 [[SELECT]], 1
107+
108+
// CHECK-NEXT: ret { i64, i64 } [[REG3]]
99109
match x {
100110
Some(x) => Some(x),
101111
None => None,
@@ -164,8 +174,8 @@ pub fn control_flow_nop_traits_64(x: ControlFlow<i64, u64>) -> ControlFlow<i64,
164174
#[no_mangle]
165175
pub fn result_nop_match_128(x: Result<i128, u128>) -> Result<i128, u128> {
166176
// CHECK: start:
167-
// CHECK-NEXT: getelementptr inbounds {{(nuw )?}}i8
168177
// CHECK-NEXT: store i128
178+
// CHECK-NEXT: getelementptr inbounds {{(nuw )?}}i8
169179
// CHECK-NEXT: store i128
170180
// CHECK-NEXT: ret void
171181
match x {
@@ -189,8 +199,8 @@ pub fn result_nop_traits_128(x: Result<i128, u128>) -> Result<i128, u128> {
189199
#[no_mangle]
190200
pub fn control_flow_nop_match_128(x: ControlFlow<i128, u128>) -> ControlFlow<i128, u128> {
191201
// CHECK: start:
192-
// CHECK-NEXT: getelementptr inbounds {{(nuw )?}}i8
193202
// CHECK-NEXT: store i128
203+
// CHECK-NEXT: getelementptr inbounds {{(nuw )?}}i8
194204
// CHECK-NEXT: store i128
195205
// CHECK-NEXT: ret void
196206
match x {

Diff for: tests/mir-opt/gvn_clone.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@ compile-flags: -Zunsound-mir-opts
2-
// FIXME: see <https://github.com/rust-lang/rust/issues/132353>
31
//@ test-mir-pass: GVN
42
//@ compile-flags: -Zmir-enable-passes=+InstSimplify-before-inline
53

Diff for: tests/mir-opt/gvn_clone.{impl#0}-clone.GVN.diff

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
- // MIR for `<impl at $DIR/gvn_clone.rs:14:10: 14:15>::clone` before GVN
2-
+ // MIR for `<impl at $DIR/gvn_clone.rs:14:10: 14:15>::clone` after GVN
1+
- // MIR for `<impl at $DIR/gvn_clone.rs:12:10: 12:15>::clone` before GVN
2+
+ // MIR for `<impl at $DIR/gvn_clone.rs:12:10: 12:15>::clone` after GVN
33

4-
fn <impl at $DIR/gvn_clone.rs:14:10: 14:15>::clone(_1: &AllCopy) -> AllCopy {
4+
fn <impl at $DIR/gvn_clone.rs:12:10: 12:15>::clone(_1: &AllCopy) -> AllCopy {
55
debug self => _1;
66
let mut _0: AllCopy;
77
let mut _2: i32;

Diff for: tests/mir-opt/gvn_copy_aggregate.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@ compile-flags: -Zunsound-mir-opts
2-
// FIXME: see <https://github.com/rust-lang/rust/issues/132353.
31
//@ test-mir-pass: GVN
42
//@ compile-flags: -Cpanic=abort
53

Diff for: tests/mir-opt/pre-codegen/clone_as_copy.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@ compile-flags: -Zunsound-mir-opts
2-
// FIXME: see <https://github.com/rust-lang/rust/issues/132353>
31
//@ compile-flags: -Cdebuginfo=full
42

53
// Check if we have transformed the nested clone to the copy in the complete pipeline.

Diff for: tests/mir-opt/pre-codegen/no_inlined_clone.{impl#0}-clone.PreCodegen.after.mir

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
fn <impl at $DIR/no_inlined_clone.rs:9:10: 9:15>::clone(_1: &Foo) -> Foo {
44
debug self => _1;
55
let mut _0: Foo;
6-
let mut _2: i32;
76

87
bb0: {
9-
StorageLive(_2);
10-
_2 = copy ((*_1).0: i32);
11-
_0 = Foo { a: move _2 };
12-
StorageDead(_2);
8+
_0 = copy (*_1);
139
return;
1410
}
1511
}

Diff for: tests/mir-opt/pre-codegen/try_identity.old.PreCodegen.after.mir

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ fn old(_1: Result<T, E>) -> Result<T, E> {
1919
}
2020

2121
bb1: {
22-
_3 = move ((_1 as Ok).0: T);
23-
_0 = Result::<T, E>::Ok(copy _3);
22+
_3 = copy ((_1 as Ok).0: T);
23+
_0 = copy _1;
2424
goto -> bb3;
2525
}
2626

2727
bb2: {
28-
_4 = move ((_1 as Err).0: E);
29-
_0 = Result::<T, E>::Err(copy _4);
28+
_4 = copy ((_1 as Err).0: E);
29+
_0 = copy _1;
3030
goto -> bb3;
3131
}
3232

Diff for: tests/mir-opt/simplify_aggregate_to_copy_miscompile.foo.GVN.diff

+23-31
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,52 @@
66
let mut _0: std::option::Option<i32>;
77
let mut _2: &std::option::Option<i32>;
88
let mut _3: &std::option::Option<i32>;
9-
let _4: &&mut std::option::Option<i32>;
10-
let mut _5: isize;
11-
let mut _7: !;
12-
let mut _8: std::option::Option<i32>;
13-
let mut _9: i32;
14-
let mut _10: !;
15-
let mut _11: &mut std::option::Option<i32>;
9+
let mut _4: isize;
10+
let mut _6: !;
11+
let mut _7: std::option::Option<i32>;
12+
let mut _8: i32;
13+
let mut _9: !;
1614
scope 1 {
17-
debug col => _6;
18-
let _6: i32;
15+
debug col => _5;
16+
let _5: i32;
1917
}
2018

2119
bb0: {
2220
StorageLive(_2);
2321
StorageLive(_3);
24-
StorageLive(_4);
25-
_4 = &_1;
26-
- _11 = deref_copy (*_4);
27-
- _3 = &(*_11);
28-
+ _11 = copy _1;
29-
+ _3 = &(*_1);
22+
_3 = &(*_1);
3023
_2 = get(move _3) -> [return: bb1, unwind unreachable];
3124
}
3225

3326
bb1: {
3427
StorageDead(_3);
35-
_5 = discriminant((*_2));
36-
switchInt(move _5) -> [1: bb2, otherwise: bb3];
28+
_4 = discriminant((*_2));
29+
switchInt(move _4) -> [1: bb2, otherwise: bb3];
3730
}
3831

3932
bb2: {
40-
- StorageLive(_6);
33+
- StorageLive(_5);
4134
+ nop;
42-
_6 = copy (((*_2) as Some).0: i32);
43-
StorageLive(_8);
44-
- _8 = Option::<i32>::None;
45-
- (*_1) = move _8;
46-
+ _8 = const Option::<i32>::None;
35+
_5 = copy (((*_2) as Some).0: i32);
36+
StorageLive(_7);
37+
- _7 = Option::<i32>::None;
38+
- (*_1) = move _7;
39+
+ _7 = const Option::<i32>::None;
4740
+ (*_1) = const Option::<i32>::None;
41+
StorageDead(_7);
42+
StorageLive(_8);
43+
_8 = copy _5;
44+
- _0 = Option::<i32>::Some(move _8);
45+
+ _0 = Option::<i32>::Some(copy _5);
4846
StorageDead(_8);
49-
StorageLive(_9);
50-
_9 = copy _6;
51-
- _0 = Option::<i32>::Some(move _9);
52-
+ _0 = Option::<i32>::Some(copy _6);
53-
StorageDead(_9);
54-
- StorageDead(_6);
47+
- StorageDead(_5);
5548
+ nop;
56-
StorageDead(_4);
5749
StorageDead(_2);
5850
return;
5951
}
6052

6153
bb3: {
62-
StorageLive(_10);
54+
StorageLive(_9);
6355
unreachable;
6456
}
6557
+ }

Diff for: tests/mir-opt/simplify_aggregate_to_copy_miscompile.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@
77
//! This test demonstrates the behavior, and should be adjusted or removed when fixing and relanding
88
//! the mir-opt.
99
#![crate_type = "lib"]
10-
// skip-filecheck
11-
//@ compile-flags: -O -Zunsound-mir-opts
1210
//@ test-mir-pass: GVN
1311
#![allow(internal_features)]
1412
#![feature(rustc_attrs, core_intrinsics)]
1513

1614
// EMIT_MIR simplify_aggregate_to_copy_miscompile.foo.GVN.diff
1715
#[no_mangle]
1816
fn foo(v: &mut Option<i32>) -> Option<i32> {
19-
if let &Some(col) = get(&v) {
17+
// CHECK-LABEL: fn foo(
18+
// CHECK-SAME: [[v:_.*]]: &mut Option<i32>
19+
// CHECK: [[v_alias_1:_.*]] = &(*_1)
20+
// CHECK-NEXT: [[v_alias_2:_.*]] = get(move [[v_alias_1]])
21+
// CHECK: (*[[v]]) = const Option::<i32>::None;
22+
// CHECK-NOT: _0 = copy (*[[v_alias_2]])
23+
// CHECK: _0 = Option::<i32>::Some
24+
// CHECK-NOT: _0 = copy (*[[v_alias_2]])
25+
if let &Some(col) = get(v) {
2026
*v = None;
2127
return Some(col);
2228
} else {

0 commit comments

Comments
 (0)