Files
rust/tests/codegen/issues/issue-122600-ptr-discriminant-update.rs
Stuart Cook f4aa209e20 Rollup merge of #139438 - Zalathar:fix-test-122600, r=scottmcm
Prevent a test from seeing forbidden numbers in the rustc version

The final CHECK-NOT directive in this test was able to see past the end of the enclosing function, and find the substring `753` or `754` in the git hash in the rustc version number, causing false failures in CI whenever the git hash happens to contain those digits in sequence.

Adding an explicit check for `ret` prevents the CHECK-NOT directive from seeing past the end of the function.

---

Manually tested by adding `// CHECK-NOT: rustc` after the existing CHECK-NOT directives, and demonstrating that the new check prevents it from seeing the rustc version string.
2025-04-06 16:21:03 +10:00

44 lines
1012 B
Rust

//@ compile-flags: -Copt-level=3
#![crate_type = "lib"]
// The bug here was that it was loading and storing the whole value.
// It's ok for it to load the discriminant,
// to preserve the UB from `unreachable_unchecked`,
// but it better only store the constant discriminant of `B`.
pub enum State {
A([u8; 753]),
B([u8; 753]),
}
// CHECK-LABEL: @update
#[no_mangle]
pub unsafe fn update(s: *mut State) {
// CHECK-NOT: alloca
// CHECK-NOT: load
// CHECK-NOT: store
// CHECK-NOT: memcpy
// CHECK-NOT: 75{{3|4}}
// CHECK: %[[TAG:.+]] = load i8, ptr %s, align 1
// CHECK-NEXT: trunc nuw i8 %[[TAG]] to i1
// CHECK-NOT: load
// CHECK-NOT: store
// CHECK-NOT: memcpy
// CHECK-NOT: 75{{3|4}}
// CHECK: store i8 1, ptr %s, align 1
// CHECK-NOT: load
// CHECK-NOT: store
// CHECK-NOT: memcpy
// CHECK-NOT: 75{{3|4}}
// CHECK: ret
let State::A(v) = s.read() else { std::hint::unreachable_unchecked() };
s.write(State::B(v));
}