Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the change that disables MIR inlining when stubbing is enabled.
No open issues 🎉
What changed in this PR
Prevents MIR inlining from bypassing Kani function stubs at optimization levels 2 and 3, addressing the false verification results reported in #5094.
Changes:
- Passes
-Z inline-mir=nowhen stubbing is enabled, including through function contracts. - Adds an optimization-level-2 regression test checking that a stub applies through an intermediate caller.
| File | Description |
|---|---|
tests/kani/Stubbing/stub_inlined_function.rs |
Tests stub application through a caller with optimization enabled. |
kani-driver/src/call_single_file.rs |
Disables MIR inlining when stubbing is enabled. |
Review effort: Balanced
Dependencies skip codegen, so passing the flag to them only changed their flags and forced a rebuild, which broke `build-cache-dirty` for `-Z function-contracts`. Add a cargo test for the local-crate path.
feliperodri
left a comment
There was a problem hiding this comment.
Thanks @r-near. Turning off MIR inlining for the crate under verification whenever stubbing or contracts are enabled is the right fix. It matters for soundness too, not only for #[kani::stub]: stub_verified replaces a call with the contract, which asserts the precondition, so an inlined call loses that check. With the base build at -Copt-level=2, this harness verifies even though caller violates x < 10; with your change it fails as it should:
#[kani::requires(x < 10)]
#[kani::ensures(|r: &u32| *r == x + 1)]
fn inc(x: u32) -> u32 { x + 1 }
fn caller() -> u32 { inc(50) }
#[kani::proof]
#[kani::stub_verified(inc)]
fn uses_contract() { let _ = caller(); }Could you add this case as a regression test (an expected test with -Copt-level=2)? It's the most important case this PR fixes. I also checked a stub on a function inlined inside a path dependency at opt-level 2: it applies with and without your change, so leaving the flag off dependencies is fine. The stubbing and contract suites pass.
|
@feliperodri added it as |
At opt-level 2/3, rustc's MIR inliner copies a stubbed function into its callers, and
FnStubPassonly replaces the function's own body, so the stub was silently skipped there. This passes-Z inline-mir=noto the crate under verification whenever stubbing is enabled (including via function contracts). Dependencies skip codegen, so they don't get it; passing it to them would only force a rebuild.Adds
tests/kani/Stubbing/stub_inlined_function.rs,tests/cargo-kani/stubbing-inlined-functionandtests/expected/function-contract/stub_verified_inlined_requires_fail.rs, which fail before this change.Resolves #5094
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.