Skip to content

Commit

Permalink
Merge pull request diffblue#8445 from tautschnig/move-is_null_pointer
Browse files Browse the repository at this point in the history
Move is_null_pointer to constant_exprt
  • Loading branch information
tautschnig authored Sep 13, 2024
2 parents f0543bd + 7b47e9f commit dc8793c
Show file tree
Hide file tree
Showing 27 changed files with 58 additions and 57 deletions.
6 changes: 3 additions & 3 deletions src/analyses/custom_bitvector_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void custom_bitvector_domaint::transform(
{
if(
lhs.is_constant() &&
is_null_pointer(to_constant_expr(lhs))) // NULL means all
to_constant_expr(lhs).is_null_pointer()) // NULL means all
{
if(mode==modet::CLEAR_MAY)
{
Expand Down Expand Up @@ -478,7 +478,7 @@ void custom_bitvector_domaint::transform(
{
if(
lhs.is_constant() &&
is_null_pointer(to_constant_expr(lhs))) // NULL means all
to_constant_expr(lhs).is_null_pointer()) // NULL means all
{
if(mode==modet::CLEAR_MAY)
{
Expand Down Expand Up @@ -716,7 +716,7 @@ exprt custom_bitvector_domaint::eval(

if(
pointer.is_constant() &&
is_null_pointer(to_constant_expr(pointer))) // NULL means all
to_constant_expr(pointer).is_null_pointer()) // NULL means all
{
if(src.id() == ID_get_may)
{
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/invariant_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ std::string inv_object_storet::build_string(const exprt &expr) const
if(expr.is_constant())
{
// NULL?
if(is_null_pointer(to_constant_expr(expr)))
if(to_constant_expr(expr).is_null_pointer())
return "0";

const auto i = numeric_cast<mp_integer>(expr);
Expand Down
4 changes: 2 additions & 2 deletions src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1672,13 +1672,13 @@ void c_typecheck_baset::typecheck_expr_trinary(if_exprt &expr)
// (at least that's how GCC behaves)
if(
to_pointer_type(operands[1].type()).base_type().id() == ID_empty &&
tmp1.is_constant() && is_null_pointer(to_constant_expr(tmp1)))
tmp1.is_constant() && to_constant_expr(tmp1).is_null_pointer())
{
implicit_typecast(operands[1], operands[2].type());
}
else if(
to_pointer_type(operands[2].type()).base_type().id() == ID_empty &&
tmp2.is_constant() && is_null_pointer(to_constant_expr(tmp2)))
tmp2.is_constant() && to_constant_expr(tmp2).is_null_pointer())
{
implicit_typecast(operands[2], operands[1].type());
}
Expand Down
3 changes: 1 addition & 2 deletions src/ansi-c/expr2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Author: Daniel Kroening, [email protected]
#include <util/c_types.h>
#include <util/config.h>
#include <util/cprover_prefix.h>
#include <util/expr_util.h>
#include <util/find_symbols.h>
#include <util/fixedbv.h>
#include <util/floatbv_expr.h>
Expand Down Expand Up @@ -1983,7 +1982,7 @@ std::string expr2ct::convert_constant(
}
else if(type.id()==ID_pointer)
{
if(is_null_pointer(src))
if(src.is_null_pointer())
{
if(configuration.use_library_macros)
dest = "NULL";
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/cpp_typecheck_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ bool cpp_typecheckt::standard_conversion_pointer_to_member(
if(expr.get_bool(ID_C_lvalue))
return false;

if(expr.is_constant() && is_null_pointer(to_constant_expr(expr)))
if(expr.is_constant() && to_constant_expr(expr).is_null_pointer())
{
new_expr = typecast_exprt::conditional_cast(expr, type);
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/cprover/bv_pointers_wide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ bvt bv_pointers_widet::convert_pointer_type(const exprt &expr)
{
const constant_exprt &c = to_constant_expr(expr);

if(is_null_pointer(c))
if(c.is_null_pointer())
return encode(pointer_logic.get_null_object(), type);
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/goto-instrument/dump_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ void dump_ct::cleanup_expr(exprt &expr)
}
// add a typecast for NULL
else if(
u.op().is_constant() && is_null_pointer(to_constant_expr(u.op())) &&
u.op().is_constant() && to_constant_expr(u.op()).is_null_pointer() &&
to_pointer_type(u.op().type()).base_type().id() == ID_empty)
{
const struct_union_typet::componentt &comp=
Expand Down Expand Up @@ -1459,7 +1459,7 @@ void dump_ct::cleanup_expr(exprt &expr)
// add a typecast for NULL or 0
if(
argument.is_constant() &&
is_null_pointer(to_constant_expr(argument)))
to_constant_expr(argument).is_null_pointer())
{
const typet &comp_type=
to_union_type(type).components().front().type();
Expand Down
2 changes: 1 addition & 1 deletion src/goto-instrument/goto_program2code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ goto_programt::const_targett goto_program2codet::convert_assign_varargs(
const exprt this_va_list_expr = target->assign_lhs();
const exprt &r = skip_typecast(target->assign_rhs());

if(r.is_constant() && is_null_pointer(to_constant_expr(r)))
if(r.is_constant() && to_constant_expr(r).is_null_pointer())
{
code_function_callt f(
symbol_exprt("va_end", code_typet({}, empty_typet())),
Expand Down
3 changes: 1 addition & 2 deletions src/goto-programs/xml_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Author: Daniel Kroening
#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/config.h>
#include <util/expr_util.h>
#include <util/fixedbv.h>
#include <util/ieee_float.h>
#include <util/invariant.h>
Expand Down Expand Up @@ -221,7 +220,7 @@ xmlt xml(const exprt &expr, const namespacet &ns)
result.name = "pointer";
result.set_attribute(
"binary", integer2binary(bvrep2integer(value, width, false), width));
if(is_null_pointer(constant_expr))
if(constant_expr.is_null_pointer())
result.data = "NULL";
}
else if(type.id() == ID_bool)
Expand Down
4 changes: 1 addition & 3 deletions src/goto-symex/shadow_memory_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ bool contains_null_or_invalid(
const std::vector<exprt> &value_set,
const exprt &address)
{
if(
address.id() == ID_constant && address.type().id() == ID_pointer &&
to_constant_expr(address).is_zero())
if(address.is_constant() && to_constant_expr(address).is_null_pointer())
{
for(const auto &e : value_set)
{
Expand Down
2 changes: 1 addition & 1 deletion src/goto-symex/symex_goto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static std::optional<renamedt<exprt, L2>> try_evaluate_pointer_comparison(

if(
skip_typecast(other_operand).id() != ID_address_of &&
(!constant_expr || !is_null_pointer(*constant_expr)))
(!constant_expr || !constant_expr->is_null_pointer()))
{
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion src/goto-synthesizer/cegis_verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ get_checked_pointer_from_null_pointer_check(const exprt &violation)
// NULL == ptr
if(
can_cast_expr<constant_exprt>(lhs_pointer) &&
is_null_pointer(*expr_try_dynamic_cast<constant_exprt>(lhs_pointer)))
expr_try_dynamic_cast<constant_exprt>(lhs_pointer)->is_null_pointer())
{
return rhs_pointer;
}
Expand Down
3 changes: 1 addition & 2 deletions src/pointer-analysis/value_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Author: Daniel Kroening, [email protected]
#include <util/bitvector_expr.h>
#include <util/byte_operators.h>
#include <util/c_types.h>
#include <util/expr_util.h>
#include <util/format_expr.h>
#include <util/format_type.h>
#include <util/namespace.h>
Expand Down Expand Up @@ -621,7 +620,7 @@ void value_sett::get_value_set_rec(
else if(expr.is_constant())
{
// check if NULL
if(is_null_pointer(to_constant_expr(expr)))
if(to_constant_expr(expr).is_null_pointer())
{
insert(
dest,
Expand Down
3 changes: 1 addition & 2 deletions src/pointer-analysis/value_set_fi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Author: Daniel Kroening, [email protected]
#include <util/arith_tools.h>
#include <util/byte_operators.h>
#include <util/c_types.h>
#include <util/expr_util.h>
#include <util/namespace.h>
#include <util/pointer_expr.h>
#include <util/simplify_expr.h>
Expand Down Expand Up @@ -532,7 +531,7 @@ void value_set_fit::get_value_set_rec(
else if(expr.is_constant())
{
// check if NULL
if(is_null_pointer(to_constant_expr(expr)))
if(to_constant_expr(expr).is_null_pointer())
{
insert(
dest,
Expand Down
3 changes: 1 addition & 2 deletions src/solvers/flattening/bv_pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Author: Daniel Kroening, [email protected]
#include <util/c_types.h>
#include <util/config.h>
#include <util/exception_utils.h>
#include <util/expr_util.h>
#include <util/namespace.h>
#include <util/pointer_expr.h>
#include <util/pointer_offset_size.h>
Expand Down Expand Up @@ -443,7 +442,7 @@ bvt bv_pointerst::convert_pointer_type(const exprt &expr)
{
const constant_exprt &c = to_constant_expr(expr);

if(is_null_pointer(c))
if(c.is_null_pointer())
return encode(pointer_logic.get_null_object(), type);
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/smt2/smt2_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3379,7 +3379,7 @@ void smt2_convt::convert_constant(const constant_exprt &expr)
}
else if(expr_type.id()==ID_pointer)
{
if(is_null_pointer(expr))
if(expr.is_null_pointer())
{
out << "(_ bv0 " << boolbv_width(expr_type)
<< ")";
Expand Down
3 changes: 1 addition & 2 deletions src/solvers/smt2_incremental/convert_expr_to_smt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <util/config.h>
#include <util/expr.h>
#include <util/expr_cast.h>
#include <util/expr_util.h>
#include <util/floatbv_expr.h>
#include <util/mathematical_expr.h>
#include <util/pointer_expr.h>
Expand Down Expand Up @@ -329,7 +328,7 @@ struct sort_based_literal_convertert : public smt_sort_const_downcast_visitort

static smt_termt convert_expr_to_smt(const constant_exprt &constant_literal)
{
if(is_null_pointer(constant_literal))
if(constant_literal.is_null_pointer())
{
const size_t bit_width =
type_checked_cast<pointer_typet>(constant_literal.type()).get_width();
Expand Down
2 changes: 1 addition & 1 deletion src/util/arith_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool to_integer(const constant_exprt &expr, mp_integer &int_value)

if(type_id==ID_pointer)
{
if(is_null_pointer(expr))
if(expr.is_null_pointer())
{
int_value=0;
return false;
Expand Down
17 changes: 1 addition & 16 deletions src/util/expr_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,20 +369,5 @@ exprt make_and(exprt a, exprt b)

bool is_null_pointer(const constant_exprt &expr)
{
if(expr.type().id() != ID_pointer)
return false;

if(expr.get_value() == ID_NULL)
return true;

// We used to support "0" (when NULL_is_zero), but really front-ends should
// resolve this and generate ID_NULL instead.
#if 0
return config.ansi_c.NULL_is_zero && expr.value_is_zero_string();
#else
INVARIANT(
!expr.value_is_zero_string() || !config.ansi_c.NULL_is_zero,
"front-end should use ID_NULL");
return false;
#endif
return expr.is_null_pointer();
}
2 changes: 2 additions & 0 deletions src/util/expr_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
* \date Sun Jul 31 21:54:44 BST 2011
*/

#include "deprecate.h"
#include "irep.h"

#include <functional>
Expand Down Expand Up @@ -116,6 +117,7 @@ exprt make_and(exprt a, exprt b);
/// Returns true if \p expr has a pointer type and a value NULL; it also returns
/// true when \p expr has value zero and NULL_is_zero is true; returns false in
/// all other cases.
DEPRECATED(SINCE(2024, 9, 10, "use constant_exprt::is_null_pointer() instead"))
bool is_null_pointer(const constant_exprt &expr);

#endif // CPROVER_UTIL_EXPR_UTIL_H
2 changes: 1 addition & 1 deletion src/util/format_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static std::ostream &format_rec(std::ostream &os, const constant_exprt &src)
return os << ieee_floatt(src);
else if(type == ID_pointer)
{
if(is_null_pointer(src))
if(src.is_null_pointer())
return os << ID_NULL;
else if(
src.get_value() == "INVALID" || src.get_value().starts_with("INVALID-"))
Expand Down
2 changes: 1 addition & 1 deletion src/util/simplify_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ simplify_exprt::simplify_typecast(const typecast_exprt &expr)
(op_plus_expr.op0().id() == ID_typecast &&
to_typecast_expr(op_plus_expr.op0()).op().is_zero()) ||
(op_plus_expr.op0().is_constant() &&
is_null_pointer(to_constant_expr(op_plus_expr.op0()))))
to_constant_expr(op_plus_expr.op0()).is_null_pointer()))
{
auto sub_size =
pointer_offset_size(to_pointer_type(op_type).base_type(), ns);
Expand Down
8 changes: 4 additions & 4 deletions src/util/simplify_expr_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1538,8 +1538,8 @@ static bool eliminate_common_addends(exprt &op0, exprt &op1)
// we can't eliminate zeros
if(
op0.is_zero() || op1.is_zero() ||
(op0.is_constant() && is_null_pointer(to_constant_expr(op0))) ||
(op1.is_constant() && is_null_pointer(to_constant_expr(op1))))
(op0.is_constant() && to_constant_expr(op0).is_null_pointer()) ||
(op1.is_constant() && to_constant_expr(op1).is_null_pointer()))
{
return true;
}
Expand Down Expand Up @@ -1736,7 +1736,7 @@ simplify_exprt::resultt<> simplify_exprt::simplify_inequality_rhs_is_constant(

const constant_exprt &op1_constant = to_constant_expr(expr.op1());

if(is_null_pointer(op1_constant))
if(op1_constant.is_null_pointer())
{
// the address of an object is never NULL

Expand Down Expand Up @@ -1799,7 +1799,7 @@ simplify_exprt::resultt<> simplify_exprt::simplify_inequality_rhs_is_constant(

exprt ptr = simplify_object(expr.op0()).expr;
// NULL + N == NULL is N == 0
if(ptr.is_constant() && is_null_pointer(to_constant_expr(ptr)))
if(ptr.is_constant() && to_constant_expr(ptr).is_null_pointer())
return make_boolean_expr(offset.is_zero());
// &x + N == NULL is false when the offset is in bounds
else if(auto address_of = expr_try_dynamic_cast<address_of_exprt>(ptr))
Expand Down
8 changes: 4 additions & 4 deletions src/util/simplify_expr_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static bool is_dereference_integer_object(
{
const constant_exprt &constant = to_constant_expr(pointer);

if(is_null_pointer(constant))
if(constant.is_null_pointer())
{
address=0;
return true;
Expand Down Expand Up @@ -398,7 +398,7 @@ simplify_exprt::simplify_pointer_offset(const pointer_offset_exprt &expr)
{
const constant_exprt &c_ptr = to_constant_expr(ptr);

if(is_null_pointer(c_ptr))
if(c_ptr.is_null_pointer())
{
return from_integer(0, expr.type());
}
Expand Down Expand Up @@ -571,7 +571,7 @@ simplify_exprt::simplify_is_dynamic_object(const unary_exprt &expr)
}

// NULL is not dynamic
if(op.is_constant() && is_null_pointer(to_constant_expr(op)))
if(op.is_constant() && to_constant_expr(op).is_null_pointer())
return false_exprt();

// &something depends on the something
Expand Down Expand Up @@ -619,7 +619,7 @@ simplify_exprt::simplify_is_invalid_pointer(const unary_exprt &expr)
}

// NULL is not invalid
if(op.is_constant() && is_null_pointer(to_constant_expr(op)))
if(op.is_constant() && to_constant_expr(op).is_null_pointer())
{
return false_exprt();
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/simplify_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ expr2bits(const exprt &expr, bool little_endian, const namespacet &ns)
}
else if(type.id() == ID_pointer)
{
if(config.ansi_c.NULL_is_zero && is_null_pointer(to_constant_expr(expr)))
if(config.ansi_c.NULL_is_zero && to_constant_expr(expr).is_null_pointer())
return std::string(to_bitvector_type(type).get_width(), '0');
else
return {};
Expand Down
Loading

0 comments on commit dc8793c

Please sign in to comment.