Skip to content

Add --expand-pointer-predicates to goto-instrument #4332

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

Conversation

karkhaz
Copy link
Collaborator

@karkhaz karkhaz commented Mar 5, 2019

This patchset adds __CPROVER_points_to_valid_memory. It tells CBMC that an object of a particular size is pointed to by a pointer, and can be used in assertions and assumptions.

It also adds the --expand-pointer-predicates flag to goto-instrument, which expands the __CPROVER_points_to_valid_memory directive. This is in preparation for future commits that will introduce more pointer predicates having side effects, which will need to be expanded into multiple instructions.

@karkhaz karkhaz force-pushed the kk-expand-pointer-predicates branch 2 times, most recently from 9deb9dd to 8cf8e62 Compare March 6, 2019 14:59
@karkhaz karkhaz assigned tautschnig and romainbrenguier and unassigned karkhaz Mar 6, 2019
@karkhaz karkhaz force-pushed the kk-expand-pointer-predicates branch 2 times, most recently from e5222d7 to c844655 Compare March 6, 2019 15:46
karkhaz and others added 3 commits March 6, 2019 10:51
The --expand-pointer-predicates pass resolves pointer predicates
(util/pointer_predicates.{cpp, h}) which have side effects and
so require expanding into multiple instructions.
Currently, the only such predicate that needs to be expanded is
__CPROVER_points_to_valid_memory (name subject to change).

The __CPROVER_points_to_valid_memory predicates takes two parameters,
a pointer and a size. Semantically,
__CPROVER_points_to_valid_memory(p, size) should be true if and only
if p points to a memory object which is valid to read/write for at
least size bytes past p. When used in assertions, this will be checked
in a similar manner to how --pointer-check checks validity of a
dereference. When used in assumptions, this predicate creates (if none
exists already) an object for p to refer to, using
local_bitvector_analysis to make that determination, and then makes
assumptions (again corresponding to the assertions made by
--pointer-check) about that object.
This commit adds support for a one-argument form of
__CPROVER_points_to_valid_memory, taking only a pointer, with no size.

If ptr has type T*, then __CPROVER_points_to_valid_memory(ptr) is
equivalent to __CPROVER_points_to_valid_memory(ptr, sizeof(T)).
@karkhaz karkhaz force-pushed the kk-expand-pointer-predicates branch from c844655 to bc07b78 Compare March 6, 2019 15:51
@tautschnig
Copy link
Collaborator

@karkhaz This is still failing CI.

@tautschnig tautschnig assigned karkhaz and unassigned romainbrenguier Mar 7, 2019
@karkhaz karkhaz force-pushed the kk-expand-pointer-predicates branch from bc07b78 to 2ddb39b Compare March 13, 2019 14:25
This commit ensures that the second argument to the
__CPROVER_points_to_valid_memory directive can be coerced to a size_t,
and adds a test to check for the failing case.
@karkhaz karkhaz force-pushed the kk-expand-pointer-predicates branch from 2ddb39b to f53b62b Compare March 13, 2019 16:20
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 2ddb39b).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/104266680

@karkhaz
Copy link
Collaborator Author

karkhaz commented Mar 13, 2019

@tautschnig do you know why the AWS CodeBuild build is failing? I tried re-pushing, it doesn't help.

Also, if I want to diagnose this problem in the future, what should I do? I can't currently see the results of that build.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: f53b62b).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/104280806

CORE
main.c
--apply-code-contracts
^EXIT=1$
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the cause of the Windows failure: goto-cl exits with exit code 64 on errors (cf. other intentionally-failing tests, git grep -w 64 regression/ansi-c).

@@ -34,6 +34,8 @@ Author: Daniel Kroening, kroening@kroening.com
#include "anonymous_member.h"
#include "padding.h"

bool is_lvalue(const exprt &expr);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be necessary, use #include <util/expr_util.h>

}

exprt same_object_expr;
if(expr.arguments().size() == 2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is established above, no need to check again.

{
UNREACHABLE;
}
same_object_expr.add_source_location() = source_location;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe points_to_valid_memory should actually take a source_locationt as an additional argument?

new_tmp_symbol(const typet &type, const source_locationt &source_location);
};

bool is_lvalue(const exprt &expr);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be necessary, use #include <util/expr_util.h>

d->source_location = assume_expr.source_location();
const symbol_exprt obj =
new_tmp_symbol(object_type, d->source_location).symbol_expr();
d->code = code_declt(obj);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use the recently added API doing assume_code.add(goto_programt::make_decl(...)); to combine most of the above into a single instruction.

goto_programt::targett a = assume_code.add_instruction(ASSIGN);
a->source_location = assume_expr.source_location();
a->code = code_assignt(pointer_expr, rhs);
a->code.add_source_location() = assume_expr.source_location();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use assume_code.add(goto_programt::make_assign(...));

{
return get_fresh_aux_symbol(
type,
id2string(source_location.get_function()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

If possible, please use the actual function identifier as found in the function map instead of this user-level name. This will require passing in such an additional irep_idt to new_tmp_symbol.

#include "namespace.h"
#include "arith_tools.h"
#include <algorithm>
#include <unordered_set>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Leave the STL includes where they were, separated by a blank line.

{
err_location(f_op);
error().source_location = f_op.source_location();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer for those changes to be squashed into the earlier commit as otherwise that code wouldn't compile (which makes bisecting hard).

@TGWDB
Copy link
Contributor

TGWDB commented May 11, 2021

Closing as this has been untouched for a couple of years. Please feel free to re-open/update if you believe this closure is erroneous.

@TGWDB TGWDB closed this May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants