Skip to content

Value-set filtering: gracefully handle pointer arithmetic #4697

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 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions regression/cbmc/Pointer_Arithmetic16/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdlib.h>

int main()
{
int *ptr = malloc(sizeof(int) * 2);
int *other_ptr;
if(ptr + 1 == other_ptr)
return 0;
__CPROVER_assert(0, "");
}
11 changes: 11 additions & 0 deletions regression/cbmc/Pointer_Arithmetic16/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
main.c

^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
^warning: ignoring
--
Value-set filtering did not take into account arithemetic over pointers and thus
spuriously failed an invariant.
19 changes: 9 additions & 10 deletions src/goto-symex/symex_goto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ void goto_symext::apply_goto_condition(
/// Try to evaluate a simple pointer comparison.
/// \param operation: ID_equal or ID_not_equal
/// \param symbol_expr: The symbol expression in the condition
/// \param other_operand: The other expression in the condition - must pass
/// goto_symex_is_constant, and since it is pointer-typed it must therefore
/// be an address of expression, a typecast of an address of expression or a
/// null pointer
/// \param other_operand: The other expression in the condition; we only support
/// an address of expression, a typecast of an address of expression or a
/// null pointer, and return an empty optionalt in all other cases
/// \param value_set: The value-set for looking up what the symbol can point to
/// \param language_mode: The language mode
/// \param ns: A namespace
Expand All @@ -90,12 +89,12 @@ static optionalt<renamedt<exprt, L2>> try_evaluate_pointer_comparison(
const constant_exprt *constant_expr =
expr_try_dynamic_cast<constant_exprt>(other_operand);

INVARIANT(
skip_typecast(other_operand).id() == ID_address_of ||
(constant_expr && constant_expr->get_value() == ID_NULL),
"An expression that passes goto_symex_is_constant and has "
"pointer-type must be an address of expression (possibly with some "
"typecasts) or a null pointer");
if(
skip_typecast(other_operand).id() != ID_address_of &&
(!constant_expr || constant_expr->get_value() != ID_NULL))
{
return {};
}

const ssa_exprt *ssa_symbol_expr =
expr_try_dynamic_cast<ssa_exprt>(symbol_expr);
Expand Down