Apply noundef attribute to all scalar types which do not permit raw init
Beyond `&`/`&mut`/`Box`, this covers `char`, discriminants, `NonZero*`, etc. All such types currently cause a Miri error if left uninitialized, and an `invalid_value` lint in cases like `mem::uninitialized::<char>()` Note that this _does not_ change whether or not it is UB for `u64` (or other integer types with no invalid values) to be undef.
This commit is contained in:
parent
8604ef0878
commit
5979b681e6
5 changed files with 61 additions and 6 deletions
|
@ -3053,6 +3053,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
|||
return;
|
||||
}
|
||||
|
||||
// Scalars which have invalid values cannot be undef.
|
||||
if !scalar.is_always_valid(self) {
|
||||
attrs.set(ArgAttribute::NoUndef);
|
||||
}
|
||||
|
||||
// Only pointer types handled below.
|
||||
if scalar.value != Pointer {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue