Skip to content

Commit 31e4b84

Browse files
committed
Auto merge of #159047 - workingjubilee:revert-enum-tag-change, r=scottmcm
Revert extension of `-1` for `None`-like tags Note that I am not marking this as resolving the inciting issue in question as it addresses the symptom without curing the disease. This reverts #155850 Said issue in question: #159035
2 parents cb014fc + 71d2d3d commit 31e4b84

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

compiler/rustc_abi/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,8 +2103,7 @@ impl Niche {
21032103
let distance_end_zero = max_value - v.end;
21042104
// FIXME: this ought to work for `bool` too, but that seems to be hitting a miscompilation
21052105
// <https://github.com/rust-lang/rust/pull/155473#issuecomment-4302036343>
2106-
let is_bool = size.bytes() == 1 && v == WrappingRange { start: 0, end: 1 };
2107-
if count == 1 && !is_bool {
2106+
if count == 1 && v != (WrappingRange { start: 0, end: 1 }) {
21082107
// We only need one, so just pick the one closest to zero.
21092108
// Not only does that obviously use zero if it's possible, but it also
21102109
// simplifies testing things like `Option<char>`, since looking for `-1`

tests/codegen-llvm/function-arguments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ pub fn return_slice(x: &[u16]) -> &[u16] {
265265
x
266266
}
267267

268-
// CHECK: { i16, i16 } @enum_id_1(i16 noundef{{( range\(i16 -1, 2\))?}} %x.0, i16 %x.1)
268+
// CHECK: { i16, i16 } @enum_id_1(i16 noundef{{( range\(i16 0, 3\))?}} %x.0, i16 %x.1)
269269
#[no_mangle]
270270
pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> {
271271
x
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//@ run-pass
2+
3+
// Bad regression test for https://github.com/rust-lang/rust/issues/159035
4+
// This should probably be replaced with a codegen test, though that might need to be in LLVM,
5+
// as it seems that the miscompilation may occur on correct IR misoptimized by SimplifyCFG.
6+
7+
#![allow(dead_code)]
8+
9+
enum Inner {
10+
A(u32),
11+
B(u32),
12+
}
13+
struct Big {
14+
_pad: u64,
15+
inner: Inner,
16+
}
17+
struct Small {
18+
a: u16,
19+
b: u16,
20+
_f: fn(),
21+
}
22+
enum Checksum {
23+
X(Big),
24+
Y(Small),
25+
}
26+
impl Checksum {
27+
fn finalize(self) -> u32 {
28+
match self {
29+
Checksum::X(h) => match h.inner {
30+
Inner::A(s) => s,
31+
Inner::B(s) => s,
32+
},
33+
Checksum::Y(s) => (u32::from(s.b) << 16) | u32::from(s.a),
34+
}
35+
}
36+
}
37+
#[inline(never)]
38+
fn run(c: Option<Checksum>) -> Option<u32> {
39+
c.map(|c| c.finalize())
40+
}
41+
fn main() {
42+
println!("{:?}", run(std::hint::black_box(None)));
43+
}

0 commit comments

Comments
 (0)