Skip to content

Commit a22a54a

Browse files
committed
Use null_pointer_exprt instead of gen_zero
1 parent 6e36ead commit a22a54a

File tree

7 files changed

+20
-19
lines changed

7 files changed

+20
-19
lines changed

src/analyses/goto_check.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,8 @@ void goto_checkt::pointer_validity_check(
972972
return;
973973

974974
const exprt &pointer=expr.op0();
975-
const typet &pointer_type=to_pointer_type(ns.follow(pointer.type()));
975+
const pointer_typet &pointer_type=
976+
to_pointer_type(ns.follow(pointer.type()));
976977

977978
assert(base_type_eq(pointer_type.subtype(), expr.type(), ns));
978979

@@ -986,7 +987,7 @@ void goto_checkt::pointer_validity_check(
986987
{
987988
if(flags.is_unknown() || flags.is_null())
988989
{
989-
notequal_exprt not_eq_null(pointer, gen_zero(pointer.type()));
990+
notequal_exprt not_eq_null(pointer, null_pointer_exprt(pointer_type));
990991

991992
add_guarded_claim(
992993
not_eq_null,
@@ -1612,7 +1613,9 @@ void goto_checkt::goto_check(goto_functiont &goto_function)
16121613

16131614
if(flags.is_unknown() || flags.is_null())
16141615
{
1615-
notequal_exprt not_eq_null(pointer, gen_zero(pointer.type()));
1616+
notequal_exprt not_eq_null(
1617+
pointer,
1618+
null_pointer_exprt(to_pointer_type(pointer.type())));
16161619

16171620
add_guarded_claim(
16181621
not_eq_null,
@@ -1651,7 +1654,9 @@ void goto_checkt::goto_check(goto_functiont &goto_function)
16511654

16521655
if(pointer.type().subtype().get(ID_identifier)!="java::java.lang.AssertionError")
16531656
{
1654-
notequal_exprt not_eq_null(pointer, gen_zero(pointer.type()));
1657+
notequal_exprt not_eq_null(
1658+
pointer,
1659+
null_pointer_exprt(to_pointer_type(pointer.type())));
16551660

16561661
add_guarded_claim(
16571662
not_eq_null,
@@ -1718,7 +1723,9 @@ void goto_checkt::goto_check(goto_functiont &goto_function)
17181723
source_locationt source_location;
17191724
source_location.set_function(i.function);
17201725

1721-
equal_exprt eq(leak_expr, gen_zero(ns.follow(leak.type)));
1726+
equal_exprt eq(
1727+
leak_expr,
1728+
null_pointer_exprt(to_pointer_type(leak.type)));
17221729
add_guarded_claim(
17231730
eq,
17241731
"dynamically allocated memory never freed",

src/cpp/cpp_typecheck_virtual_table.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ void cpp_typecheckt::do_virtual_table(const symbolt &symbol)
4747
if(compo.get_bool("is_pure_virtual"))
4848
{
4949
pointer_typet pointer_type(code_type);
50-
e = gen_zero(pointer_type);
51-
assert(e.is_not_nil());
50+
e=null_pointer_exprt(pointer_type);
5251
value_map[compo.get("virtual_name")] = e;
5352
}
5453
else

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
906906
if(statement=="aconst_null")
907907
{
908908
assert(results.size()==1);
909-
results[0]=gen_zero(java_reference_type(void_typet()));
909+
results[0]=null_pointer_exprt(java_reference_type(void_typet()));
910910
}
911911
else if(statement=="athrow")
912912
{
@@ -1370,7 +1370,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
13701370
assert(op.size()==1 && results.empty());
13711371
code_ifthenelset code_branch;
13721372
const typecast_exprt lhs(op[0], pointer_typet(empty_typet()));
1373-
const exprt rhs(gen_zero(lhs.type()));
1373+
const exprt rhs(null_pointer_exprt(to_pointer_type(lhs.type())));
13741374
code_branch.cond()=binary_relation_exprt(lhs, ID_notequal, rhs);
13751375
code_branch.then_case()=code_gotot(label(number));
13761376
code_branch.then_case().add_source_location()=i_it->source_location;
@@ -1384,7 +1384,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
13841384
irep_idt number=to_constant_expr(arg0).get_value();
13851385
code_ifthenelset code_branch;
13861386
const typecast_exprt lhs(op[0], pointer_typet(empty_typet()));
1387-
const exprt rhs(gen_zero(lhs.type()));
1387+
const exprt rhs(null_pointer_exprt(to_pointer_type(lhs.type())));
13881388
code_branch.cond()=binary_relation_exprt(lhs, ID_equal, rhs);
13891389
code_branch.then_case()=code_gotot(label(number));
13901390
code_branch.then_case().add_source_location()=i_it->source_location;

src/java_bytecode/java_types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Function: java_reference_type
183183
184184
\*******************************************************************/
185185

186-
typet java_reference_type(const typet &subtype)
186+
reference_typet java_reference_type(const typet &subtype)
187187
{
188188
return reference_typet(subtype);
189189
}

src/java_bytecode/java_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ typet java_char_type();
2020
typet java_float_type();
2121
typet java_double_type();
2222
typet java_boolean_type();
23-
typet java_reference_type(const typet &subtype);
23+
reference_typet java_reference_type(const typet &subtype);
2424
symbol_typet java_classname(const std::string &);
2525

2626
pointer_typet java_array_type(const char subtype);

src/util/arith_tools.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,7 @@ constant_exprt from_integer(
188188
else if(type_id==ID_pointer)
189189
{
190190
if(int_value==0)
191-
{
192-
constant_exprt result(type);
193-
result.set_value(ID_NULL);
194-
return result;
195-
}
191+
return null_pointer_exprt(to_pointer_type(type));
196192
}
197193
else if(type_id==ID_c_bit_field)
198194
{

src/util/simplify_expr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,7 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
543543
operand.is_false() &&
544544
config.ansi_c.NULL_is_zero)
545545
{
546-
expr=gen_zero(expr_type);
547-
assert(expr.is_not_nil());
546+
expr=null_pointer_exprt(to_pointer_type(expr_type));
548547
return false;
549548
}
550549
}

0 commit comments

Comments
 (0)