Skip to content

__CPROVER_enum_is_in_range() fails on enum value returning functions. #6586

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

Closed
ilvn opened this issue Jan 18, 2022 · 3 comments · Fixed by #6594
Closed

__CPROVER_enum_is_in_range() fails on enum value returning functions. #6586

ilvn opened this issue Jan 18, 2022 · 3 comments · Fixed by #6594

Comments

@ilvn
Copy link
Contributor

ilvn commented Jan 18, 2022

CBMC version: 5.48.0 (cbmc-5.48.0)
Operating system: macOS 12.1 (21C52)
Exact command line resulting in the issue: cbmc --enum-range-check x.c
What behaviour did you expect: VERIFICATION SUCCESSFUL
What happened instead: VERIFICATION FAILED

This is the test code

// x.c

enum enm { first, second, third, fourth, };

static enum enm efunc(void)
{
    return second;
}

int main(void)
{
    enum enm e = efunc();
    __CPROVER_assert(__CPROVER_enum_is_in_range(e), "enum failure");
    return (e);
}

The verification result when verified with cbmc --enum-range-check x.c

** Results:
x.c function main
[main.enum-range-check.1] line 12 enum range check in return_value_efunc: FAILURE
[main.enum-range-check.2] line 12 enum range check in return_value_efunc: SUCCESS
[main.assertion.1] line 13 enum failure: SUCCESS
[main.enum-range-check.3] line 13 enum range check in e: SUCCESS
[main.enum-range-check.4] line 13 enum range check in e: SUCCESS
[main.enum-range-check.5] line 13 enum range check in e: SUCCESS
[main.enum-range-check.6] line 13 enum range check in e: SUCCESS
[main.enum-range-check.7] line 14 enum range check in e: SUCCESS

** 1 of 8 failed (2 iterations)
VERIFICATION FAILED

The verification reports failure in line 12 enum enm e = efunc();.
Replacing function call with e.g. enum enm e = second; will give successful verification, as expected.

@tautschnig tautschnig self-assigned this Jan 18, 2022
@tautschnig
Copy link
Collaborator

Thank you for your report! It seems that we wrongly insert this check multiple times, where one of these insertions is before even making an assignment to the value. (Note how lines 12 and 13 appear multiple times in the output.)

@tautschnig tautschnig added the bug label Jan 18, 2022
tautschnig added a commit to tautschnig/cbmc that referenced this issue Jan 19, 2022
We already disabled these checks for assignment left-hand sides, but
need to do the same for function calls. Else we'd be asserting validity
before the value has been assigned.

Fixes: diffblue#6586

Co-authored-by: Ilia Levin <[email protected]>
@tautschnig
Copy link
Collaborator

Thank you again for your detailed report. This will be fixed once #6594 has been merged.

tautschnig added a commit to tautschnig/cbmc that referenced this issue Jan 19, 2022
We already disabled these checks for assignment left-hand sides, but
need to do the same for function calls. Else we'd be asserting validity
before the value has been assigned.

Fixes: diffblue#6586, diffblue#6451

Co-authored-by: Ilia Levin <[email protected]>
@ilvn
Copy link
Contributor Author

ilvn commented Jan 20, 2022

Great! Thank you for the fix.

@tautschnig tautschnig removed their assignment Jan 27, 2022
tautschnig added a commit to tautschnig/cbmc that referenced this issue Jan 27, 2022
We already disabled these checks for assignment left-hand sides, but
need to do the same for function calls. Else we'd be asserting validity
before the value has been assigned.

Fixes: diffblue#6586, diffblue#6451

Co-authored-by: Ilia Levin <[email protected]>
tautschnig added a commit to tautschnig/cbmc that referenced this issue Jan 28, 2022
We already disabled these checks for assignment left-hand sides, but
need to do the same for function calls. Else we'd be asserting validity
before the value has been assigned.

Fixes: diffblue#6586, diffblue#6451

Co-authored-by: Ilia Levin <[email protected]>
tautschnig added a commit to tautschnig/cbmc that referenced this issue Feb 1, 2022
We already disabled these checks for assignment left-hand sides, but
need to do the same for function calls. Else we'd be asserting validity
before the value has been assigned.

Fixes: diffblue#6586, diffblue#6451

Co-authored-by: Ilia Levin <[email protected]>
tautschnig added a commit to tautschnig/cbmc that referenced this issue Feb 1, 2022
We already disabled these checks for assignment left-hand sides, but
need to do the same for function calls. Else we'd be asserting validity
before the value has been assigned.

Fixes: diffblue#6586, diffblue#6451

Co-authored-by: Ilia Levin <[email protected]>
tautschnig added a commit to tautschnig/cbmc that referenced this issue Feb 6, 2022
We already disabled these checks for assignment left-hand sides, but
need to do the same for function calls. Else we'd be asserting validity
before the value has been assigned.

Fixes: diffblue#6586, diffblue#6451

Co-authored-by: Ilia Levin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants