Skip to content

Commit 351952e

Browse files
author
kroening
committed
Properly distinguish null pointer constants and (T*)0
git-svn-id: svn+ssh://svn.cprover.org/srv/svn/cbmc/trunk@3614 6afb6bc1-c8e4-404c-8f48-9ae832c5b171
1 parent 81aea22 commit 351952e

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/ansi-c/expr2c.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,6 @@ std::string expr2ct::convert_typecast(
579579
from_type.id()==ID_unsignedbv)
580580
return convert(src.op(), precedence);
581581

582-
if(to_type.id()==ID_pointer &&
583-
ns.follow(to_type.subtype()).id()==ID_empty && // to (void *)?
584-
src.op0().is_zero())
585-
return "NULL";
586-
587582
std::string dest="("+convert(to_type)+")";
588583

589584
unsigned p;
@@ -2079,7 +2074,7 @@ std::string expr2ct::convert_constant(
20792074
}
20802075
else if(type.id()==ID_pointer)
20812076
{
2082-
if(src.is_zero())
2077+
if(to_constant_expr(src).get_value()==ID_NULL)
20832078
{
20842079
dest="NULL";
20852080
if(type.subtype().id()!=ID_empty)

src/solvers/flattening/bv_pointers.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ void bv_pointerst::convert_pointer_type(const exprt &expr, bvt &bv)
307307
op_type.id()==ID_c_enum)
308308
{
309309
// Cast from integer to pointer.
310-
// We need to be able to convert the integer 0 to NULL.
311310
// We just do a zero extension.
312311

313312
const bvt &op_bv=convert_bv(op);

src/util/expr.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ bool exprt::is_zero() const
477477
}
478478
else if(type_id==ID_pointer)
479479
{
480-
if(constant.get_value()==ID_NULL) return true;
481480
return constant.value_is_zero_string();
482481
}
483482
}

src/util/simplify_expr.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
316316
return false;
317317
}
318318

319+
#if 0
320+
// should be architecture-specific constant
319321
// casts from NULL to any integer
320322
if(op_type.id()==ID_pointer &&
321323
expr.op0().is_constant() &&
@@ -326,6 +328,7 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
326328
expr.swap(tmp);
327329
return false;
328330
}
331+
#endif
329332

330333
// casts from pointer to integer
331334
// where width of integer >= width of pointer
@@ -785,10 +788,15 @@ static bool is_dereference_integer_object(
785788
!to_integer(expr.op0().op0(), address))
786789
return true;
787790

788-
if(expr.op0().is_zero()) // NULL
791+
if(expr.op0().is_constant())
789792
{
790-
address=0;
791-
return true;
793+
/*if(to_constant_expr(expr.op0()).get_value()==ID_NULL) // NULL
794+
{
795+
address=XXX; // architecture-specific constant
796+
return true;
797+
}
798+
else*/ if(!to_integer(expr.op0(), address))
799+
return true;
792800
}
793801
}
794802

@@ -3520,7 +3528,7 @@ bool simplify_exprt::simplify_inequality_constant(exprt &expr)
35203528
// note that 'ptr' may be an integer
35213529
exprt op=expr.op0().op0();
35223530
expr.op0().swap(op);
3523-
expr.op1()=gen_zero(expr.op0().type());
3531+
expr.op1().type()=expr.op0().type();
35243532
simplify_inequality(expr); // do again!
35253533
return false;
35263534
}

0 commit comments

Comments
 (0)