rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
95.12k stars 12.27k forks source link

mir-opt tests fail on big endian #126261

Closed nikic closed 4 days ago

nikic commented 1 month ago

A number of mir-opt tests fail on s390x, which is a big endian architecture. Failures for 1.79:

---- [mir-opt] tests/mir-opt/const_debuginfo.rs stdout ----
106   }
107   
108   ALLOC0 (size: 8, align: 4) {
-         20 00 00 00 20 00 00 00                         │  ... ...
+         00 00 00 20 00 00 00 20                         │ ... ... 
110   }
111   
112   ALLOC1 (size: 4, align: 2) {
-         01 00 63 00                                     │ ..c.
+         00 01 00 63                                     │ ...c
114   }
115   
116 
thread '[mir-opt] tests/mir-opt/const_debuginfo.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
---- [mir-opt] tests/mir-opt/const_prop/address_of_pair.rs stdout ----
47  + }
48  + 
49  + ALLOC0 (size: 8, align: 4) {
-   +     01 00 00 00 00 __ __ __                         │ .....░░░
+   +     00 00 00 01 00 __ __ __                         │ .....░░░
51    }
52    
53  
thread '[mir-opt] tests/mir-opt/const_prop/address_of_pair.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/const_prop/address_of_pair.fn0.GVN.diff
---- [mir-opt] tests/mir-opt/const_prop/checked_add.rs stdout ----
27  + }
28  + 
29  + ALLOC0 (size: 8, align: 4) {
-   +     02 00 00 00 00 __ __ __                         │ .....░░░
+   +     00 00 00 02 00 __ __ __                         │ .....░░░
31    }
32    
33  
thread '[mir-opt] tests/mir-opt/const_prop/checked_add.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/const_prop/checked_add.main.GVN.panic-unwind.diff
---- [mir-opt] tests/mir-opt/const_prop/mutable_variable_aggregate.rs stdout ----
27  + }
28  + 
29  + ALLOC0 (size: 8, align: 4) {
-   +     2a 00 00 00 2b 00 00 00                         │ *...+...
+   +     00 00 00 2a 00 00 00 2b                         │ ...*...+
31    }
32    
33  
thread '[mir-opt] tests/mir-opt/const_prop/mutable_variable_aggregate.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/const_prop/mutable_variable_aggregate.main.GVN.diff
---- [mir-opt] tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs stdout ----
34  + }
35  + 
36  + ALLOC0 (size: 8, align: 4) {
-   +     2a 00 00 00 2b 00 00 00                         │ *...+...
+   +     00 00 00 2a 00 00 00 2b                         │ ...*...+
38    }
39    
40  
thread '[mir-opt] tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.GVN.diff
---- [mir-opt] tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs stdout ----
51  + }
52  + 
53  + ALLOC0 (size: 8, align: 4) {
-   +     01 00 00 00 02 00 00 00                         │ ........
+   +     00 00 00 01 00 00 00 02                         │ ........
55    }
56    
57  
thread '[mir-opt] tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-unwind.diff
---- [mir-opt] tests/mir-opt/const_prop/return_place.rs stdout ----
20  + }
21  + 
22  + ALLOC0 (size: 8, align: 4) {
-   +     04 00 00 00 00 __ __ __                         │ .....░░░
+   +     00 00 00 04 00 __ __ __                         │ .....░░░
24    }
25    
26  
thread '[mir-opt] tests/mir-opt/const_prop/return_place.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/const_prop/return_place.add.GVN.panic-unwind.diff
---- [mir-opt] tests/mir-opt/const_prop/slice_len.rs stdout ----
52  + }
53  + 
54  + ALLOC0 (size: 12, align: 4) {
-   +     01 00 00 00 02 00 00 00 03 00 00 00             │ ............
+   +     00 00 00 01 00 00 00 02 00 00 00 03             │ ............
56    }
57    
58  
thread '[mir-opt] tests/mir-opt/const_prop/slice_len.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff
---- [mir-opt] tests/mir-opt/const_prop/tuple_literal_propagation.rs stdout ----
34  + }
35  + 
36  + ALLOC0 (size: 8, align: 4) {
-   +     01 00 00 00 02 00 00 00                         │ ........
+   +     00 00 00 01 00 00 00 02                         │ ........
38    }
39    
40  
thread '[mir-opt] tests/mir-opt/const_prop/tuple_literal_propagation.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-unwind.diff
---- [mir-opt] tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs stdout ----
109 + }
110 + 
111 + ALLOC2 (size: 16, align: 8) {
-   +     01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
+   +     00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 │ ................
113 + }
114 + 
115 + ALLOC1 (size: 16, align: 8) {
-   +     01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
+   +     00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 │ ................
117 + }
118 + 
119 + ALLOC0 (size: 16, align: 8) {
-   +     01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
+   +     00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 │ ................
121   }
122   
123 
thread '[mir-opt] tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff
---- [mir-opt] tests/mir-opt/dataflow-const-prop/checked.rs stdout ----
79  + }
80  + 
81  + ALLOC0 (size: 8, align: 4) {
-   +     00 00 00 80 01 __ __ __                         │ .....░░░
+   +     80 00 00 00 01 __ __ __                         │ .....░░░
83  + }
84  + 
85  + ALLOC1 (size: 8, align: 4) {
-   +     03 00 00 00 00 __ __ __                         │ .....░░░
+   +     00 00 00 03 00 __ __ __                         │ .....░░░
87    }
88    
89  
thread '[mir-opt] tests/mir-opt/dataflow-const-prop/checked.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.panic-unwind.diff
---- [mir-opt] tests/mir-opt/dataflow-const-prop/enum.rs stdout ----
122   }
123   
124   ALLOC0 (size: 8, align: 4) {
-         01 00 00 00 04 00 00 00                         │ ........
+         00 00 00 01 00 00 00 04                         │ ........
126   }
127   
128   ALLOC1 (static: statics::C, size: 8, align: 4) {
thread '[mir-opt] tests/mir-opt/dataflow-const-prop/enum.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.64bit.diff
---- [mir-opt] tests/mir-opt/dataflow-const-prop/struct.rs stdout ----
200 + }
201 + 
202 + ALLOC6 (size: 8, align: 4) {
-   +     01 00 00 00 23 00 00 00                         │ ....#...
+   +     00 00 00 01 00 00 00 23                         │ .......#
204 + }
205 + 
206 + ALLOC7 (size: 8, align: 4) {
-   +     01 00 00 00 23 00 00 00                         │ ....#...
+   +     00 00 00 01 00 00 00 23                         │ .......#
208 + }
209 + 
210 + ALLOC8 (size: 8, align: 4) {
-   +     01 00 00 00 23 00 00 00                         │ ....#...
+   +     00 00 00 01 00 00 00 23                         │ .......#
212 + }
213 + 
214 + ALLOC9 (size: 8, align: 4) {
-   +     01 00 00 00 01 00 00 00                         │ ........
+   +     00 00 00 01 00 00 00 01                         │ ........
216 + }
217 + 
218 + ALLOC10 (size: 4, align: 4) {
-   +     01 00 00 00                                     │ ....
+   +     00 00 00 01                                     │ ....
220   }
221   
222   ALLOC5 (static: BIG_STAT, size: 8, align: 8) {
224   }
225   
226   ALLOC0 (size: 32, align: 8) {
-         0x00 │ 01 00 00 00 23 00 00 00 ╾ALLOC1<imm>╼ │ ....#...╾──────╼
-         0x10 │ 02 00 00 00 00 00 00 00 00 00 a4 42 __ __ __ __ │ ...........B░░░░
+         0x00 │ 00 00 00 01 00 00 00 23 ╾ALLOC1<imm>╼ │ .......#╾──────╼
+         0x10 │ 00 00 00 00 00 00 00 02 42 a4 00 00 __ __ __ __ │ ........B...░░░░
229   }
230   
231   ALLOC1 (size: 8, align: 4) {
-         00 00 34 42 00 00 90 42                         │ ..4B...B
+         42 34 00 00 42 90 00 00                         │ B4..B...
233   }
234   
235   ALLOC4 (static: SMALL_STAT, size: 8, align: 8) {
238   
239   ALLOC2 (size: 32, align: 8) {
240       0x00 │ 00 00 00 00 __ __ __ __ ╾ALLOC3<imm>╼ │ ....░░░░╾──────╼
-         0x10 │ 01 00 00 00 00 00 00 00 00 00 10 41 __ __ __ __ │ ...........A░░░░
+         0x10 │ 00 00 00 00 00 00 00 01 41 10 00 00 __ __ __ __ │ ........A...░░░░
242   }
243   
244   ALLOC3 (size: 4, align: 4) {
-         00 00 50 41                                     │ ..PA
+         41 50 00 00                                     │ AP..
246   }
247   
248 
thread '[mir-opt] tests/mir-opt/dataflow-const-prop/struct.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.64bit.diff
---- [mir-opt] tests/mir-opt/dataflow-const-prop/tuple.rs stdout ----
95  + }
96  + 
97  + ALLOC0 (size: 8, align: 4) {
-   +     02 00 00 00 03 00 00 00                         │ ........
+   +     00 00 00 02 00 00 00 03                         │ ........
99  + }
100 + 
101 + ALLOC1 (size: 8, align: 4) {
-   +     02 00 00 00 03 00 00 00                         │ ........
+   +     00 00 00 02 00 00 00 03                         │ ........
103 + }
104 + 
105 + ALLOC2 (size: 8, align: 4) {
-   +     02 00 00 00 03 00 00 00                         │ ........
+   +     00 00 00 02 00 00 00 03                         │ ........
107 + }
108 + 
109 + ALLOC3 (size: 8, align: 4) {
-   +     01 00 00 00 02 00 00 00                         │ ........
+   +     00 00 00 01 00 00 00 02                         │ ........
111   }
112   
113 
thread '[mir-opt] tests/mir-opt/dataflow-const-prop/tuple.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/dataflow-const-prop/tuple.main.DataflowConstProp.64bit.diff
---- [mir-opt] tests/mir-opt/enum_opt.rs stdout ----
67  + }
68  + 
69  + ALLOC0 (size: 16, align: 8) {
-   +     05 20 00 00 00 00 00 00 01 00 00 00 00 00 00 00 │ . ..............
+   +     00 00 00 00 00 00 20 05 00 00 00 00 00 00 00 01 │ ...... .........
71    }
72    
73  
thread '[mir-opt] tests/mir-opt/enum_opt.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/enum_opt.unin.EnumSizeOpt.64bit.diff
---- [mir-opt] tests/mir-opt/gvn.rs stdout ----
179 + }
180 + 
181 + ALLOC1 (size: 16, align: 8) {
-   +     01 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 │ ................
+   +     00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 02 │ ................
183 + }
184 + 
185 + ALLOC0 (size: 16, align: 8) {
-   +     01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 │ ................
+   +     00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 │ ................
187   }
188   
189 
thread '[mir-opt] tests/mir-opt/gvn.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-unwind.diff
---- [mir-opt] tests/mir-opt/pre-codegen/optimizes_into_variable.rs stdout ----
64  + }
65  + 
66  + ALLOC0 (size: 8, align: 4) {
-   +     04 00 00 00 00 __ __ __                         │ .....░░░
+   +     00 00 00 04 00 __ __ __                         │ .....░░░
68    }
69    
70  
thread '[mir-opt] tests/mir-opt/pre-codegen/optimizes_into_variable.rs' panicked at src/tools/compiletest/src/runtest.rs:4421:21:
Actual MIR output differs from expected MIR output /builddir/build/BUILD/rust-1.79.0~beta.10-build/rustc-beta-src/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-unwind.diff
failures:
    [mir-opt] tests/mir-opt/const_debuginfo.rs
    [mir-opt] tests/mir-opt/const_prop/address_of_pair.rs
    [mir-opt] tests/mir-opt/const_prop/checked_add.rs
    [mir-opt] tests/mir-opt/const_prop/mutable_variable_aggregate.rs
    [mir-opt] tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs
    [mir-opt] tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs
    [mir-opt] tests/mir-opt/const_prop/return_place.rs
    [mir-opt] tests/mir-opt/const_prop/slice_len.rs
    [mir-opt] tests/mir-opt/const_prop/tuple_literal_propagation.rs
    [mir-opt] tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs
    [mir-opt] tests/mir-opt/dataflow-const-prop/checked.rs
    [mir-opt] tests/mir-opt/dataflow-const-prop/enum.rs
    [mir-opt] tests/mir-opt/dataflow-const-prop/struct.rs
    [mir-opt] tests/mir-opt/dataflow-const-prop/tuple.rs
    [mir-opt] tests/mir-opt/enum_opt.rs
    [mir-opt] tests/mir-opt/gvn.rs
    [mir-opt] tests/mir-opt/pre-codegen/optimizes_into_variable.rs

