diff options
| author | Ralf Jung <post@ralfj.de> | 2024-06-08 12:04:38 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-06-08 12:24:48 +0200 |
| commit | 9b05e154f39f1a413ebc09c8f1dd751f991b3bba (patch) | |
| tree | e1b689f414c8ecb9ea89a262e62053af1823a584 /compiler/rustc_middle | |
| parent | d8fde5074571dfa3fecbc2a304597a83fcd6a893 (diff) | |
| download | rust-9b05e154f39f1a413ebc09c8f1dd751f991b3bba.tar.gz rust-9b05e154f39f1a413ebc09c8f1dd751f991b3bba.zip | |
StorageLive: refresh storage (instead of UB) when local is already live
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/mir/syntax.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index ebe77a1abfd..9855c72197e 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -361,16 +361,19 @@ pub enum StatementKind<'tcx> { /// At any point during the execution of a function, each local is either allocated or /// unallocated. Except as noted below, all locals except function parameters are initially /// unallocated. `StorageLive` statements cause memory to be allocated for the local while - /// `StorageDead` statements cause the memory to be freed. Using a local in any way (not only - /// reading/writing from it) while it is unallocated is UB. + /// `StorageDead` statements cause the memory to be freed. In other words, + /// `StorageLive`/`StorageDead` act like the heap operations `allocate`/`deallocate`, but for + /// stack-allocated local variables. Using a local in any way (not only reading/writing from it) + /// while it is unallocated is UB. /// /// Some locals have no `StorageLive` or `StorageDead` statements within the entire MIR body. /// These locals are implicitly allocated for the full duration of the function. There is a /// convenience method at `rustc_mir_dataflow::storage::always_storage_live_locals` for /// computing these locals. /// - /// If the local is already allocated, calling `StorageLive` again is UB. However, for an - /// unallocated local an additional `StorageDead` all is simply a nop. + /// If the local is already allocated, calling `StorageLive` again will implicitly free the + /// local and then allocate fresh uninitilized memory. If a local is already deallocated, + /// calling `StorageDead` again is a NOP. StorageLive(Local), /// See `StorageLive` above. |
