Skip to content

Turn debug assertions into CBMC constraints when CBMC is used #666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 17, 2025

Conversation

hanno-becker
Copy link
Contributor

Previously, runtime assertions via debug_assert_xxx and CBMC
assertions via cassert(...) were separate.

This commit modifies the implementation of the debug assertion
macros so that when CBMC is used, debug assertions are intepreted
as proof obligations.

This removes some redundancy and non-uniformity in the code,
and also reduces the likelihood that debug assertions and CBMC
contracts get out of sync. In some case, this actually happened,
and the commit fixes this. The commit also adds further bounds
assertions in alignment with pre/post conditions.

A slight nuisance is that the debug assertions cannot flatten
nested structures like polyvec for the bounds check, running
into issue diffblue/cbmc#8570. We
work around this by introducing a new xxx_2d (for 2-dimensional)
macro which takes two dimensions and uses a two-step array
access, circumventing the above CBMC issue.

@hanno-becker hanno-becker added enhancement New feature or request CBMC labels Jan 16, 2025
@hanno-becker hanno-becker added this to the beta milestone Jan 16, 2025
@hanno-becker hanno-becker marked this pull request as ready for review January 16, 2025 12:08
@hanno-becker hanno-becker requested a review from a team January 16, 2025 12:08
@hanno-becker hanno-becker force-pushed the asserts2 branch 2 times, most recently from ce87d46 to 27519b4 Compare January 17, 2025 08:26
Copy link
Contributor

@mkannwischer mkannwischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still some >= 0 loop invariants in here. Those will have to be removed when this is rebased on #664.

@hanno-becker hanno-becker force-pushed the asserts2 branch 2 times, most recently from 8ce0b89 to 998281f Compare January 17, 2025 09:16
Previously, runtime assertions via debug_assert_xxx and CBMC
assertions via cassert(...) were separate.

This commit modifies the implementation of the debug assertion
macros so that when CBMC is used, debug assertions are intepreted
as proof obligations.

This removes some redundancy and non-uniformity in the code,
and also reduces the likelihood that debug assertions and CBMC
contracts get out of sync. In some case, this actually happened,
and the commit fixes this. The commit also adds further bounds
assertions in alignment with pre/post conditions.

A slight nuisance is that the debug assertions cannot flatten
nested structures like polyvec for the bounds check, running
into issue diffblue/cbmc#8570. We
work around this by introducing a new `xxx_2d` (for 2-dimensional)
macro which takes two dimensions and uses a two-step array
access, circumventing the above CBMC issue.

Signed-off-by: Hanno Becker <[email protected]>
Copy link
Contributor

@mkannwischer mkannwischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes!

@hanno-becker hanno-becker merged commit b79f6f1 into main Jan 17, 2025
124 checks passed
@hanno-becker hanno-becker deleted the asserts2 branch January 17, 2025 09:55
@mkannwischer mkannwischer modified the milestones: beta, v1.0.0-alpha.2 Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CBMC enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants