Skip to content

Commit 5680fa1

Browse files
committed
Auto merge of #115140 - wesleywiser:turn_off_mir_sroa, r=cuviper
Disable MIR SROA optimization by default Turn off the MIR SROA optimization by default to prevent incorrect debuginfo generation and rustc ICEs caused by invalid LLVM IR being created. Related to #115113 r? `@cuviper` cc `@saethlin`
2 parents f155f8c + 298ec52 commit 5680fa1

17 files changed

+293
-213
lines changed

compiler/rustc_mir_transform/src/sroa.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct ScalarReplacementOfAggregates;
1212

1313
impl<'tcx> MirPass<'tcx> for ScalarReplacementOfAggregates {
1414
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
15-
sess.mir_opt_level() >= 2
15+
sess.mir_opt_level() >= 3
1616
}
1717

1818
#[instrument(level = "debug", skip(self, tcx, body))]

tests/incremental/hashes/match_expressions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub fn change_mutability_of_binding_in_pattern(x: u32) -> u32 {
227227

228228
// Ignore optimized_mir in cfail2, the only change to optimized MIR is a span.
229229
#[cfg(not(any(cfail1,cfail4)))]
230-
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,typeck")]
230+
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck")]
231231
#[rustc_clean(cfg="cfail3")]
232232
#[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir,typeck")]
233233
#[rustc_clean(cfg="cfail6")]

tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-abort.diff

+38-32
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,37 @@
3333
+ debug ptr => _11;
3434
+ scope 18 (inlined NonNull::<[u8]>::as_mut_ptr) {
3535
+ debug self => _11;
36-
+ let mut _15: std::ptr::NonNull<u8>;
36+
+ let mut _16: std::ptr::NonNull<u8>;
3737
+ scope 19 (inlined NonNull::<[u8]>::as_non_null_ptr) {
3838
+ debug self => _11;
39-
+ let mut _16: *mut u8;
40-
+ let mut _17: *mut [u8];
39+
+ let mut _17: *mut u8;
40+
+ let mut _18: *mut [u8];
4141
+ scope 20 {
4242
+ scope 21 (inlined NonNull::<[u8]>::as_ptr) {
4343
+ debug self => _11;
44-
+ let mut _18: *const [u8];
44+
+ let mut _19: *const [u8];
4545
+ }
4646
+ scope 22 (inlined ptr::mut_ptr::<impl *mut [u8]>::as_mut_ptr) {
47-
+ debug self => _17;
47+
+ debug self => _18;
4848
+ }
4949
+ scope 23 (inlined NonNull::<u8>::new_unchecked) {
50-
+ debug ptr => _16;
51-
+ let mut _19: *const u8;
50+
+ debug ptr => _17;
51+
+ let mut _20: *const u8;
52+
+ let mut _21: *mut u8;
5253
+ scope 24 {
5354
+ scope 25 (inlined NonNull::<T>::new_unchecked::runtime::<u8>) {
54-
+ debug ptr => _16;
55+
+ debug ptr => _21;
5556
+ scope 26 (inlined ptr::mut_ptr::<impl *mut u8>::is_null) {
56-
+ debug self => _16;
57-
+ let mut _20: *mut u8;
57+
+ debug self => _21;
58+
+ let mut _22: *mut u8;
5859
+ scope 27 {
5960
+ scope 28 (inlined ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
60-
+ debug ptr => _20;
61+
+ debug ptr => _22;
6162
+ scope 29 (inlined ptr::mut_ptr::<impl *mut u8>::addr) {
62-
+ debug self => _20;
63+
+ debug self => _22;
6364
+ scope 30 {
6465
+ scope 31 (inlined ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
65-
+ debug self => _20;
66+
+ debug self => _22;
6667
+ }
6768
+ }
6869
+ }
@@ -75,8 +76,8 @@
7576
+ }
7677
+ }
7778
+ scope 32 (inlined NonNull::<u8>::as_ptr) {
78-
+ debug self => _15;
79-
+ let mut _21: *const u8;
79+
+ debug self => _16;
80+
+ let mut _23: *const u8;
8081
+ }
8182
+ }
8283
+ }
@@ -93,13 +94,14 @@
9394
+ scope 10 {
9495
+ scope 11 (inlined std::ptr::Alignment::new_unchecked) {
9596
+ debug align => _5;
97+
+ let mut _15: usize;
9698
+ scope 12 {
9799
+ scope 14 (inlined std::ptr::Alignment::new_unchecked::runtime) {
98-
+ debug align => _5;
100+
+ debug align => _15;
99101
+ scope 15 (inlined core::num::<impl usize>::is_power_of_two) {
100-
+ debug self => _5;
102+
+ debug self => _15;
101103
+ scope 16 (inlined core::num::<impl usize>::count_ones) {
102-
+ debug self => _5;
104+
+ debug self => _15;
103105
+ }
104106
+ }
105107
+ }
@@ -129,7 +131,9 @@
129131
+ StorageLive(_12);
130132
+ StorageLive(_13);
131133
+ StorageLive(_14);
134+
+ StorageLive(_15);
132135
+ _14 = _5 as std::ptr::Alignment (Transmute);
136+
+ StorageDead(_15);
133137
+ _8 = Layout { size: _4, align: move _14 };
134138
+ StorageDead(_14);
135139
+ StorageLive(_9);
@@ -153,27 +157,29 @@
153157
+
154158
+ bb4: {
155159
+ _11 = ((_9 as Ok).0: std::ptr::NonNull<[u8]>);
156-
+ StorageLive(_15);
157160
+ StorageLive(_16);
158161
+ StorageLive(_17);
159162
+ StorageLive(_18);
160-
+ _18 = (_11.0: *const [u8]);
161-
+ _17 = move _18 as *mut [u8] (PtrToPtr);
162-
+ StorageDead(_18);
163-
+ _16 = _17 as *mut u8 (PtrToPtr);
164-
+ StorageDead(_17);
165163
+ StorageLive(_19);
166-
+ StorageLive(_20);
167-
+ _19 = _16 as *const u8 (PointerCoercion(MutToConstPointer));
168-
+ _15 = NonNull::<u8> { pointer: _19 };
169-
+ StorageDead(_20);
164+
+ _19 = (_11.0: *const [u8]);
165+
+ _18 = move _19 as *mut [u8] (PtrToPtr);
170166
+ StorageDead(_19);
171-
+ StorageDead(_16);
167+
+ _17 = _18 as *mut u8 (PtrToPtr);
168+
+ StorageDead(_18);
169+
+ StorageLive(_20);
172170
+ StorageLive(_21);
173-
+ _21 = (_15.0: *const u8);
174-
+ _6 = move _21 as *mut u8 (PtrToPtr);
171+
+ StorageLive(_22);
172+
+ _20 = _17 as *const u8 (PointerCoercion(MutToConstPointer));
173+
+ _16 = NonNull::<u8> { pointer: _20 };
174+
+ StorageDead(_22);
175175
+ StorageDead(_21);
176-
+ StorageDead(_15);
176+
+ StorageDead(_20);
177+
+ StorageDead(_17);
178+
+ StorageLive(_23);
179+
+ _23 = (_16.0: *const u8);
180+
+ _6 = move _23 as *mut u8 (PtrToPtr);
181+
+ StorageDead(_23);
182+
+ StorageDead(_16);
177183
+ StorageDead(_9);
178184
+ StorageDead(_13);
179185
+ StorageDead(_12);

tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-unwind.diff

+38-32
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,37 @@
3333
+ debug ptr => _11;
3434
+ scope 18 (inlined NonNull::<[u8]>::as_mut_ptr) {
3535
+ debug self => _11;
36-
+ let mut _15: std::ptr::NonNull<u8>;
36+
+ let mut _16: std::ptr::NonNull<u8>;
3737
+ scope 19 (inlined NonNull::<[u8]>::as_non_null_ptr) {
3838
+ debug self => _11;
39-
+ let mut _16: *mut u8;
40-
+ let mut _17: *mut [u8];
39+
+ let mut _17: *mut u8;
40+
+ let mut _18: *mut [u8];
4141
+ scope 20 {
4242
+ scope 21 (inlined NonNull::<[u8]>::as_ptr) {
4343
+ debug self => _11;
44-
+ let mut _18: *const [u8];
44+
+ let mut _19: *const [u8];
4545
+ }
4646
+ scope 22 (inlined ptr::mut_ptr::<impl *mut [u8]>::as_mut_ptr) {
47-
+ debug self => _17;
47+
+ debug self => _18;
4848
+ }
4949
+ scope 23 (inlined NonNull::<u8>::new_unchecked) {
50-
+ debug ptr => _16;
51-
+ let mut _19: *const u8;
50+
+ debug ptr => _17;
51+
+ let mut _20: *const u8;
52+
+ let mut _21: *mut u8;
5253
+ scope 24 {
5354
+ scope 25 (inlined NonNull::<T>::new_unchecked::runtime::<u8>) {
54-
+ debug ptr => _16;
55+
+ debug ptr => _21;
5556
+ scope 26 (inlined ptr::mut_ptr::<impl *mut u8>::is_null) {
56-
+ debug self => _16;
57-
+ let mut _20: *mut u8;
57+
+ debug self => _21;
58+
+ let mut _22: *mut u8;
5859
+ scope 27 {
5960
+ scope 28 (inlined ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
60-
+ debug ptr => _20;
61+
+ debug ptr => _22;
6162
+ scope 29 (inlined ptr::mut_ptr::<impl *mut u8>::addr) {
62-
+ debug self => _20;
63+
+ debug self => _22;
6364
+ scope 30 {
6465
+ scope 31 (inlined ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
65-
+ debug self => _20;
66+
+ debug self => _22;
6667
+ }
6768
+ }
6869
+ }
@@ -75,8 +76,8 @@
7576
+ }
7677
+ }
7778
+ scope 32 (inlined NonNull::<u8>::as_ptr) {
78-
+ debug self => _15;
79-
+ let mut _21: *const u8;
79+
+ debug self => _16;
80+
+ let mut _23: *const u8;
8081
+ }
8182
+ }
8283
+ }
@@ -93,13 +94,14 @@
9394
+ scope 10 {
9495
+ scope 11 (inlined std::ptr::Alignment::new_unchecked) {
9596
+ debug align => _5;
97+
+ let mut _15: usize;
9698
+ scope 12 {
9799
+ scope 14 (inlined std::ptr::Alignment::new_unchecked::runtime) {
98-
+ debug align => _5;
100+
+ debug align => _15;
99101
+ scope 15 (inlined core::num::<impl usize>::is_power_of_two) {
100-
+ debug self => _5;
102+
+ debug self => _15;
101103
+ scope 16 (inlined core::num::<impl usize>::count_ones) {
102-
+ debug self => _5;
104+
+ debug self => _15;
103105
+ }
104106
+ }
105107
+ }
@@ -129,7 +131,9 @@
129131
+ StorageLive(_12);
130132
+ StorageLive(_13);
131133
+ StorageLive(_14);
134+
+ StorageLive(_15);
132135
+ _14 = _5 as std::ptr::Alignment (Transmute);
136+
+ StorageDead(_15);
133137
+ _8 = Layout { size: _4, align: move _14 };
134138
+ StorageDead(_14);
135139
+ StorageLive(_9);
@@ -170,27 +174,29 @@
170174
+
171175
+ bb6: {
172176
+ _11 = ((_9 as Ok).0: std::ptr::NonNull<[u8]>);
173-
+ StorageLive(_15);
174177
+ StorageLive(_16);
175178
+ StorageLive(_17);
176179
+ StorageLive(_18);
177-
+ _18 = (_11.0: *const [u8]);
178-
+ _17 = move _18 as *mut [u8] (PtrToPtr);
179-
+ StorageDead(_18);
180-
+ _16 = _17 as *mut u8 (PtrToPtr);
181-
+ StorageDead(_17);
182180
+ StorageLive(_19);
183-
+ StorageLive(_20);
184-
+ _19 = _16 as *const u8 (PointerCoercion(MutToConstPointer));
185-
+ _15 = NonNull::<u8> { pointer: _19 };
186-
+ StorageDead(_20);
181+
+ _19 = (_11.0: *const [u8]);
182+
+ _18 = move _19 as *mut [u8] (PtrToPtr);
187183
+ StorageDead(_19);
188-
+ StorageDead(_16);
184+
+ _17 = _18 as *mut u8 (PtrToPtr);
185+
+ StorageDead(_18);
186+
+ StorageLive(_20);
189187
+ StorageLive(_21);
190-
+ _21 = (_15.0: *const u8);
191-
+ _6 = move _21 as *mut u8 (PtrToPtr);
188+
+ StorageLive(_22);
189+
+ _20 = _17 as *const u8 (PointerCoercion(MutToConstPointer));
190+
+ _16 = NonNull::<u8> { pointer: _20 };
191+
+ StorageDead(_22);
192192
+ StorageDead(_21);
193-
+ StorageDead(_15);
193+
+ StorageDead(_20);
194+
+ StorageDead(_17);
195+
+ StorageLive(_23);
196+
+ _23 = (_16.0: *const u8);
197+
+ _6 = move _23 as *mut u8 (PtrToPtr);
198+
+ StorageDead(_23);
199+
+ StorageDead(_16);
194200
+ StorageDead(_9);
195201
+ StorageDead(_13);
196202
+ StorageDead(_12);

tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.mir

+23-11
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ fn checked_shl(_1: u32, _2: u32) -> Option<u32> {
77
scope 1 (inlined core::num::<impl u32>::checked_shl) {
88
debug self => _1;
99
debug rhs => _2;
10-
let mut _7: bool;
10+
let mut _7: (u32, bool);
11+
let _8: u32;
12+
let _9: bool;
13+
let mut _10: bool;
1114
scope 2 {
12-
debug a => _5;
13-
debug b => _6;
15+
debug a => _8;
16+
debug b => _9;
1417
}
1518
scope 3 (inlined core::num::<impl u32>::overflowing_shl) {
1619
debug self => _1;
@@ -35,26 +38,35 @@ fn checked_shl(_1: u32, _2: u32) -> Option<u32> {
3538
}
3639

3740
bb0: {
41+
StorageLive(_8);
42+
StorageLive(_9);
43+
StorageLive(_7);
3844
StorageLive(_5);
39-
StorageLive(_6);
4045
StorageLive(_4);
4146
StorageLive(_3);
4247
_3 = const 31_u32;
4348
_4 = BitAnd(_2, move _3);
4449
StorageDead(_3);
4550
_5 = ShlUnchecked(_1, _4);
4651
StorageDead(_4);
52+
StorageLive(_6);
4753
_6 = Ge(_2, const _);
48-
StorageLive(_7);
49-
_7 = unlikely(_6) -> [return: bb1, unwind unreachable];
54+
_7 = (move _5, move _6);
55+
StorageDead(_6);
56+
StorageDead(_5);
57+
_8 = (_7.0: u32);
58+
_9 = (_7.1: bool);
59+
StorageDead(_7);
60+
StorageLive(_10);
61+
_10 = unlikely(_9) -> [return: bb1, unwind unreachable];
5062
}
5163

5264
bb1: {
53-
switchInt(move _7) -> [0: bb2, otherwise: bb3];
65+
switchInt(move _10) -> [0: bb2, otherwise: bb3];
5466
}
5567

5668
bb2: {
57-
_0 = Option::<u32>::Some(_5);
69+
_0 = Option::<u32>::Some(_8);
5870
goto -> bb4;
5971
}
6072

@@ -64,9 +76,9 @@ fn checked_shl(_1: u32, _2: u32) -> Option<u32> {
6476
}
6577

6678
bb4: {
67-
StorageDead(_7);
68-
StorageDead(_6);
69-
StorageDead(_5);
79+
StorageDead(_10);
80+
StorageDead(_9);
81+
StorageDead(_8);
7082
return;
7183
}
7284
}

tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@ fn mem_replace(_1: &mut u32, _2: u32) -> u32 {
1515
scope 7 (inlined std::ptr::write::<u32>) {
1616
debug dst => _4;
1717
debug src => _2;
18+
let mut _6: *mut u32;
1819
scope 8 {
1920
scope 9 (inlined std::ptr::write::runtime::<u32>) {
20-
debug dst => _4;
21+
debug dst => _6;
2122
}
2223
}
2324
}
2425
}
2526
scope 4 (inlined std::ptr::read::<u32>) {
2627
debug src => _3;
28+
let mut _5: *const u32;
2729
scope 5 {
2830
scope 6 (inlined std::ptr::read::runtime::<u32>) {
29-
debug src => _3;
31+
debug src => _5;
3032
}
3133
}
3234
}
@@ -36,11 +38,15 @@ fn mem_replace(_1: &mut u32, _2: u32) -> u32 {
3638
bb0: {
3739
StorageLive(_3);
3840
_3 = &raw const (*_1);
41+
StorageLive(_5);
3942
_0 = (*_3);
43+
StorageDead(_5);
4044
StorageDead(_3);
4145
StorageLive(_4);
4246
_4 = &raw mut (*_1);
47+
StorageLive(_6);
4348
(*_4) = _2;
49+
StorageDead(_6);
4450
StorageDead(_4);
4551
return;
4652
}

0 commit comments

Comments
 (0)