Skip to content

Emit retags in codegen to support BorrowSanitizer (part 2)#156210

Open
icmccorm wants to merge 3 commits into
rust-lang:mainfrom
BorrowSanitizer:codegen-emit-retag-2
Open

Emit retags in codegen to support BorrowSanitizer (part 2)#156210
icmccorm wants to merge 3 commits into
rust-lang:mainfrom
BorrowSanitizer:codegen-emit-retag-2

Conversation

@icmccorm
Copy link
Copy Markdown
Contributor

@icmccorm icmccorm commented May 5, 2026

Tracking issue: #154760
Zulip Thread

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

@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 May 5, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 5, 2026

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

@saethlin
Copy link
Copy Markdown
Member

saethlin commented May 5, 2026

r? saethlin

@rustbot rustbot assigned saethlin and unassigned RalfJung May 5, 2026
@rust-log-analyzer

This comment has been minimized.

@icmccorm icmccorm force-pushed the codegen-emit-retag-2 branch from 951a9ed to 4e3df71 Compare May 7, 2026 17:02
@rustbot

This comment has been minimized.

@icmccorm
Copy link
Copy Markdown
Contributor Author

icmccorm commented May 7, 2026

Now that #154327 has been merged, we no longer need special handling for drop glue.

@rust-bors

This comment has been minimized.

@icmccorm icmccorm force-pushed the codegen-emit-retag-2 branch from 4e3df71 to 5135340 Compare May 15, 2026 16:53
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 15, 2026

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.

LocalRef::PendingOperand => LocalRef::PendingOperand,
})
.collect::<Vec<_>>();
// If we branched during retagging, then we need to update the
Copy link
Copy Markdown
Member

@saethlin saethlin May 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would retagging introduce a branch?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We selectively retag variants of enums that contain references or Box. For example,

fn foo(opt: Option<Box<i32>>) { .. }

This will branch on the discriminant of opt to retag the Box, if it's there.

}
fx.store_return(bx, ret_dest, &fn_abi.ret, invokeret);

// If the return value has variants that needed to be retagged,
Copy link
Copy Markdown
Member

@saethlin saethlin May 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you mentioning variants here? Why isn't this just "if the return value needs to be retagged"?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that should just say "if the return value needs to be retagged".

use crate::traits::BuilderMethods;

pub(crate) fn place_needs_retag(place: &Place<'_>) -> bool {
// We're not interested in tracking stores to "outside" locations
Copy link
Copy Markdown
Member

@saethlin saethlin May 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "outside" mean?

View changes since the review

Copy link
Copy Markdown
Contributor Author

@icmccorm icmccorm May 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whups - we shouldn't need to need to skip these retags any more, now that #154341 has been merged. This was an artifact of the old AddRetag implementation. Here's the relevant part of @RalfJung's explanation for why these were skipped in that PR:

For assignments of the form *ptr = expr, if the assignment involves copying a reference, we probably want to do a retag -- but if we do a Retag(*ptr) as the next instruction, it can be non-trivial to argue that this even retags the right value, so we refrained from doing retags in that case.

I'll remove place_needs_retag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants