Skip to content

virtual function elimination: only use type.checked.load for function pointers - #164290

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
folkertdev:vfe-load-fix
Oct 31, 2026
Merged

rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
folkertdev:vfe-load-fix

Conversation

@folkertdev

Copy link
Copy Markdown
Contributor

tracking issue: #68262

fixes #164267

The documentation on @llvm.type.checked.load says:

https://llvm.org/docs/LangRef.html#llvm-type-checked-load-intrinsic

The first argument is a pointer from which to load a function pointer.

But we also used it for other kinds of types, causing type mismatches in LLVM IR. So, just use a plain load instead in those cases. This was missed in #130734.

This also fixes a related bug with feature(ptr_metadata), see https://godbolt.org/z/9d941rhWd. Basically #130734 passed an invalid type along, causing an ICE down the line. This example was found by an LLM.

r? codegen

@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 Oct 13, 2026
@matthiaskrgr

Copy link
Copy Markdown
Member

this this also fix #124093 ?

@folkertdev

Copy link
Copy Markdown
Contributor Author

No, that is a problem with requesting -Zvirtual-function-elimination=true on an intermediate artifact (not a binary, static library, or something else that LTO actually runs on). If you change the example there to use --crate-type=staticlib it works https://godbolt.org/z/P6eox5Geh.

So that is more a problem on the rust side: what do we do with the flag when we know that the backend can't handle it.

@rust-bors

This comment has been minimized.

The langref says that

> The first argument is a pointer from which to load a function pointer

So whenever we load something that is not a function pointer, we should not use `type_checked_load`
@rustbot

rustbot commented Oct 29, 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 Oct 30, 2026

Copy link
Copy Markdown
Contributor

📌 Commit dfbacfb 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 Oct 30, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Oct 31, 2026
virtual function elimination: only use `type.checked.load` for function pointers

tracking issue: rust-lang#68262

fixes rust-lang#164267

The documentation on `@llvm.type.checked.load` says:

https://llvm.org/docs/LangRef.html#llvm-type-checked-load-intrinsic

> The first argument is a pointer from which to load a function pointer.

But we also used it for other kinds of types, causing type mismatches in LLVM IR. So, just use a plain load instead in those cases. This was missed in rust-lang#130734.

This also fixes a related bug with `feature(ptr_metadata)`, see https://godbolt.org/z/9d941rhWd. Basically rust-lang#130734 passed an invalid type along, causing an ICE down the line. This example was found by an LLM.

r? codegen
rust-bors Bot pushed a commit that referenced this pull request Oct 31, 2026
Rollup of 19 pull requests

Successful merges:

 - #160370 (rustdoc: notable trait badge and popover enhancements)
 - #163410 (Use a macro to reduce duplication in `core/src/num/f{16,32,64,128}.rs` (part 1))
 - #164290 (virtual function elimination: only use `type.checked.load` for function pointers)
 - #165113 (Limit lldb string summary length)
 - #165146 (Stop using LLVM struct types for array/pointer offset GEPs (rebase))
 - #165197 (Inline usages of `is_doc_keyword_or_attribute` and `is_rustc_doc_primitive`)
 - #165209 (Don't ICE when making diagnostic in `point_at_dyn_trait_in_field_def` if there's no `dyn Trait` field to point at)
 - #153633 (feat: improve `Cell` doc)
 - #164686 (Add regression test for new solver hang on cyclic projection bound)
 - #164937 (Add example for misaligned elements in `subslice_range`)
 - #164981 (Reflection add TypeId::name)
 - #165035 (Suggest `gca!` for path const args that use generic params)
 - #165106 (Windows: Disallow some special chars in bat script names)
 - #165120 (Add regression test for overlap check hang with unresolved type in where clause)
 - #165158 (Tiny optimization to `TypeErrCtxt::report_inference_failure()`)
 - #165184 (GCI: Check where-clauses of associated constants for well-formedness)
 - #165190 (Improve delayed bug comment and message on first_method_vtable_slot)
 - #165196 (inhabitedness: use try_normalize_erasing_regions on ADT fields)
 - #165206 (tests: clarify dead_code_pub_in_binary FIXME after Cargo workaround)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 31, 2026
virtual function elimination: only use `type.checked.load` for function pointers

tracking issue: rust-lang#68262

fixes rust-lang#164267

The documentation on `@llvm.type.checked.load` says:

https://llvm.org/docs/LangRef.html#llvm-type-checked-load-intrinsic

> The first argument is a pointer from which to load a function pointer.

But we also used it for other kinds of types, causing type mismatches in LLVM IR. So, just use a plain load instead in those cases. This was missed in rust-lang#130734.

This also fixes a related bug with `feature(ptr_metadata)`, see https://godbolt.org/z/9d941rhWd. Basically rust-lang#130734 passed an invalid type along, causing an ICE down the line. This example was found by an LLM.

r? codegen
rust-bors Bot pushed a commit that referenced this pull request Oct 31, 2026
…uwer

Rollup of 23 pull requests

