about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-07-21 19:32:17 +0000
committerbors <bors@rust-lang.org>2023-07-21 19:32:17 +0000
commitd908a5b08e9ccbd2b41f8b399aa6cd919d5cb451 (patch)
treeacb2921e0160ca30e1264981ecd0158be2a2b49f /compiler/rustc_codegen_ssa/src
parentc3c5a5c5f7a0cf9acdfe60440a1e1fa68a1c1278 (diff)
parent41a73d8251553afa39c7082b44b2781ca4898578 (diff)
downloadrust-d908a5b08e9ccbd2b41f8b399aa6cd919d5cb451.tar.gz
rust-d908a5b08e9ccbd2b41f8b399aa6cd919d5cb451.zip
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.
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/traits/consts.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_ssa/src/traits/consts.rs b/compiler/rustc_codegen_ssa/src/traits/consts.rs
index d6e9bfce1a4..822c19155e3 100644
--- a/compiler/rustc_codegen_ssa/src/traits/consts.rs
+++ b/compiler/rustc_codegen_ssa/src/traits/consts.rs
@@ -5,7 +5,13 @@ use rustc_target::abi;
 pub trait ConstMethods<'tcx>: BackendTypes {
     // Constant constructors
     fn const_null(&self, t: Self::Type) -> Self::Value;
+    /// Generate an uninitialized value (matching uninitialized memory in MIR).
+    /// Whether memory is initialized or not is tracked byte-for-byte.
     fn const_undef(&self, t: Self::Type) -> Self::Value;
+    /// Generate a fake value. Poison always affects the entire value, even if just a single byte is
+    /// poison. This can only be used in codepaths that are already UB, i.e., UB-free Rust code
+    /// (including code that e.g. copies uninit memory with `MaybeUninit`) can never encounter a
+    /// poison value.
     fn const_poison(&self, t: Self::Type) -> Self::Value;
     fn const_int(&self, t: Self::Type, i: i64) -> Self::Value;
     fn const_uint(&self, t: Self::Type, i: u64) -> Self::Value;