Some previous fixes for such failures were https://github.com/rust-lang/rust/pull/115167 and https://github.com/rust-lang/rust/pull/106046.

nikic commented 1 month ago

Something peculiar about many of these tests is that transforms seem to create ALLOCs that are not actually referenced by MIR. Is that expected?

In terms of fixing this, the existing approach of picking constants that are endianness-independent doesn't seem very scalable. Maybe it would make sense to have a flag that disables dumping the contents of allocations? I think that for most of these tests they are not relevant (especially as the allocations are unused in the first place).

DianQK commented 1 month ago

Something peculiar about many of these tests is that transforms seem to create ALLOCs that are not actually referenced by MIR. Is that expected?

This appears to be an intermediate result of the optimization process, such as: https://rust.godbolt.org/z/ohz1YMqez (tests/mir-opt/const_prop/slice_len.rs).

In terms of fixing this, the existing approach of picking constants that are endianness-independent doesn't seem very scalable. Maybe it would make sense to have a flag that disables dumping the contents of allocations? I think that for most of these tests they are not relevant (especially as the allocations are unused in the first place).

There is an option ignore-endian-big to skip these tests, but I like another option to change the output to be uniformly little-endian.

cuviper commented 1 month ago

If these tests don't actually care about the raw bytes in their UI comparisons, then they can use normalize-stderr-test to hide the bytes. There are quite a few tests that already normalize to the string "HEX_DUMP".

cuviper commented 1 month ago

Rather than trying to normalize output, I'm proposing an option in #126502 to skip the raw bytes altogether.

uweigand commented 2 days ago

Huh, looks like a new instance has crept in just as the PR was merged. I'm now seeing a new test fail:

---- [mir-opt] tests/mir-opt/dataflow-const-prop/aggregate_copy.rs stdout ----
60      + }
61      + 
62      + ALLOC0 (size: 8, align: 4) {
-       +     05 00 00 00 03 00 00 00                         │ ........
+       +     00 00 00 05 00 00 00 03                         │ ........
64        }