Repository navigation
Preserve memory initialization checks at unresolved calls - #5172
feliperodri merged 9 commits into
Conversation
|
Pushed a small follow-up: Disclosure: this comment was prepared with the help of AI assistants. |
There was a problem hiding this comment.
🟡 Changes recommended
Repeated traversal of shared field types can make shim classification exponential and stall compilation, while uncached callee-body availability checks add redundant work during points-to analysis.
2 open issues
What changed in this PR
This PR preserves Kani’s memory-initialization checks when a call cannot be resolved, advancing #3300 without adding support for indirect-call memory effects.
Changes:
- Preserve pending argument loads and operand checks before unsupported-call diagnostics.
- Share fallible call resolution and guard unsupported memory-state transfers through generated shims.
- Add paired plain and seeded regressions for direct calls, indirect calls, generated shims, and entry-block checks.
| File | Description |
|---|---|
tests/expected/uninit/unresolved-calls/wrapped-pointer-seeded.rs |
Covers wrapped-pointer calls with analysis seeds. |
tests/expected/uninit/unresolved-calls/wrapped-pointer-seeded.expected |
Requires the function-pointer diagnostic. |
tests/expected/uninit/unresolved-calls/wrapped-pointer-plain.rs |
Covers wrapped-pointer calls without seeds. |
tests/expected/uninit/unresolved-calls/wrapped-pointer-plain.expected |
Requires the function-pointer diagnostic. |
tests/expected/uninit/unresolved-calls/virtual-seeded.rs |
Covers trait-object calls with analysis seeds. |
tests/expected/uninit/unresolved-calls/virtual-seeded.expected |
Requires the trait-object diagnostic. |
tests/expected/uninit/unresolved-calls/virtual-plain.rs |
Covers trait-object calls without seeds. |
tests/expected/uninit/unresolved-calls/virtual-plain.expected |
Requires the trait-object diagnostic. |
tests/expected/uninit/unresolved-calls/pending-ops-seeded.rs |
Exercises uninitialized call operands with seeds. |
tests/expected/uninit/unresolved-calls/pending-ops-seeded.expected |
Requires both operand and unsupported-call failures. |
tests/expected/uninit/unresolved-calls/pending-ops-plain.rs |
Exercises uninitialized call operands without seeds. |
tests/expected/uninit/unresolved-calls/pending-ops-plain.expected |
Requires both operand and unsupported-call failures. |
tests/expected/uninit/unresolved-calls/global-escaped-seeded.rs |
Covers indirect global-pointer access with seeds. |
tests/expected/uninit/unresolved-calls/global-escaped-seeded.expected |
Requires the function-pointer diagnostic. |
tests/expected/uninit/unresolved-calls/global-escaped-plain.rs |
Covers indirect global-pointer access without seeds. |
tests/expected/uninit/unresolved-calls/global-escaped-plain.expected |
Requires the function-pointer diagnostic. |
tests/expected/uninit/unresolved-calls/generated-positive-seeded.rs |
Covers supported generated-shim paths with seeds. |
tests/expected/uninit/unresolved-calls/generated-positive-seeded.expected |
Requires successful generated-shim verification. |
tests/expected/uninit/unresolved-calls/generated-positive-plain.rs |
Covers supported generated-shim paths without seeds. |
tests/expected/uninit/unresolved-calls/generated-positive-plain.expected |
Requires successful generated-shim verification. |
tests/expected/uninit/unresolved-calls/fn-trait-pointer-seeded.rs |
Covers Fn-trait function-pointer calls with seeds. |
tests/expected/uninit/unresolved-calls/fn-trait-pointer-seeded.expected |
Requires rejection of the underlying indirect call. |
tests/expected/uninit/unresolved-calls/fn-trait-pointer-plain.rs |
Covers Fn-trait function-pointer calls without seeds. |
tests/expected/uninit/unresolved-calls/fn-trait-pointer-plain.expected |
Requires rejection of the underlying indirect call. |
tests/expected/uninit/unresolved-calls/fn-pointer-seeded.rs |
Covers basic function-pointer calls with seeds. |
tests/expected/uninit/unresolved-calls/fn-pointer-seeded.expected |
Requires the function-pointer diagnostic. |
tests/expected/uninit/unresolved-calls/fn-pointer-plain.rs |
Covers basic function-pointer calls without seeds. |
tests/expected/uninit/unresolved-calls/fn-pointer-plain.expected |
Requires the function-pointer diagnostic. |
tests/expected/uninit/unresolved-calls/erased-pointer-seeded.rs |
Covers type-erased pointer arguments with seeds. |
tests/expected/uninit/unresolved-calls/erased-pointer-seeded.expected |
Requires the function-pointer diagnostic. |
tests/expected/uninit/unresolved-calls/erased-pointer-plain.rs |
Covers type-erased pointer arguments without seeds. |
tests/expected/uninit/unresolved-calls/erased-pointer-plain.expected |
Requires the function-pointer diagnostic. |
tests/expected/uninit/unresolved-calls/entry-partial-seeded.rs |
Exercises partially initialized entry arguments with seeds. |
tests/expected/uninit/unresolved-calls/entry-partial-seeded.expected |
Requires union-read and unsupported-call failures. |
tests/expected/uninit/unresolved-calls/entry-partial-plain.rs |
Exercises partially initialized entry arguments without seeds. |
tests/expected/uninit/unresolved-calls/entry-partial-plain.expected |
Requires union-read and unsupported-call failures. |
tests/expected/uninit/unresolved-calls/entry-initialized-seeded.rs |
Exercises initialized entry arguments with seeds. |
tests/expected/uninit/unresolved-calls/entry-initialized-seeded.expected |
Requires a successful read check before call rejection. |
tests/expected/uninit/unresolved-calls/entry-initialized-plain.rs |
Exercises initialized entry arguments without seeds. |
tests/expected/uninit/unresolved-calls/entry-initialized-plain.expected |
Requires a successful read check before call rejection. |
tests/expected/uninit/unresolved-calls/direct-seeded.rs |
Provides a supported direct-call control with seeds. |
tests/expected/uninit/unresolved-calls/direct-seeded.expected |
Requires successful direct-call verification. |
tests/expected/uninit/unresolved-calls/direct-plain.rs |
Provides a supported direct-call control without seeds. |
tests/expected/uninit/unresolved-calls/direct-plain.expected |
Requires successful direct-call verification. |
kani-compiler/src/kani_middle/transform/check_uninit/ptr_uninit/uninit_visitor.rs |
Preserves pending checks and guards shim storage transfers. |
kani-compiler/src/kani_middle/transform/check_uninit/ptr_uninit/mod.rs |
Supplies compiler and instance context to the visitor. |
kani-compiler/src/kani_middle/transform/check_uninit/delayed_ub/instrumentation_visitor.rs |
Delegates unsupported-call diagnostics to the local visitor. |
kani-compiler/src/kani_middle/transform/check_uninit/delayed_ub/initial_target_visitor.rs |
Skips failed resolutions during seed collection. |
kani-compiler/src/kani_middle/points_to/points_to_analysis.rs |
Shares call resolution and preserves graph state on failure. |
kani-compiler/src/kani_middle/points_to/mod.rs |
Exports the shared call resolver. |
Review effort: Balanced
feliperodri
left a comment
There was a problem hiding this comment.
Thanks, the change is right. Dropping the operations already collected for an unresolved call lost real checks (the *pointer read in your custom-MIR example), and keeping them while still adding the unsupported check fixes it without hiding the limitation. Sharing one fallible resolver between the visitor and the points-to analysis, and looking bodies up per instance with checked_body, also removes the unwraps on unresolvable calls. Treating shims whose by-value storage may carry union state as unsupported is the conservative choice until state can flow through them.
Blocking: the merge of main brought in a toolchain where FieldDef::ty takes GenericArgs by value, so kani-compiler doesn't build (error[E0308] at uninit_visitor.rs:787, which is every red job). With the one-line fix below it builds, and locally all 22 unresolved-calls harnesses pass, as do the expected uninit (53) and kani Uninit (10) suites. Clippy and fmt are clean. I'll approve once CI is green.
A heads-up on #5196 (nested unions), which touches the same visit_terminator call handling: whichever lands second will need a rebase. After #5196, [MaybeUninit<T>; N] and tuples containing MaybeUninit are supported, so their clone shims (a.clone()) will hit your shim guard and be reported as unsupported. That's sound, but it's worth a follow-up issue to carry the state through those shims the way #5196 does for ordinary calls.
|
Thanks for the review. I merged current
On #5196: agreed, I'll open a follow-up issue about carrying initialization state through clone shims once it lands. |
feliperodri
left a comment
There was a problem hiding this comment.
Thanks for the update. The *args fix builds on the current toolchain, and both Copilot points are addressed: the visited set keeps the shim walk linear and is sound (a repeated type has either already made the result true or contributes false again), and points-to reuses the resolver's body. The merge with #5184 keeps both checks. Locally, the uninit expected (56) and kani Uninit (10) suites pass, and clippy and fmt are clean. The red CI jobs are the codegen_cache flake (fixed by #5207, the rest were cancelled by fail-fast) and a runner shutdown in perf-benchcomp. Approving.
A few non-blocking follow-ups:
try_resolve_instancein the visitor now callschecked_bodyfor every resolved call, which builds the callee's stable MIR and discards it. Availability doesn't need the body (Itemwithhas_body()or anyShim), so the visitor could skip building it and leave fetching the body to points-to, where caching it per instance would also help the dataflow iterations.unsupported_call_reasonis defined twice with the same message; one shared copy would avoid drift.let Some(body) = body else { return };in points-to cannot fail, since the resolver always returns a body for non-foreign items. Anexpectwith that invariant (or a comment) would keep a future change from silently dropping the call effect.
6154b31