Successful merges:

 - #163410 (Use a macro to reduce duplication in `core/src/num/f{16,32,64,128}.rs` (part 1))
 - #164290 (virtual function elimination: only use `type.checked.load` for function pointers)
 - #165113 (Limit lldb string summary length)
 - #165146 (Stop using LLVM struct types for array/pointer offset GEPs (rebase))
 - #165197 (Inline usages of `is_doc_keyword_or_attribute` and `is_rustc_doc_primitive`)
 - #165209 (Don't ICE when making diagnostic in `point_at_dyn_trait_in_field_def` if there's no `dyn Trait` field to point at)
 - #165228 (Fix error output for invalid `SBValue` children)
 - #153633 (feat: improve `Cell` doc)
 - #164686 (Add regression test for new solver hang on cyclic projection bound)
 - #164730 (core: Rename `abort_immediate` to `crash`)
 - #164937 (Add example for misaligned elements in `subslice_range`)
 - #165019 (Add safety section for from_utf8_unchecked/from_raw_parts)
 - #165035 (Suggest `gca!` for path const args that use generic params)
 - #165106 (Windows: Disallow some special chars in bat script names)
 - #165120 (Add regression test for overlap check hang with unresolved type in where clause)
 - #165158 (Tiny optimization to `TypeErrCtxt::report_inference_failure()`)
 - #165184 (GCI: Check where-clauses of associated constants for well-formedness)
 - #165190 (Improve delayed bug comment and message on first_method_vtable_slot)
 - #165196 (inhabitedness: use try_normalize_erasing_regions on ADT fields)
 - #165206 (tests: clarify dead_code_pub_in_binary FIXME after Cargo workaround)
 - #165214 (add MaybeUninit::from_ref)
 - #165225 (LoongArch: Restore `feature(stdarch_loongarch)` for bootstrap)
 - #165235 (two LLVM backend cleanups)

Failed merges:

 - #160370 (rustdoc: notable trait badge and popover enhancements)
 - #164981 (Reflection add TypeId::name)
@rust-bors
rust-bors Bot merged commit e339217 into rust-lang:main Oct 31, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 31, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 31, 2026
Rollup merge of #164290 - folkertdev:vfe-load-fix, r=saethlin

virtual function elimination: only use `type.checked.load` for function pointers

tracking issue: #68262

fixes #164267

The documentation on `@llvm.type.checked.load` says:

https://llvm.org/docs/LangRef.html#llvm-type-checked-load-intrinsic

> The first argument is a pointer from which to load a function pointer.

But we also used it for other kinds of types, causing type mismatches in LLVM IR. So, just use a plain load instead in those cases. This was missed in #130734.

This also fixes a related bug with `feature(ptr_metadata)`, see https://godbolt.org/z/9d941rhWd. Basically #130734 passed an invalid type along, causing an ICE down the line. This example was found by an LLM.

r? codegen
mehmettoplu-rs pushed a commit to mehmettoplu-rs/rustc_codegen_gcc that referenced this pull request Nov 22, 2026
…uwer

Rollup of 23 pull requests

Successful merges:

 - rust-lang/rust#163410 (Use a macro to reduce duplication in `core/src/num/f{16,32,64,128}.rs` (part 1))
 - rust-lang/rust#164290 (virtual function elimination: only use `type.checked.load` for function pointers)
 - rust-lang/rust#165113 (Limit lldb string summary length)
 - rust-lang/rust#165146 (Stop using LLVM struct types for array/pointer offset GEPs (rebase))
 - rust-lang/rust#165197 (Inline usages of `is_doc_keyword_or_attribute` and `is_rustc_doc_primitive`)
 - rust-lang/rust#165209 (Don't ICE when making diagnostic in `point_at_dyn_trait_in_field_def` if there's no `dyn Trait` field to point at)
 - rust-lang/rust#165228 (Fix error output for invalid `SBValue` children)
 - rust-lang/rust#153633 (feat: improve `Cell` doc)
 - rust-lang/rust#164686 (Add regression test for new solver hang on cyclic projection bound)
 - rust-lang/rust#164730 (core: Rename `abort_immediate` to `crash`)
 - rust-lang/rust#164937 (Add example for misaligned elements in `subslice_range`)
 - rust-lang/rust#165019 (Add safety section for from_utf8_unchecked/from_raw_parts)
 - rust-lang/rust#165035 (Suggest `gca!` for path const args that use generic params)
 - rust-lang/rust#165106 (Windows: Disallow some special chars in bat script names)
 - rust-lang/rust#165120 (Add regression test for overlap check hang with unresolved type in where clause)
 - rust-lang/rust#165158 (Tiny optimization to `TypeErrCtxt::report_inference_failure()`)
 - rust-lang/rust#165184 (GCI: Check where-clauses of associated constants for well-formedness)
 - rust-lang/rust#165190 (Improve delayed bug comment and message on first_method_vtable_slot)
 - rust-lang/rust#165196 (inhabitedness: use try_normalize_erasing_regions on ADT fields)
 - rust-lang/rust#165206 (tests: clarify dead_code_pub_in_binary FIXME after Cargo workaround)
 - rust-lang/rust#165214 (add MaybeUninit::from_ref)
 - rust-lang/rust#165225 (LoongArch: Restore `feature(stdarch_loongarch)` for bootstrap)
 - rust-lang/rust#165235 (two LLVM backend cleanups)

Failed merges:

 - rust-lang/rust#160370 (rustdoc: notable trait badge and popover enhancements)
 - rust-lang/rust#164981 (Reflection add TypeId::name)
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.

Non-valid LLVM IR generated with -Z virtual-function-elimination

4 participants