Skip to content

Emit retags in codegen to support BorrowSanitizer (part 1)#156208

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
BorrowSanitizer:codegen-emit-retag-1
May 18, 2026
Merged

Emit retags in codegen to support BorrowSanitizer (part 1)#156208
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
BorrowSanitizer:codegen-emit-retag-1

Conversation

@icmccorm

@icmccorm icmccorm commented May 5, 2026

Copy link
Copy Markdown
Contributor

Tracking issue: #154760
Zulip Thread

This is the first of several PRs that will add experimental support for emitting retags as function calls in codegen. Each PR will be a minimal, improved slice of the changes in #155965.

This PR contains all of the changes that will affect codegen backends. It adds methods to IntrinsicCallBuilderMethods for emitting each kind of retag call.

cc: @RalfJung

@rustbot

rustbot commented May 5, 2026

Copy link
Copy Markdown
Collaborator

The GCC codegen subtree was changed

cc @antoyo, @GuillaumeGomez

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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 May 5, 2026
@rustbot

rustbot commented May 5, 2026

Copy link
Copy Markdown
Collaborator

r? @jackh726

rustbot has assigned @jackh726.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 19 candidates

@saethlin

saethlin commented May 5, 2026

Copy link
Copy Markdown
Member

r? saethlin

@rustbot rustbot assigned saethlin and unassigned jackh726 May 5, 2026
@icmccorm icmccorm force-pushed the codegen-emit-retag-1 branch from 824ce42 to e15861b Compare May 15, 2026 16:38
@rustbot

rustbot commented May 15, 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.

@saethlin

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor

📌 Commit e15861b 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 May 17, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 17, 2026
…-1, r=saethlin

Emit retags in codegen to support BorrowSanitizer (part 1)

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/593004012)

This is the first of several PRs that will add experimental support for emitting retags as function calls in codegen. Each PR will be a minimal, improved slice of the changes in rust-lang#155965.

This PR contains all of the changes that will affect codegen backends. It adds methods to `IntrinsicCallBuilderMethods` for emitting each kind of retag call.

cc: @RalfJung
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors try jobs=aarch64-apple

@rust-bors

rust-bors Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor

⌛ Trying commit e15861b with merge e6b753f

To cancel the try build, run the command @bors try cancel.

Workflow: https://github.com/rust-lang/rust/actions/runs/25990798832

rust-bors Bot pushed a commit that referenced this pull request May 17, 2026
Emit retags in codegen to support BorrowSanitizer (part 1)


try-job: aarch64-apple
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors try cancel

@rust-bors

rust-bors Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor

Try build cancelled. Cancelled workflows:

rust-bors Bot pushed a commit that referenced this pull request May 17, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #151742 (Remove redundant information in `rustc_abi::Variants`)
 - #151362 (Add interior-mutability suggestion to `static_mut_refs`)
 - #156121 (compiler: suggest `.collect()` when `String` is expected and `Iterator` is found)
 - #156208 (Emit retags in codegen to support BorrowSanitizer (part 1))
 - #156596 (Split `LintExpectationId`s)
 - #156607 (ci: Update FreeBSD version to FreeBSD 14)
 - #156376 (suggest hex escapes for C-style escapes)
 - #156577 (Test EII UI tests with prefer-dynamic)
 - #156585 (explicit tail calls: ignore some tests on unsupported LLVM targets)
 - #156598 (Avoid rustfix suggestions for macro-expanded unused imports)
 - #156616 (rustdoc: add test case for `-Drustdoc::` and `--cap-lints`)
 - #156633 (Add regression test for issue #41261)
 - #156635 (rename unexpected_try_recover function)
 - #156636 (minor `rustc_mir_transform` cleanup)
rust-bors Bot pushed a commit that referenced this pull request May 17, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #151742 (Remove redundant information in `rustc_abi::Variants`)
 - #151362 (Add interior-mutability suggestion to `static_mut_refs`)
 - #156121 (compiler: suggest `.collect()` when `String` is expected and `Iterator` is found)
 - #156208 (Emit retags in codegen to support BorrowSanitizer (part 1))
 - #156596 (Split `LintExpectationId`s)
 - #156607 (ci: Update FreeBSD version to FreeBSD 14)
 - #156376 (suggest hex escapes for C-style escapes)
 - #156577 (Test EII UI tests with prefer-dynamic)
 - #156585 (explicit tail calls: ignore some tests on unsupported LLVM targets)
 - #156598 (Avoid rustfix suggestions for macro-expanded unused imports)
 - #156616 (rustdoc: add test case for `-Drustdoc::` and `--cap-lints`)
 - #156633 (Add regression test for issue #41261)
 - #156635 (rename unexpected_try_recover function)
 - #156636 (minor `rustc_mir_transform` cleanup)
@rust-bors rust-bors Bot merged commit ff42fc0 into rust-lang:main May 18, 2026
11 of 12 checks passed
rust-timer added a commit that referenced this pull request May 18, 2026
Rollup merge of #156208 - BorrowSanitizer:codegen-emit-retag-1, r=saethlin

Emit retags in codegen to support BorrowSanitizer (part 1)

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

This is the first of several PRs that will add experimental support for emitting retags as function calls in codegen. Each PR will be a minimal, improved slice of the changes in #155965.

This PR contains all of the changes that will affect codegen backends. It adds methods to `IntrinsicCallBuilderMethods` for emitting each kind of retag call.

