Skip to content

Commit e794441

Browse files
authored
Merge pull request #4697 from tautschnig/fix-value-set-filtering
Value-set filtering: gracefully handle pointer arithmetic
2 parents 0888187 + e739fbb commit e794441

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdlib.h>
2+
3+
int main()
4+
{
5+
int *ptr = malloc(sizeof(int) * 2);
6+
int *other_ptr;
7+
if(ptr + 1 == other_ptr)
8+
return 0;
9+
__CPROVER_assert(0, "");
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring
9+
--
10+
Value-set filtering did not take into account arithemetic over pointers and thus
11+
spuriously failed an invariant.

src/goto-symex/symex_goto.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ void goto_symext::apply_goto_condition(
7070
/// Try to evaluate a simple pointer comparison.
7171
/// \param operation: ID_equal or ID_not_equal
7272
/// \param symbol_expr: The symbol expression in the condition
73-
/// \param other_operand: The other expression in the condition - must pass
74-
/// goto_symex_is_constant, and since it is pointer-typed it must therefore
75-
/// be an address of expression, a typecast of an address of expression or a
76-
/// null pointer
73+
/// \param other_operand: The other expression in the condition; we only support
74+
/// an address of expression, a typecast of an address of expression or a
75+
/// null pointer, and return an empty optionalt in all other cases
7776
/// \param value_set: The value-set for looking up what the symbol can point to
7877
/// \param language_mode: The language mode
7978
/// \param ns: A namespace
@@ -90,12 +89,12 @@ static optionalt<renamedt<exprt, L2>> try_evaluate_pointer_comparison(
9089
const constant_exprt *constant_expr =
9190
expr_try_dynamic_cast<constant_exprt>(other_operand);
9291

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

10099
const ssa_exprt *ssa_symbol_expr =
101100
expr_try_dynamic_cast<ssa_exprt>(symbol_expr);

0 commit comments

Comments
 (0)