Skip to content

Commit dc8793c

Browse files
authored
Merge pull request #8445 from tautschnig/move-is_null_pointer
Move is_null_pointer to constant_exprt
2 parents f0543bd + 7b47e9f commit dc8793c

27 files changed

+58
-57
lines changed

src/analyses/custom_bitvector_analysis.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void custom_bitvector_domaint::transform(
349349
{
350350
if(
351351
lhs.is_constant() &&
352-
is_null_pointer(to_constant_expr(lhs))) // NULL means all
352+
to_constant_expr(lhs).is_null_pointer()) // NULL means all
353353
{
354354
if(mode==modet::CLEAR_MAY)
355355
{
@@ -478,7 +478,7 @@ void custom_bitvector_domaint::transform(
478478
{
479479
if(
480480
lhs.is_constant() &&
481-
is_null_pointer(to_constant_expr(lhs))) // NULL means all
481+
to_constant_expr(lhs).is_null_pointer()) // NULL means all
482482
{
483483
if(mode==modet::CLEAR_MAY)
484484
{
@@ -716,7 +716,7 @@ exprt custom_bitvector_domaint::eval(
716716

717717
if(
718718
pointer.is_constant() &&
719-
is_null_pointer(to_constant_expr(pointer))) // NULL means all
719+
to_constant_expr(pointer).is_null_pointer()) // NULL means all
720720
{
721721
if(src.id() == ID_get_may)
722722
{

src/analyses/invariant_set.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ std::string inv_object_storet::build_string(const exprt &expr) const
121121
if(expr.is_constant())
122122
{
123123
// NULL?
124-
if(is_null_pointer(to_constant_expr(expr)))
124+
if(to_constant_expr(expr).is_null_pointer())
125125
return "0";
126126

127127
const auto i = numeric_cast<mp_integer>(expr);

src/ansi-c/c_typecheck_expr.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1672,13 +1672,13 @@ void c_typecheck_baset::typecheck_expr_trinary(if_exprt &expr)
16721672
// (at least that's how GCC behaves)
16731673
if(
16741674
to_pointer_type(operands[1].type()).base_type().id() == ID_empty &&
1675-
tmp1.is_constant() && is_null_pointer(to_constant_expr(tmp1)))
1675+
tmp1.is_constant() && to_constant_expr(tmp1).is_null_pointer())
16761676
{
16771677
implicit_typecast(operands[1], operands[2].type());
16781678
}
16791679
else if(
16801680
to_pointer_type(operands[2].type()).base_type().id() == ID_empty &&
1681-
tmp2.is_constant() && is_null_pointer(to_constant_expr(tmp2)))
1681+
tmp2.is_constant() && to_constant_expr(tmp2).is_null_pointer())
16821682
{
16831683
implicit_typecast(operands[2], operands[1].type());
16841684
}

src/ansi-c/expr2c.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Author: Daniel Kroening, [email protected]
1313
#include <util/c_types.h>
1414
#include <util/config.h>
1515
#include <util/cprover_prefix.h>
16-
#include <util/expr_util.h>
1716
#include <util/find_symbols.h>
1817
#include <util/fixedbv.h>
1918
#include <util/floatbv_expr.h>
@@ -1983,7 +1982,7 @@ std::string expr2ct::convert_constant(
19831982
}
19841983
else if(type.id()==ID_pointer)
19851984
{
1986-
if(is_null_pointer(src))
1985+
if(src.is_null_pointer())
19871986
{
19881987
if(configuration.use_library_macros)
19891988
dest = "NULL";

src/cpp/cpp_typecheck_conversions.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ bool cpp_typecheckt::standard_conversion_pointer_to_member(
603603
if(expr.get_bool(ID_C_lvalue))
604604
return false;
605605

606-
if(expr.is_constant() && is_null_pointer(to_constant_expr(expr)))
606+
if(expr.is_constant() && to_constant_expr(expr).is_null_pointer())
607607
{
608608
new_expr = typecast_exprt::conditional_cast(expr, type);
609609
return true;

src/cprover/bv_pointers_wide.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ bvt bv_pointers_widet::convert_pointer_type(const exprt &expr)
387387
{
388388
const constant_exprt &c = to_constant_expr(expr);
389389

390-
if(is_null_pointer(c))
390+
if(c.is_null_pointer())
391391
return encode(pointer_logic.get_null_object(), type);
392392
else
393393
{

src/goto-instrument/dump_c.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ void dump_ct::cleanup_expr(exprt &expr)
13991399
}
14001400
// add a typecast for NULL
14011401
else if(
1402-
u.op().is_constant() && is_null_pointer(to_constant_expr(u.op())) &&
1402+
u.op().is_constant() && to_constant_expr(u.op()).is_null_pointer() &&
14031403
to_pointer_type(u.op().type()).base_type().id() == ID_empty)
14041404
{
14051405
const struct_union_typet::componentt &comp=
@@ -1459,7 +1459,7 @@ void dump_ct::cleanup_expr(exprt &expr)
14591459
// add a typecast for NULL or 0
14601460
if(
14611461
argument.is_constant() &&
1462-
is_null_pointer(to_constant_expr(argument)))
1462+
to_constant_expr(argument).is_null_pointer())
14631463
{
14641464
const typet &comp_type=
14651465
to_union_type(type).components().front().type();

src/goto-instrument/goto_program2code.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ goto_programt::const_targett goto_program2codet::convert_assign_varargs(
311311
const exprt this_va_list_expr = target->assign_lhs();
312312
const exprt &r = skip_typecast(target->assign_rhs());
313313

314-
if(r.is_constant() && is_null_pointer(to_constant_expr(r)))
314+
if(r.is_constant() && to_constant_expr(r).is_null_pointer())
315315
{
316316
code_function_callt f(
317317
symbol_exprt("va_end", code_typet({}, empty_typet())),

src/goto-programs/xml_expr.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Author: Daniel Kroening
1616
#include <util/arith_tools.h>
1717
#include <util/c_types.h>
1818
#include <util/config.h>
19-
#include <util/expr_util.h>
2019
#include <util/fixedbv.h>
2120
#include <util/ieee_float.h>
2221
#include <util/invariant.h>
@@ -221,7 +220,7 @@ xmlt xml(const exprt &expr, const namespacet &ns)
221220
result.name = "pointer";
222221
result.set_attribute(
223222
"binary", integer2binary(bvrep2integer(value, width, false), width));
224-
if(is_null_pointer(constant_expr))
223+
if(constant_expr.is_null_pointer())
225224
result.data = "NULL";
226225
}
227226
else if(type.id() == ID_bool)

src/goto-symex/shadow_memory_util.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,7 @@ bool contains_null_or_invalid(
319319
const std::vector<exprt> &value_set,
320320
const exprt &address)
321321
{
322-
if(
323-
address.id() == ID_constant && address.type().id() == ID_pointer &&
324-
to_constant_expr(address).is_zero())
322+
if(address.is_constant() && to_constant_expr(address).is_null_pointer())
325323
{
326324
for(const auto &e : value_set)
327325
{

src/goto-symex/symex_goto.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static std::optional<renamedt<exprt, L2>> try_evaluate_pointer_comparison(
9191

9292
if(
9393
skip_typecast(other_operand).id() != ID_address_of &&
94-
(!constant_expr || !is_null_pointer(*constant_expr)))
94+
(!constant_expr || !constant_expr->is_null_pointer()))
9595
{
9696
return {};
9797
}

src/goto-synthesizer/cegis_verifier.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ get_checked_pointer_from_null_pointer_check(const exprt &violation)
7171
// NULL == ptr
7272
if(
7373
can_cast_expr<constant_exprt>(lhs_pointer) &&
74-
is_null_pointer(*expr_try_dynamic_cast<constant_exprt>(lhs_pointer)))
74+
expr_try_dynamic_cast<constant_exprt>(lhs_pointer)->is_null_pointer())
7575
{
7676
return rhs_pointer;
7777
}

src/pointer-analysis/value_set.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Author: Daniel Kroening, [email protected]
1515
#include <util/bitvector_expr.h>
1616
#include <util/byte_operators.h>
1717
#include <util/c_types.h>
18-
#include <util/expr_util.h>
1918
#include <util/format_expr.h>
2019
#include <util/format_type.h>
2120
#include <util/namespace.h>
@@ -621,7 +620,7 @@ void value_sett::get_value_set_rec(
621620
else if(expr.is_constant())
622621
{
623622
// check if NULL
624-
if(is_null_pointer(to_constant_expr(expr)))
623+
if(to_constant_expr(expr).is_null_pointer())
625624
{
626625
insert(
627626
dest,

src/pointer-analysis/value_set_fi.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Author: Daniel Kroening, [email protected]
1414
#include <util/arith_tools.h>
1515
#include <util/byte_operators.h>
1616
#include <util/c_types.h>
17-
#include <util/expr_util.h>
1817
#include <util/namespace.h>
1918
#include <util/pointer_expr.h>
2019
#include <util/simplify_expr.h>
@@ -532,7 +531,7 @@ void value_set_fit::get_value_set_rec(
532531
else if(expr.is_constant())
533532
{
534533
// check if NULL
535-
if(is_null_pointer(to_constant_expr(expr)))
534+
if(to_constant_expr(expr).is_null_pointer())
536535
{
537536
insert(
538537
dest,

src/solvers/flattening/bv_pointers.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Author: Daniel Kroening, [email protected]
1313
#include <util/c_types.h>
1414
#include <util/config.h>
1515
#include <util/exception_utils.h>
16-
#include <util/expr_util.h>
1716
#include <util/namespace.h>
1817
#include <util/pointer_expr.h>
1918
#include <util/pointer_offset_size.h>
@@ -443,7 +442,7 @@ bvt bv_pointerst::convert_pointer_type(const exprt &expr)
443442
{
444443
const constant_exprt &c = to_constant_expr(expr);
445444

446-
if(is_null_pointer(c))
445+
if(c.is_null_pointer())
447446
return encode(pointer_logic.get_null_object(), type);
448447
else
449448
{

src/solvers/smt2/smt2_conv.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3379,7 +3379,7 @@ void smt2_convt::convert_constant(const constant_exprt &expr)
33793379
}
33803380
else if(expr_type.id()==ID_pointer)
33813381
{
3382-
if(is_null_pointer(expr))
3382+
if(expr.is_null_pointer())
33833383
{
33843384
out << "(_ bv0 " << boolbv_width(expr_type)
33853385
<< ")";

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <util/config.h>
77
#include <util/expr.h>
88
#include <util/expr_cast.h>
9-
#include <util/expr_util.h>
109
#include <util/floatbv_expr.h>
1110
#include <util/mathematical_expr.h>
1211
#include <util/pointer_expr.h>
@@ -329,7 +328,7 @@ struct sort_based_literal_convertert : public smt_sort_const_downcast_visitort
329328

330329
static smt_termt convert_expr_to_smt(const constant_exprt &constant_literal)
331330
{
332-
if(is_null_pointer(constant_literal))
331+
if(constant_literal.is_null_pointer())
333332
{
334333
const size_t bit_width =
335334
type_checked_cast<pointer_typet>(constant_literal.type()).get_width();

src/util/arith_tools.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ bool to_integer(const constant_exprt &expr, mp_integer &int_value)
2525

2626
if(type_id==ID_pointer)
2727
{
28-
if(is_null_pointer(expr))
28+
if(expr.is_null_pointer())
2929
{
3030
int_value=0;
3131
return false;

src/util/expr_util.cpp

+1-16
Original file line numberDiff line numberDiff line change
@@ -369,20 +369,5 @@ exprt make_and(exprt a, exprt b)
369369

370370
bool is_null_pointer(const constant_exprt &expr)
371371
{
372-
if(expr.type().id() != ID_pointer)
373-
return false;
374-
375-
if(expr.get_value() == ID_NULL)
376-
return true;
377-
378-
// We used to support "0" (when NULL_is_zero), but really front-ends should
379-
// resolve this and generate ID_NULL instead.
380-
#if 0
381-
return config.ansi_c.NULL_is_zero && expr.value_is_zero_string();
382-
#else
383-
INVARIANT(
384-
!expr.value_is_zero_string() || !config.ansi_c.NULL_is_zero,
385-
"front-end should use ID_NULL");
386-
return false;
387-
#endif
372+
return expr.is_null_pointer();
388373
}

src/util/expr_util.h

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717
* \date Sun Jul 31 21:54:44 BST 2011
1818
*/
1919

20+
#include "deprecate.h"
2021
#include "irep.h"
2122

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

121123
#endif // CPROVER_UTIL_EXPR_UTIL_H

src/util/format_expr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static std::ostream &format_rec(std::ostream &os, const constant_exprt &src)
194194
return os << ieee_floatt(src);
195195
else if(type == ID_pointer)
196196
{
197-
if(is_null_pointer(src))
197+
if(src.is_null_pointer())
198198
return os << ID_NULL;
199199
else if(
200200
src.get_value() == "INVALID" || src.get_value().starts_with("INVALID-"))

src/util/simplify_expr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ simplify_exprt::simplify_typecast(const typecast_exprt &expr)
906906
(op_plus_expr.op0().id() == ID_typecast &&
907907
to_typecast_expr(op_plus_expr.op0()).op().is_zero()) ||
908908
(op_plus_expr.op0().is_constant() &&
909-
is_null_pointer(to_constant_expr(op_plus_expr.op0()))))
909+
to_constant_expr(op_plus_expr.op0()).is_null_pointer()))
910910
{
911911
auto sub_size =
912912
pointer_offset_size(to_pointer_type(op_type).base_type(), ns);

src/util/simplify_expr_int.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1538,8 +1538,8 @@ static bool eliminate_common_addends(exprt &op0, exprt &op1)
15381538
// we can't eliminate zeros
15391539
if(
15401540
op0.is_zero() || op1.is_zero() ||
1541-
(op0.is_constant() && is_null_pointer(to_constant_expr(op0))) ||
1542-
(op1.is_constant() && is_null_pointer(to_constant_expr(op1))))
1541+
(op0.is_constant() && to_constant_expr(op0).is_null_pointer()) ||
1542+
(op1.is_constant() && to_constant_expr(op1).is_null_pointer()))
15431543
{
15441544
return true;
15451545
}
@@ -1736,7 +1736,7 @@ simplify_exprt::resultt<> simplify_exprt::simplify_inequality_rhs_is_constant(
17361736

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

1739-
if(is_null_pointer(op1_constant))
1739+
if(op1_constant.is_null_pointer())
17401740
{
17411741
// the address of an object is never NULL
17421742

@@ -1799,7 +1799,7 @@ simplify_exprt::resultt<> simplify_exprt::simplify_inequality_rhs_is_constant(
17991799

18001800
exprt ptr = simplify_object(expr.op0()).expr;
18011801
// NULL + N == NULL is N == 0
1802-
if(ptr.is_constant() && is_null_pointer(to_constant_expr(ptr)))
1802+
if(ptr.is_constant() && to_constant_expr(ptr).is_null_pointer())
18031803
return make_boolean_expr(offset.is_zero());
18041804
// &x + N == NULL is false when the offset is in bounds
18051805
else if(auto address_of = expr_try_dynamic_cast<address_of_exprt>(ptr))

src/util/simplify_expr_pointer.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static bool is_dereference_integer_object(
3838
{
3939
const constant_exprt &constant = to_constant_expr(pointer);
4040

41-
if(is_null_pointer(constant))
41+
if(constant.is_null_pointer())
4242
{
4343
address=0;
4444
return true;
@@ -398,7 +398,7 @@ simplify_exprt::simplify_pointer_offset(const pointer_offset_exprt &expr)
398398
{
399399
const constant_exprt &c_ptr = to_constant_expr(ptr);
400400

401-
if(is_null_pointer(c_ptr))
401+
if(c_ptr.is_null_pointer())
402402
{
403403
return from_integer(0, expr.type());
404404
}
@@ -571,7 +571,7 @@ simplify_exprt::simplify_is_dynamic_object(const unary_exprt &expr)
571571
}
572572

573573
// NULL is not dynamic
574-
if(op.is_constant() && is_null_pointer(to_constant_expr(op)))
574+
if(op.is_constant() && to_constant_expr(op).is_null_pointer())
575575
return false_exprt();
576576

577577
// &something depends on the something
@@ -619,7 +619,7 @@ simplify_exprt::simplify_is_invalid_pointer(const unary_exprt &expr)
619619
}
620620

621621
// NULL is not invalid
622-
if(op.is_constant() && is_null_pointer(to_constant_expr(op)))
622+
if(op.is_constant() && to_constant_expr(op).is_null_pointer())
623623
{
624624
return false_exprt();
625625
}

src/util/simplify_utils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ expr2bits(const exprt &expr, bool little_endian, const namespacet &ns)
439439
}
440440
else if(type.id() == ID_pointer)
441441
{
442-
if(config.ansi_c.NULL_is_zero && is_null_pointer(to_constant_expr(expr)))
442+
if(config.ansi_c.NULL_is_zero && to_constant_expr(expr).is_null_pointer())
443443
return std::string(to_bitvector_type(type).get_width(), '0');
444444
else
445445
return {};

0 commit comments

Comments
 (0)