Skip to content

Disable MIR inlining so calls are always checked against callee specs - #349

Open
coord-e wants to merge 1 commit into
mainfrom
claude/gifted-bohr-6wptpz
Open

coord-e wants to merge 1 commit into
mainfrom
claude/gifted-bohr-6wptpz

Conversation

@coord-e

@coord-e coord-e commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Fixes #348.

At -C opt-level=2/3 with incremental compilation off (for example cargo --release), rustc's MIR Inline pass inlines small same-crate functions into their callers. This includes functions with requires/ensures and #[thrust::trusted] ones. An inlined call leaves no Call terminator in optimized_mir, so Thrust never checked the arguments against the callee's precondition, and violations verified as safe.

This PR sets -Zinline-mir=no (unstable_opts.inline_mir = Some(false)) in CompilerCalls::config, next to the MIR passes the driver already disables. Inline::is_enabled checks this option first, so every call stays a call and is typed through the callee's spec at any opt level.

Test

tests/ui/{pass,fail}/trusted_requires_opt_level.rs call a trusted function with requires(x != 0) at -C opt-level=3, once with 1 and once with 0. Without this change, the fail case verifies as safe.

cargo test (402 UI tests), cargo fmt --check and cargo clippy -D warnings all pass locally. I also re-ran the issue's reproducers at opt-level 2 and 3. Each now gives Unsat, including the get_unchecked one under PCSat.


Generated by Claude Code

At -C opt-level=2/3 with incremental compilation off (e.g. cargo
--release), rustc's MIR Inline pass inlines small same-crate functions
into their callers, including ones with requires/ensures and
#[thrust::trusted] ones. An inlined call leaves no Call terminator, so
its arguments were never checked against the callee's precondition and
violations verified as safe.

Fixes #348

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQVMLYpCUxi5PMD6MSDMqM
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T21:24:18.113593Z 3e44a25 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e44a255a4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main.rs

// A call inlined by the MIR inliner leaves no `Call` terminator behind, so the
// arguments are never checked against the callee's specification.
config.opts.unstable_opts.inline_mir = Some(false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Account for the mandatory force-inlining pass

When a verified crate enables rustc_attrs and marks a specified or trusted callee with #[rustc_force_inline], this setting does not preserve its Call terminator: rustc runs a separate mandatory ForceInline pass whose is_enabled always returns true and which cannot be overridden (rustc source). Consequently, such a callee's precondition can still disappear and an invalid call can verify as safe; account for this pass or reject specifications on force-inlined functions rather than claiming all calls remain visible.

Useful? React with 👍 / 👎.

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

None yet

Projects

None yet

2 participants