mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 02:33:55 +00:00
645c0fddd2
Previously, it was only put on scalars with range validity invariants like bool, was uninit was obviously invalid for those. Since then, we have normatively declared all uninit primitives to be undefined behavior and can therefore put `noundef` on them. The remaining concern was the `mem::uninitialized` function, which cause quite a lot of UB in the older parts of the ecosystem. This function now doesn't return uninit values anymore, making users of it safe from this change. The only real sources of UB where people could encounter uninit primitives are `MaybeUninit::uninit().assume_init()`, which has always be clear in the docs about being UB and from heap allocations (like reading from the spare capacity of a vec. This is hopefully rare enough to not break anything.
21 lines
540 B
Rust
21 lines
540 B
Rust
// no-system-llvm
|
|
// compile-flags: -Coverflow-checks=no -O
|
|
// revisions: YES NO
|
|
// [YES]compile-flags: -Zfewer-names=yes
|
|
// [NO] compile-flags: -Zfewer-names=no
|
|
#![crate_type = "lib"]
|
|
|
|
#[no_mangle]
|
|
pub fn sum(x: u32, y: u32) -> u32 {
|
|
// YES-LABEL: define{{.*}}i32 @sum(i32 noundef %0, i32 noundef %1)
|
|
// YES-NEXT: %3 = add i32 %1, %0
|
|
// YES-NEXT: ret i32 %3
|
|
|
|
// NO-LABEL: define{{.*}}i32 @sum(i32 noundef %x, i32 noundef %y)
|
|
// NO-NEXT: start:
|
|
// NO-NEXT: %z = add i32 %y, %x
|
|
// NO-NEXT: ret i32 %z
|
|
let z = x + y;
|
|
z
|
|
}
|