Refs #3300
With
-Z uninit-checks, when the uninitialized-memory visitor cannot resolve a call (a function pointer, a trait object, ...),visit_terminatorreturns early. Everything it had already collected for that terminator is dropped: the checks on the call's operands and, in a statement-free entry block, the argument loads. Kani still reports that it does not support checks across such calls, but the actual uninitialized read in the operand is no longer reported.Example (
pending-ops-plain.rs, custom MIR so that the read is an operand of the call):The harness passes a pointer to an uninitialized heap byte. On
mainthe only failed check is the "calls through function pointers" diagnostic, and theindirect.safety_checkfor*pointeris missing. With this change both are reported.Change
Unsupportedafter the operations already collected, and push the target through the common path. The resulting order is entryLoadArgument, operand checks,Unsupported, then the call.checked_bodyinstead of the definition-levelhas_body(), so generated shims are covered. Seed collection skips failed resolutions instead of unwrapping, and points-to keeps its existing graph when it cannot follow a callee.StoreArgument/LoadArgument. No new shadow transfer is added.Testing
tests/expected/uninit/unresolved-callsadds 22 harnesses: direct calls, function pointers, trait objects, erased, wrapped and global function pointers, Fn-trait pointers, generated shims, pending operand reads and statement-free entry blocks with initialized companions. Each comes in a plain variant and a "seeded" variant whose ordinary byte copy gives delayed-UB analysis targets.On
mainsix of them fail: in the entry-block and pending-read cases theindirect.safety_checkproperties are missing from the results. With this change all uninit-checks suites pass.Kani CI for
88fec3b397(this branch merged with currentmain) in my fork passed the regression jobs on all five platforms, plus documentation, perf, LLBC and benchcomp. Format and Clippy and Cargo Deny also passed. On macOS 15 Intel,script-based-pre/verify_std_cmdhit its timeout on the first attempt and passed on a rerun.Not in this PR
FnDefcalls before this pass runs.UnionAsFieldstatement path is a separate issue.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
Disclosure: this change and description were prepared with the help of AI assistants.