cc: @RalfJung
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request May 18, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#151742 (Remove redundant information in `rustc_abi::Variants`)
 - rust-lang/rust#151362 (Add interior-mutability suggestion to `static_mut_refs`)
 - rust-lang/rust#156121 (compiler: suggest `.collect()` when `String` is expected and `Iterator` is found)
 - rust-lang/rust#156208 (Emit retags in codegen to support BorrowSanitizer (part 1))
 - rust-lang/rust#156596 (Split `LintExpectationId`s)
 - rust-lang/rust#156607 (ci: Update FreeBSD version to FreeBSD 14)
 - rust-lang/rust#156376 (suggest hex escapes for C-style escapes)
 - rust-lang/rust#156577 (Test EII UI tests with prefer-dynamic)
 - rust-lang/rust#156585 (explicit tail calls: ignore some tests on unsupported LLVM targets)
 - rust-lang/rust#156598 (Avoid rustfix suggestions for macro-expanded unused imports)
 - rust-lang/rust#156616 (rustdoc: add test case for `-Drustdoc::` and `--cap-lints`)
 - rust-lang/rust#156633 (Add regression test for issue rust-lang/rust#41261)
 - rust-lang/rust#156635 (rename unexpected_try_recover function)
 - rust-lang/rust#156636 (minor `rustc_mir_transform` cleanup)
@ehuss ehuss added this to the 1.97.0 milestone May 28, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 4, 2026
…-2, r=saethlin

Emit retags in codegen to support BorrowSanitizer (part 2)

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/593004012)

This is one of several PRs that will add experimental support for emitting retags as function calls in codegen. Each PR will be a minimal, improved slice of the changes in rust-lang#155965.

This PR adds a new unstable flag `-Zcodegen-emit-retag`, which will enable experimental retag calls in generated code. This flag is a nop for now, but the relevant methods have been added to codegen_ssa, and they are called wherever retags are necessary. Subsequent PRs will complete this implementation.

This does not depend on rust-lang#156208.

r? @RalfJung
rust-bors Bot pushed a commit that referenced this pull request Jun 4, 2026
Emit retags in codegen to support BorrowSanitizer (part 2)

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

This is one of several PRs that will add experimental support for emitting retags as function calls in codegen. Each PR will be a minimal, improved slice of the changes in #155965.

This PR adds a new unstable flag `-Zcodegen-emit-retag`, which will enable experimental retag calls in generated code. This flag is a nop for now, but the relevant methods have been added to codegen_ssa, and they are called wherever retags are necessary. Subsequent PRs will complete this implementation.

This does not depend on #156208. 

r? @RalfJung
rust-timer added a commit that referenced this pull request Jun 4, 2026
Rollup merge of #156210 - BorrowSanitizer:codegen-emit-retag-2, r=saethlin

Emit retags in codegen to support BorrowSanitizer (part 2)

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

This is one of several PRs that will add experimental support for emitting retags as function calls in codegen. Each PR will be a minimal, improved slice of the changes in #155965.

This PR adds a new unstable flag `-Zcodegen-emit-retag`, which will enable experimental retag calls in generated code. This flag is a nop for now, but the relevant methods have been added to codegen_ssa, and they are called wherever retags are necessary. Subsequent PRs will complete this implementation.

This does not depend on #156208.

r? @RalfJung
@icmccorm icmccorm deleted the codegen-emit-retag-1 branch June 7, 2026 21:12
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 13, 2026
…-3, r=saethlin

Emit retags in codegen to support BorrowSanitizer (part 3)

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/593004012)

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

This PR adds `RetagPlan`, which describes where the pointers that need to be retagged live within the layout of a type. We create a `RetagPlan` ahead of time because only a subset of the variants of a type might contain retagable values. We only want to branch to these variants, and ignore all of the others. If a type can generate a `RetagPlan`, then we will use it as a guide for inserting calls to our retag intrinsics. If a type does not generate a `RetagPlan`, then it does not need to be retagged, and we can skip it.

This does not emit a `RetagPlan::EmitRetag` yet. That will come in a subsequent PR.

Previous parts: rust-lang#156208, rust-lang#156210

cc: @RalfJung
r? @saethlin
rust-timer added a commit that referenced this pull request Jun 13, 2026
Rollup merge of #157825 - BorrowSanitizer:codegen-emit-retag-3, r=saethlin

Emit retags in codegen to support BorrowSanitizer (part 3)

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

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

This PR adds `RetagPlan`, which describes where the pointers that need to be retagged live within the layout of a type. We create a `RetagPlan` ahead of time because only a subset of the variants of a type might contain retagable values. We only want to branch to these variants, and ignore all of the others. If a type can generate a `RetagPlan`, then we will use it as a guide for inserting calls to our retag intrinsics. If a type does not generate a `RetagPlan`, then it does not need to be retagged, and we can skip it.

This does not emit a `RetagPlan::EmitRetag` yet. That will come in a subsequent PR.

Previous parts: #156208, #156210

cc: @RalfJung
r? @saethlin
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 2, 2026
…-4, r=saethlin

Emit retags in codegen to support BorrowSanitizer (part 4)

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/593004012)

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

This PR emits our retag intrinsics based on the structure of a `RetagPlan`. The feature works end-to-end now! But, it has two limitations:

* We do not track interior mutable or pinned ranges precisely. This will come in the next PR, which should be the last one that we need to complete this feature (excluding documentation and compile tests).

* We recurse into `repr(simd)` types when building a `RetagPlan`, but we do not emit retags for their fields. We would need `BuilderMethods::insert_element`, which isn't available. I'm not sure what the best workaround would be for this.

Related: rust-lang#157825, rust-lang#156210, rust-lang#156208

Cc: @RalfJung
r? @saethlin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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.

6 participants