Skip to content

VFE: set !type for vtables in constants - #166164

Open
folkertdev wants to merge 2 commits into
rust-lang:mainfrom
folkertdev:vfe-const
Open

folkertdev wants to merge 2 commits into
rust-lang:mainfrom
folkertdev:vfe-const

Conversation

@folkertdev

@folkertdev folkertdev commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

tracking issue: #68262

fixes #164774

A vtable in a constant takes a different codegen path, and previously it did not apply the attributes that virtual function elimination needs. That could lead to miscompilations. So, use the get_vtable helper in both paths.

  • GCC does not need to set the VFE metadata. I'd like it to also use get_vtable, but that requires more refactoring, and I'd prefer to do that in the rustc_codegen_gcc repo
  • Cranelift already shares the vtable creation code across places where it emits one.

I'm aware of an issue with vtables escaping to global assembly. However, I think we first need to fix applying the !type and !vcall_visibility attributes to non-prefix supertrait vtables, and can then revisit this issue (tracked as #166223). EDIT: apparently looking at vtable fields manually is UB, so this is even less relevant than I thought.

Best reviewed commit-by-commit.

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 18, 2026
@folkertdev
folkertdev marked this pull request as ready for review November 19, 2026 20:49
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 19, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 19, 2026
@rustbot

rustbot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

r? @adwinwhite

rustbot has assigned @adwinwhite.
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 79 candidates
  • Random selection from 19 candidates

@adwinwhite

Copy link
Copy Markdown
Contributor

r? codegen

@rustbot rustbot assigned saethlin and unassigned adwinwhite Nov 23, 2026
@folkertdev

Copy link
Copy Markdown
Contributor Author

r? WaffleLapkin (because you reviewed #165475)

@rustbot rustbot assigned WaffleLapkin and unassigned saethlin Nov 23, 2026
@rustbot

rustbot commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

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

A vtable in a constant takes a different codegen path, and previously it did not apply the attributes that virtual function elimination needs. That could lead to miscompilations

- GCC does not need to set the VFE metadata. I'd like it to also use get_vtable, but that requires more refactoring, and I'd prefer to do that in the `rustc_codegen_gcc` repo
- Cranelift already shares the vtable creation code across places where it emits one.
@rustbot

rustbot commented Nov 28, 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.

This branch has not been deployed

No deployments
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-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.

static trait object with -Zvirtual-function-elimination calls incorrect implementation

5 participants