Repository navigation
Fix SMT pointer type dependency discovery - #9159
Open
chaizhenhua wants to merge 1 commit into
Open
chaizhenhua wants to merge 1 commit into
chaizhenhua wants to merge 1 commit into
Conversation
Pointers are encoded as bitvectors, but type discovery currently declares their pointee datatypes. A recursive Leaf -> Internal pointer -> Leaf value type can consequently use a struct-tag alias before it has been registered, throwing map::at during SMT conversion. Separate sort and expression dependencies in the existing type visitor. Pointer targets only require expression discovery, including implicit VLA sizes. Track visited tags together with their discovery mode so a pointer visit cannot suppress a later by-value visit. Size expressions continue to discover the full dependencies of their operands. Add focused regressions for both recursive entry orders, mixed pointer/value visits, nested VLA sizes, complex/state sorts, bitvector pointer arithmetic, and recursive unions. The recursive pointer test fails on the unmodified develop implementation and passes with this change. Validation: clang-format 18 on changed lines; SMT unit tests (48 cases, 237 assertions); all unit tests (620 cases, 19494 assertions) and expected failures; cbmc-CORE (1128 passed, 67 skipped); smt2_solver-CORE (42 passed, 2 skipped); seven existing pointer/VLA regressions using Z3; both recursive alias entry orders produce the expected counterexample through Z3.
chaizhenhua
requested review from
TGWDB,
kroening,
martin-cs,
peterschrammel and
tautschnig
as code owners
September 10, 2026 00:53
feliperodri
pushed a commit
to tautschnig/kani
that referenced
this pull request
Nov 20, 2026
…ecking#5203) ## Summary Lower core's native comparison and pattern assertion failures through Kani's existing GOTO panic model. On the current PR base, this reduces the GOTO program and reports failures at the user's assertion with a fixed diagnostic. A CBMC SMT conversion failure in the Challenge 18 `ChunksExactMut::nth_back` harness on its pinned toolchain motivated the change. ## Additional implementation notes - Match `assert_failed`, `assert_failed_inner`, and `assert_matches_failed` in the same core module as `panic_fmt`. Apply the rewrite before reachability in GOTO, which provides the `PanicStub` hook. - Check the enabled user-stub map once per codegen unit. An active stub for any of the three assertion entries disables their lowering for that unit. This preserves an `assert_failed_inner` stub when the assertion calls an outer entry first. The formatter helper guard also uses the enabled stub map. - `RustcIntrinsicsPass` prepends a static diagnostic and keeps the original MIR operands in the rewritten call to `panic_stub`. The GOTO hook reads operand 0 as the message and evaluates the other operands in order for their safety checks before emitting the assertion property. - Clear the original generic arguments when redirecting to the non-generic `panic_stub`. This also applies to the existing rewrite of generic panic functions such as `begin_panic::<M>`. - With the default assertion configuration, `assert_ne!` and `debug_assert_eq!` report the comparison expression. `core::assert_eq!` and `assert_matches!` report the new fixed diagnostics at the assertion lines. ## Diagnostics Rewritten comparison assertions report `assertion failed`. Rewritten pattern assertions report `pattern assertion failed`. These fixed diagnostics also apply when a literal custom message is supplied. The base reports the runtime-formatting placeholder from `core::panicking` for the same native assertions. The model retains the caller's construction of `fmt::Arguments` and evaluates the original operands before emitting the panic property and ending the path. Formatting callbacks such as `Debug::fmt` are outside the modeled panic path. ## Validation Validated revision `dc85d0d` against upstream base `c25a57bc` with `nightly-2026-11-18`, CBMC 6.11.0, and CVC5 1.3.0. - The diagnostics regression observes the user's own messages for stubs of `assert_failed` and `assert_failed_inner`. Separate `assert_eq!` and `assert_matches!` harnesses check the inner stub with distinct expected messages. - The defensive inactive-stub regression uses raw compiler flags to allow the annotation while leaving the stub pass disabled. The explicit MIR regression checks that a null pointer dereference in a projected operand is reported in a `should_panic` harness. - The `Assert`, `Stubbing`, and `FmtDerive` groups report 59 passes with two existing fixme cases ignored. All 53 expected-output cases selected by `assert panic stub` and all 25 LLBC cases pass. ### Validation clarification The standalone CVC5 harness passes on upstream base `c25a57bc` and does not reproduce the original Challenge 18 SMT conversion failure there. On that base the demonstrated benefits are a smaller GOTO program and improved assertion diagnostics. `assert_failed_native.rs` and `native-assert-projected-argument.rs` pass on both the base and the revision as regression guards for assertion, panic, and safety-check behavior. The original Challenge 18 end-to-end result uses its project pin. The PR base's nightly stops while compiling that project's `core`, before the Challenge 18 harness can run. ### GOTO program size Set `main_checkout` and `candidate_checkout` to the absolute paths of the independently built base and PR checkouts, then run the script with Bash. It runs the same fixture for both harnesses in fresh temporary directories. ```sh set -eu KANI_MAIN="$main_checkout/scripts/kani" KANI_CANDIDATE="$candidate_checkout/scripts/kani" fixture="$candidate_checkout/tests/kani/Assert/assert_failed_native.rs" for KANI in "$KANI_MAIN" "$KANI_CANDIDATE"; do for harness in check_failed_equality check_failed_pattern; do ( run_dir="$(mktemp -d)" trap 'rm -rf -- "$run_dir"' EXIT cp "$fixture" "$run_dir/native.rs" cd "$run_dir" printf '%s %s\n' "$KANI" "$harness" "$KANI" native.rs -Z unstable-options --no-assert-overrides --exact \ --harness "$harness" --only-codegen --keep-temps wc -c ./*.symtab.out python3 -c 'import json, sys; print(len(json.load(open(sys.argv[1]))))' ./*.pretty_name_map.json ) done done ``` | Harness | Base symbol table bytes | Revised symbol table bytes | Base pretty-name entries | Revised pretty-name entries | | --- | ---: | ---: | ---: | ---: | | `check_failed_equality` | 2,210,210 | 24,478 | 7,424 | 160 | | `check_failed_pattern` | 2,207,361 | 17,297 | 7,413 | 133 | Extends the panic lowering from model-checking#4169. The pinned-toolchain SMT failure is related to diffblue/cbmc#9159. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: Mingzhi Gao <gmz563527968@126.com> Co-authored-by: v3risec <272978695+v3risec@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Recursive pointer types can make SMT conversion use a struct-tag alias
before registration and throw
map::at. Keep pointer targets in the existingtype visitor, but discover their expression dependencies without declaring
unneeded pointee sorts. Visiting a tag in this mode does not suppress a later
by-value visit, and VLA size expressions retain their full dependencies.
This change only fixes pointer type dependency discovery. It makes no solver
performance claim and does not change response batching, binders, or unknown
expression handling.
Validation includes a failing baseline regression, 48 SMT unit cases, the
complete unit suite,
cbmc-CORE,smt2_solver-CORE, seven existing pointer/VLAregressions through Z3, and both recursive alias entry orders producing the
expected counterexample. Existing CORE exclusions remain unchanged.