Skip to content

Remove warn_and_top_on_zero from BaseInvariant for division by zero#2016

Draft
sim642 wants to merge 1 commit intomasterfrom
div-by-zero-invariant-2
Draft

Remove warn_and_top_on_zero from BaseInvariant for division by zero#2016
sim642 wants to merge 1 commit intomasterfrom
div-by-zero-invariant-2

Conversation

@sim642
Copy link
Copy Markdown
Member

@sim642 sim642 commented May 5, 2026

This is the continuation of #1892 regarding the top-ification aspect.

I tried to just remove it and no tests fail. But I'll see on sv-benchmarks if this actually matters sometime.

Question

In #1892 (comment):

Okay, so here specifically the question is what the backward transfer function should be for c = a / [0;0], given some value for c, how can one refine a? And what about c = a / [0;1]...

The strange thing is that the warn_and_top_on_zero code is about the second argument, not the first one.

And it looks like it just tries to avoid a definite division by zero in the calculations that follow, e.g. ID.div a b. But doing so isn't actually a problem: once we're doing the refinement, we've already forward-evaluated that exact calculation with the zero divisor without issues. I don't think the abstract division operator in int domains should fail because of that.
Also note that the second argument (without top-ification) would still be, e.g., [0,0], not bottom. So it's not triggering ArithmeticOnIntegerBot by doing that.

Maybe some git archeology is needed for this code. Perhaps it was added at a time when the division operators in int domains had problems with doing this and warn_and_top_on_zero was added to work around them.

TODO

  • sv-benchmarks

@sim642 sim642 self-assigned this May 5, 2026
@sim642 sim642 added the cleanup Refactoring, clean-up label May 5, 2026
@sim642
Copy link
Copy Markdown
Member Author

sim642 commented May 5, 2026

Maybe some git archeology is needed for this code. Perhaps it was added at a time when the division operators in int domains had problems with doing this and warn_and_top_on_zero was added to work around them.

This is essentially reverting ae01aba. Its previous commit added the following test:

int tmp;
int p_9 = 60;
tmp = (p_9 +1) % 0;
if ((p_9 +1) % 0) {
tmp = 1;
}

The test doesn't contain any checks though. But it's also not crashing after the revert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup Refactoring, clean-up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant