about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/back/write.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-26 08:44:10 +0000
committerbors <bors@rust-lang.org>2024-08-26 08:44:10 +0000
commit22572d0994593197593e2a1b7b18d720a9a349a7 (patch)
tree127548e1d05f81029098dcb0af783d0815211c13 /compiler/rustc_codegen_ssa/src/back/write.rs
parentf48062e7d040579ac5705e1b36b34675000da5dd (diff)
parent74a21425cca6742f08a6df25bb153a3b7a43f56a (diff)
downloadrust-22572d0994593197593e2a1b7b18d720a9a349a7.tar.gz
rust-22572d0994593197593e2a1b7b18d720a9a349a7.zip
Auto merge of #129508 - RalfJung:transient-locals, r=cjgillot
const checking: properly compute the set of transient locals

For const-checking the MIR of a const/static initializer, we have to know the set of "transient" locals. The reason for this is that creating a mutable (or interior mutable) reference to a transient local is "safe" in the sense that this reference cannot possibly end up in the final value of the const -- even if it is turned into a raw pointer and stored in a union, we will see that pointer during interning and reliably reject it as dangling.

So far, we determined the set of transient locals as "locals that have a `StorageDead` somewhere". But that's not quite right -- if we had MIR like
```rust
StorageLive(_5);
StorageDead(_5);
StorageLive(_5);
// no further storage annotations for _5
```
Then we'd consider `_5` to be "transient", but it is not actually transient.

We do not currently generate such MIR, but I feel uneasy relying on subtle invariants like this. So this PR implements a proper analysis for computing the set of "transient" locals: a local is "transient" if it is guaranteed dead at all `Return` terminators.

Cc `@cjgillot`
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/back/write.rs')
0 files changed, 0 insertions, 0 deletions