Skip to content

Fix invalid instantiation of fake intrinsic bodies - #165769

Open
oli-obk wants to merge 2 commits into
rust-lang:mainfrom
oli-obk:lmao-unreachable-body-in-any-intrinsic
Open

oli-obk wants to merge 2 commits into
rust-lang:mainfrom
oli-obk:lmao-unreachable-body-in-any-intrinsic

Conversation

@oli-obk

@oli-obk oli-obk commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

fixes #164984

In #122037 I created those fake bodies because we wanted to avoid all the checks I added here, and the intrinsics are always overridden anyway. Well, so we thought. If you're creative you can get at them, and it's possible there are cases that could be exposed on stable. Seems generally nicer to make it more robust

@rustbot

rustbot commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@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 Nov 10, 2026
@rustbot

rustbot commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

r? @jieyouxu

rustbot has assigned @jieyouxu.
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, mir, mir-opt
  • compiler, mir, mir-opt expanded to 79 candidates
  • Random selection from 22 candidates

@oli-obk

oli-obk commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

cc @RalfJung

@rust-log-analyzer

This comment has been minimized.

@oli-obk
oli-obk force-pushed the lmao-unreachable-body-in-any-intrinsic branch from ab84fb6 to 8714e50 Compare November 11, 2026 10:36

@RalfJung RalfJung left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread compiler/rustc_interface/src/passes.rs Outdated
sess.time("MIR_borrow_checking", || {
tcx.par_hir_body_owners(|def_id| {
if tcx.is_intrinsic_that_must_be_overridden(def_id) {
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return;
return; // there is no MIR here to check

Comment thread compiler/rustc_mir_transform/src/lib.rs Outdated
@@ -334,7 +334,10 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {

// Remove the fake bodies for `global_asm!`, since they're not useful

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The comment needs to be updated

let def_id = local_def_id.to_def_id();
let kind = tcx.def_kind(def_id);
if !kind.is_fn_like() {
if !kind.is_fn_like() || tcx.is_intrinsic_that_must_be_overridden(def_id) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some intrinsics can unwind, so false does not seem like a conservative answer here?

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.

well, we previously also returned false, because there was nothing in the body (except for an unreachable terminator). So yea, we should def figure out what the right behaviour here is. I don't see anything marking intrinsics as possibly unwinding, so we'd need to start doing that.

also this is about ffi unwinds, so this would be limited to things like const_eval_select that invoke closures or callbacks?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Where does this nice error come from? I expected this to ICE.

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.

Checking upstream crates' mir goes through is_mir_available as MIR isn't encoded unless the function is inline or generic

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sure -- but why does that not ICE? Hitting this error is always a bug, isn't it?

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.

iirc there are some tests for weird combinations of cli flags that can cause this. But yea, ideally this would be an ICE

@rustbot rustbot assigned RalfJung and unassigned jieyouxu Nov 11, 2026
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 11, 2026
@rustbot

rustbot commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@oli-obk
oli-obk force-pushed the lmao-unreachable-body-in-any-intrinsic branch from 8714e50 to 1e52c52 Compare November 12, 2026 11:20
@oli-obk

oli-obk commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 12, 2026
@oli-obk
oli-obk force-pushed the lmao-unreachable-body-in-any-intrinsic branch from 1e52c52 to b474d01 Compare November 12, 2026 15:06
@rustbot

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

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.

UB with use std::intrinsics::abort_immediate as main;

5 participants