Emit explicit contract:: symbols for functions with contracts#4612
Open
tautschnig wants to merge 1 commit into
Open
Emit explicit contract:: symbols for functions with contracts#4612tautschnig wants to merge 1 commit into
contract:: symbols for functions with contracts#4612tautschnig wants to merge 1 commit into
Conversation
CBMC's DFCC contract instrumentation (`--enforce-contract` / `--replace-call-with-contract`) expects a dedicated `contract::<fn>` symbol to exist for any function carrying a contract. For C inputs this symbol is created by the ANSI-C typechecker, which also moves the contract clauses (e.g. `c_spec_assigns`) onto it. Kani builds goto-programs directly and never runs that typechecker, so the symbol was absent. CBMC used to paper over this by deriving an empty contract symbol from the function on the fly, but that fallback was removed for soundness in diffblue/cbmc#8739, turning the missing symbol into a hard error and breaking every `#[kani::proof_for_contract]` harness. Synthesize the companion `contract::<name>` symbol during symbol-table serialization. It shares the function's contract-bearing type, has no body, and is marked as a property, reconstructing exactly the symbol CBMC's typechecker (and its old fallback) produced. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Kani’s CBMC symbol-table serialization to synthesize the dedicated contract::<fn> symbols required by CBMC’s DFCC contract instrumentation, restoring compatibility with newer CBMC versions where the previous fallback behavior was removed.
Changes:
- Add a helper to derive a
contract::<name>symbol for any function symbol carrying a contract. - Emit the companion
contract::<name>symbol duringgoto_program::SymbolTable -> irep::SymbolTableserialization.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+720
to
+727
| fn to_contract_irep(&self, mm: &MachineModel) -> super::Symbol { | ||
| let mut contract_symbol = self.to_irep(mm); | ||
| contract_symbol.name = format!("contract::{}", self.name).into(); | ||
| contract_symbol.is_property = true; | ||
| // The contract symbol is a pure specification and carries no body. | ||
| contract_symbol.value = Irep::nil(); | ||
| contract_symbol | ||
| } |
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.
CBMC's DFCC contract instrumentation (
--enforce-contract/--replace-call-with-contract) expects a dedicatedcontract::<fn>symbol to exist for any function carrying a contract. For C inputs this symbol is created by the ANSI-C typechecker, which also moves the contract clauses (e.g.c_spec_assigns) onto it.Kani builds goto-programs directly and never runs that typechecker, so the symbol was absent. CBMC used to paper over this by deriving an empty contract symbol from the function on the fly, but that fallback was removed for soundness in diffblue/cbmc#8739, turning the missing symbol into a hard error and breaking every
#[kani::proof_for_contract]harness.Synthesize the companion
contract::<name>symbol during symbol-table serialization. It shares the function's contract-bearing type, has no body, and is marked as a property, reconstructing exactly the symbol CBMC's typechecker (and its old fallback) produced.This is a necessary (though not necessarily sufficient) change to enable upgrading to newer CBMC versions.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.