Skip to content

Crash in enforcing loop invariant contract due to imprecise alias analysis #6021

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
SaswatPadhi opened this issue Apr 8, 2021 · 2 comments · Fixed by #6249
Closed

Crash in enforcing loop invariant contract due to imprecise alias analysis #6021

SaswatPadhi opened this issue Apr 8, 2021 · 2 comments · Fixed by #6249
Assignees
Labels
aws Bugs or features of importance to AWS CBMC users aws-high bug Code Contracts Function and loop contracts

Comments

@SaswatPadhi
Copy link
Contributor

CBMC version: 99f1a2e

Operating system: 10.15.7

Test case:

#include <assert.h>
#include <stdlib.h>

#define SIZE 8

struct blob { char *data; };

void main()
{
  struct blob *b = malloc(sizeof(struct blob));
  b->data = malloc(SIZE);

  b->data[5] = 0;
  for (unsigned i = 0; i < SIZE; i++)
    __CPROVER_loop_invariant(i <= SIZE)
  {
    b->data[i] = 1;
  }

  assert(b->data[5] == 0);
}

Exact command line resulting in the issue:

$ goto-cc test.c -o test.1.gb
$ goto-instrument --enforce-all-contracts test.1.gb test.2.gb

What behaviour did you expect:

goto-instrument would decompose the invariant contract to appropriate assertions and assumptions.

What happened instead:

goto-instrument crashes with a precondition violation:

$ goto-instrument --enforce-all-contracts test.1.gb test.2.gb
Reading GOTO program from 'test2.goto'
--- begin invariant violation report ---
Invariant check failed
File: ../util/pointer_expr.h:387 function: dereference_exprt
Condition: op.type().id() == ID_pointer
Reason: Precondition
Backtrace:
...

Additional Information:

In this case local_may_alias.get is imprecise and returns an unknown expression for the pointer being modified (b->data[i]).

We should avoid the crash and show a warning / error regarding the imprecision of the alias analysis.

@SaswatPadhi SaswatPadhi added aws Bugs or features of importance to AWS CBMC users bug Code Contracts Function and loop contracts labels Apr 8, 2021
SaswatPadhi added a commit to padhi-forks/cbmc that referenced this issue Apr 13, 2021
These regression tests currently fail due to imprecision in alias
analysis (see: diffblue#6021).

In future, we could either improve the alias analysis, or add manual
assigns clause annotations on these loops and make sure that the arrays
are correctly havoced.
SaswatPadhi added a commit to padhi-forks/cbmc that referenced this issue Apr 13, 2021
These regression tests currently fail due to imprecision in alias
analysis (see: diffblue#6021).

In future, we could either improve the alias analysis, or add manual
assigns clause annotations on these loops and make sure that the arrays
are correctly havoced.
@SaswatPadhi SaswatPadhi self-assigned this Apr 13, 2021
@SaswatPadhi
Copy link
Contributor Author

SaswatPadhi commented Apr 13, 2021

Based on discussions with @tautschnig and @mww-aws:

  • we should allow __CPROVER_assigns annotations on loops
  • we should show an error in this case and instruct the user to use __CPROVER_assigns since automatic inference of the modified set was imprecise

SaswatPadhi added a commit to padhi-forks/cbmc that referenced this issue Apr 14, 2021
These regression tests currently fail due to imprecision in alias
analysis (see: diffblue#6021).

In future, we could either improve the alias analysis, or add manual
assigns clause annotations on these loops and make sure that the arrays
are correctly havoced.
@SaswatPadhi
Copy link
Contributor Author

Removed the pending merge label.

The commit that referred to this issue added some KNOWNBUG regression tests that should pass once this issue is resolved. The commit does not fix this issue. Sorry if that was confusing.

jezhiggins pushed a commit to jezhiggins/cbmc that referenced this issue Apr 23, 2021
These regression tests currently fail due to imprecision in alias
analysis (see: diffblue#6021).

In future, we could either improve the alias analysis, or add manual
assigns clause annotations on these loops and make sure that the arrays
are correctly havoced.
@jimgrundy jimgrundy added aws-high aws Bugs or features of importance to AWS CBMC users and removed aws Bugs or features of importance to AWS CBMC users labels Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws Bugs or features of importance to AWS CBMC users aws-high bug Code Contracts Function and loop contracts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants