Skip to content

Check for validity of pointers in assigns clause #6077

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 1 commit into from
May 13, 2021

Conversation

ArenBabikian
Copy link
Contributor

Consider the following example:

void bar(int *x, int *y) __CPROVER_assigns(*x, *y)
{
  *x = 3;
  if(y != NULL)
    *y = 5;
}

void foo(int *x) __CPROVER_assigns(*x)
{
  bar(x, NULL);
  *x = 3;
}

The potential problem in this case is that foo calls bar by passing a null pointer. Of course, considering the contents of bar, this will not be problematic. However, the assigns clause for bar is not aware of what is inside bar, so the assigns clause previously could not handle the null pointer.

This PR adds support for such cases, by checking for passed null pointers at the goto program level.

Note: currently, this PR only supports pointers, which is required for function contracts for the coreJSON project.

  • 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.
  • 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).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Copy link
Collaborator

@feliperodri feliperodri left a comment

Choose a reason for hiding this comment

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

I few minor comments.

@feliperodri feliperodri added aws Bugs or features of importance to AWS CBMC users Code Contracts Function and loop contracts labels May 6, 2021
@feliperodri feliperodri changed the title Supports passing NULL to a function that may assign to the corresponding parameter Avoid havoc of NULL assignable symbols May 6, 2021
@feliperodri feliperodri changed the title Avoid havoc of NULL assignable symbols Check for validity of pointers in assigns clause May 6, 2021
Copy link
Collaborator

@feliperodri feliperodri left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@SaswatPadhi SaswatPadhi left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, but I left a few minor comments.

Also, please check why the builds are failing.

@codecov
Copy link

codecov bot commented May 11, 2021

Codecov Report

Merging #6077 (d5402d9) into develop (4c14789) will increase coverage by 0.59%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6077      +/-   ##
===========================================
+ Coverage    74.52%   75.12%   +0.59%     
===========================================
  Files         1447     1447              
  Lines       157808   157825      +17     
===========================================
+ Hits        117610   118563     +953     
+ Misses       40198    39262     -936     
Impacted Files Coverage Δ
src/goto-instrument/code_contracts.cpp 85.03% <100.00%> (+0.29%) ⬆️
src/ansi-c/expr2c.cpp 69.20% <0.00%> (+0.09%) ⬆️
src/solvers/smt2/smt2_conv.cpp 60.63% <0.00%> (+0.22%) ⬆️
src/solvers/lowering/byte_operators.cpp 92.16% <0.00%> (+0.36%) ⬆️
src/util/pointer_expr.h 77.71% <0.00%> (+0.36%) ⬆️
src/ansi-c/c_typecast.cpp 79.00% <0.00%> (+0.55%) ⬆️
src/goto-programs/goto_program.h 91.63% <0.00%> (+0.64%) ⬆️
src/goto-instrument/wmm/cycle_collection.cpp 88.04% <0.00%> (+3.26%) ⬆️
src/goto-instrument/rw_set.h 47.27% <0.00%> (+5.45%) ⬆️
src/goto-instrument/wmm/event_graph.h 71.29% <0.00%> (+6.48%) ⬆️
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 25a7b36...d5402d9. Read the comment docs.

Copy link
Contributor

@SaswatPadhi SaswatPadhi left a comment

Choose a reason for hiding this comment

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

Almost there. A couple of previous comments that are unaddressed:

This adds support for the cases where a null pointer is passed as
a parameter to a function that may assign to it. We add checks in
goto program to handle such instances as special cases of assigns
clause handling.
Copy link
Contributor

@SaswatPadhi SaswatPadhi left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for all the changes! 😄

Copy link
Contributor

@chrisr-diffblue chrisr-diffblue left a comment

Choose a reason for hiding this comment

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

LGTM

@SaswatPadhi SaswatPadhi merged commit 0b4a3e8 into diffblue:develop May 13, 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 bugfix Code Contracts Function and loop contracts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants