Skip to content

Emit retags in codegen to support BorrowSanitizer (part 5) - #159245

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
BorrowSanitizer:codegen-emit-retag-5
Aug 1, 2026
Merged

Emit retags in codegen to support BorrowSanitizer (part 5)#159245
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
BorrowSanitizer:codegen-emit-retag-5

Conversation

@icmccorm

@icmccorm icmccorm commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Tracking issue: #154760
Zulip Thread

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,

fn cell(x: &(i32, Cell<i32>)) { ... }

This program will have IR similar to the following:

@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: #158100

Cc: @RalfJung
r? @saethlin

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 13, 2026
@rust-bors

This comment has been minimized.

@icmccorm
icmccorm force-pushed the codegen-emit-retag-5 branch from b7d93a2 to a3a56d7 Compare July 20, 2026 20:04
@rustbot

rustbot commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Comment thread compiler/rustc_codegen_ssa/src/mir/retag.rs
@icmccorm
icmccorm force-pushed the codegen-emit-retag-5 branch from e06b5d4 to a87d3c3 Compare July 30, 2026 15:49
@saethlin

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

📌 Commit a87d3c3 has been approved by saethlin

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 31, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 1, 2026
…-5, r=saethlin

Emit retags in codegen to support BorrowSanitizer (part 5)

Tracking issue: rust-lang#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#158100

Cc: @RalfJung
r? @saethlin
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 1, 2026
…-5, r=saethlin

Emit retags in codegen to support BorrowSanitizer (part 5)

Tracking issue: rust-lang#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#158100

Cc: @RalfJung
r? @saethlin
rust-bors Bot pushed a commit that referenced this pull request Aug 1, 2026
Rollup of 14 pull requests

Successful merges:

 - #159245 (Emit retags in codegen to support BorrowSanitizer (part 5))
 - #159864 (Report "capacity overflow" for oversized Rc<[T]>/Arc<[T]>)
 - #160079 (make atomic operations const)
 - #160124 (Structurally prevent zero-count `BackendRepr::SimdVector`s)
 - #160162 (Make `#[fundamental]` only apply to the first argument of `Box`)
 - #160210 (Remove an outdated FIXME)
 - #160282 (Improve diagnostic for patterns in function pointer types)
 - #157928 (Eagerly fetch typeck results when linting)
 - #159672 (Improve suggestions when multiples tuples implement the same trait)
 - #159861 (Add documentation for the `non_exhaustive` attribute)
 - #159907 (Fix `hidden_glob_reexports` in `rustc_ast`)
 - #159998 (Align expect messages with guidance)
 - #160145 (Expand checks for register_tool)
 - #160307 (Update `minifier` version to `0.4.0`)
@rust-bors
rust-bors Bot merged commit ad93b9a into rust-lang:main Aug 1, 2026
13 checks passed
rust-timer added a commit that referenced this pull request Aug 1, 2026
Rollup merge of #159245 - BorrowSanitizer:codegen-emit-retag-5, r=saethlin

Emit retags in codegen to support BorrowSanitizer (part 5)

Tracking issue: #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: #158100

Cc: @RalfJung
r? @saethlin
@rustbot rustbot added this to the 1.99.0 milestone Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants