Skip to content

Contracts: --no-assertions keeps the checks of contracts - #9576

Open
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:kiro/contracts-no-assertions
Open

tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:kiro/contracts-no-assertions

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

goto_convertt::convert_assert marks every assertion that it converts as user-provided. The contracts instrumentation builds several of its checks as code_assertt and goto-converts them, so they count as the user's assertions too:

  • the check that a loop invariant is inductive (DFCC's loop_invariant_step, and that of the older instrumentation in contracts.cpp, including the decreases clause's checks);
  • DFCC's checks of requires clauses (when replacing a call) and of ensures clauses (when checking a contract).

--no-assertions is to drop the user's assertions only, but transform_assertions_assumptions then turns these checks into SKIP, while the loop and the call still assume what they would have checked. For example, with --dfcc main --apply-loop-contracts --signed-overflow-check --no-assertions,

int main()
{
  int i = 0;
  while(i < 10)
    __CPROVER_loop_invariant(i == 0)
    {
      i++;
    }
  int x = 2147483647 + i;
  return x;
}

reports VERIFICATION SUCCESSFUL, although the invariant is not inductive and the addition overflows. The same holds for a false postcondition under --enforce-contract and a violated precondition under --replace-call-with-contract.

The instrumentation now marks its checks as not user-provided (a helper mark_contract_checks in contracts/utils.{h,cpp} after each such goto_convert), as the other generated checks are, which --no-built-in-assertions drops.

Tests: loop_contracts_no_assertions, contracts_ensures_no_assertions and contracts_requires_no_assertions (in contracts-dfcc, run in both the DFCC and the non-DFCC mode) fail before and pass now. contracts, contracts-dfcc (both modes), goto-instrument and cbmc CORE pass.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

goto_convert marks the assertions that it converts as user-provided, and
the code that instruments loop and function contracts converts its
checks so: the check that a loop invariant is inductive (DFCC's and the
older instrumentation's, and the decreases clause's), and those of
requires and ensures clauses. --no-assertions, which is to ignore the
user's assertions, thus dropped them, while the loop and the calls still
assumed what they would have checked: a loop invariant that is not
inductive verified successfully. The instrumentation now marks its
checks as not user-provided (as the other generated checks are, which
--no-built-in-assertions drops).

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 12:16

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.29%. Comparing base (4853dbe) to head (2c491a4).
⚠️ Report is 4 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9576      +/-   ##
===========================================
- Coverage    81.29%   81.29%   -0.01%     
===========================================
  Files         1725     1725              
  Lines       191655   191677      +22     
  Branches        73       73              
===========================================
+ Hits        155809   155824      +15     
- Misses       35846    35853       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@feliperodri feliperodri added the Code Contracts Function and loop contracts label Nov 25, 2026

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

Code Contracts Function and loop contracts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants