Files
rust/compiler/rustc_codegen_ssa
Jacob Pratt ad93b9a0be Rollup merge of #159245 - BorrowSanitizer:codegen-emit-retag-5, r=saethlin
Emit retags in codegen to support BorrowSanitizer (part 5)

Tracking issue: rust-lang/rust#154760
[Zulip Thread](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Staging.20for.20emitting.20retags.20in.20codegen/with/592364811)

This is one of several PRs that add experimental support for emitting retags as function calls in codegen.

This PR adds support for emitting global arrays that specify the ranges of interior mutable and pinned data. For example,
```rust
fn cell(x: &(i32, Cell<i32>)) { ... }
```
This program will have IR similar to the following:
```llvm
@anon.0 = unnamed_addr constant [16 x i8] c"\04...\04..."
define void @cell(ptr %0)  {
start:
  %x = call ptr @__rust_retag_reg(ptr %0, i64 8, i8 1, ptr @anon.0, ptr null)
  ...
}
```
The last four bytes at offset four are interior mutable.

Users can disable this behavior by passing `no-precise-im` or `no-precise-pin` as options to  `-Zcodegen-emit-retag`. In that case, the last two parameters to the retag intrinsic will always be null pointers.

BorrowSanitizer will be able to switch to using nightly once this is merged. Thank you @saethlin for reviewing these PRs!

Note: we still do not support retagging SIMD types, since cg-ssa does not support `insertelement`.

Related: rust-lang/rust#158100

Cc: @RalfJung
r? @saethlin
2026-07-31 22:25:10 -04:00
..
…

Please read the rustc-dev-guide chapter on Backend Agnostic Codegen.