Skip to content

Commit d908a5b

Browse files
committed
Auto merge of #113892 - RalfJung:uninit-undef-poison, r=wesleywiser
clarify MIR uninit vs LLVM undef/poison In [this LLVM discussion](https://discourse.llvm.org/t/rfc-load-instruction-uninitialized-memory-semantics/67481) I learned that mapping our uninitialized memory in MIR to poison in LLVM would be quite problematic due to the lack of a byte type. I am not sure where to write down this insight but this seems like a reasonable start.
2 parents c3c5a5c + 41a73d8 commit d908a5b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

compiler/rustc_codegen_ssa/src/traits/consts.rs

+6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ use rustc_target::abi;
55
pub trait ConstMethods<'tcx>: BackendTypes {
66
// Constant constructors
77
fn const_null(&self, t: Self::Type) -> Self::Value;
8+
/// Generate an uninitialized value (matching uninitialized memory in MIR).
9+
/// Whether memory is initialized or not is tracked byte-for-byte.
810
fn const_undef(&self, t: Self::Type) -> Self::Value;
11+
/// Generate a fake value. Poison always affects the entire value, even if just a single byte is
12+
/// poison. This can only be used in codepaths that are already UB, i.e., UB-free Rust code
13+
/// (including code that e.g. copies uninit memory with `MaybeUninit`) can never encounter a
14+
/// poison value.
915
fn const_poison(&self, t: Self::Type) -> Self::Value;
1016
fn const_int(&self, t: Self::Type, i: i64) -> Self::Value;
1117
fn const_uint(&self, t: Self::Type, i: u64) -> Self::Value;

compiler/rustc_const_eval/src/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub enum Immediate<Prov: Provenance = AllocId> {
3131
/// A pair of two scalar value (must have `ScalarPair` ABI where both fields are
3232
/// `Scalar::Initialized`).
3333
ScalarPair(Scalar<Prov>, Scalar<Prov>),
34-
/// A value of fully uninitialized memory. Can have and size and layout.
34+
/// A value of fully uninitialized memory. Can have arbitrary size and layout.
3535
Uninit,
3636
}
3737

0 commit comments

Comments
 (0)