Skip to content
Draft
6 changes: 5 additions & 1 deletion jbmc/src/java_bytecode/java_object_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,8 +1087,12 @@ void java_object_factoryt::gen_nondet_init(
else
{
exprt within_bounds = interval.make_contains_expr(expr);
if(!within_bounds.is_true())
if(
!within_bounds.is_constant() ||
!to_constant_expr(within_bounds).is_true())
{
assignments.add(code_assumet(std::move(within_bounds)));
}
}

if(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ static bool is_call_to(

static bool is_assume_false(goto_programt::const_targett inst)
{
return inst->is_assume() && inst->condition().is_false();
return inst->is_assume() && inst->condition().is_constant() &&
to_constant_expr(inst->condition()).is_false();
}

/// Interpret `program`, resolving classid comparisons assuming any actual
Expand All @@ -90,17 +91,20 @@ static goto_programt::const_targett interpret_classid_comparison(
{
exprt guard = pc->condition();
guard = resolve_classid_test(guard, actual_class_id, ns);
if(guard.is_true())
if(!guard.is_constant())
{
// Can't resolve the test, so exit here:
return pc;
}
else if(to_constant_expr(guard).is_true())
{
REQUIRE(pc->targets.begin() != pc->targets.end());
pc = *(pc->targets.begin());
}
else if(guard.is_false())
++pc;
else
{
// Can't resolve the test, so exit here:
return pc;
CHECK_RETURN(to_constant_expr(guard).is_false());
++pc;
}
}
else if(pc->type() == SKIP)
Expand Down
6 changes: 3 additions & 3 deletions src/analyses/constant_propagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ void constant_propagator_domaint::transform(
else
g = not_exprt(from->condition());
partial_evaluate(values, g, ns);
if(g.is_false())
values.set_to_bottom();
if(g.is_constant() && to_constant_expr(g).is_false())
values.set_to_bottom();
else
two_way_propagate_rec(g, ns, cp);
}
Expand Down Expand Up @@ -376,7 +376,7 @@ bool constant_propagator_domaint::two_way_propagate_rec(

// x != FALSE ==> x == TRUE

if(rhs.is_zero() || rhs.is_false())
if(to_constant_expr(rhs).is_zero() || to_constant_expr(rhs).is_false())
rhs = from_integer(1, rhs.type());
else
rhs = from_integer(0, rhs.type());
Expand Down
24 changes: 12 additions & 12 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 @@ -530,7 +530,7 @@ void custom_bitvector_domaint::transform(

const exprt result2 = simplify_expr(eval(guard, cba), ns);

if(result2.is_false())
if(result2.is_constant() && to_constant_expr(result2).is_false())
make_bottom();
}
break;
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 Expand Up @@ -814,12 +814,12 @@ void custom_bitvector_analysist::check(
if(use_xml)
{
out << "<result status=\"";
if(result.is_true())
if(!result.is_constant())
out << "UNKNOWN";
else if(to_constant_expr(result).is_true())
out << "SUCCESS";
else if(result.is_false())
out << "FAILURE";
else
out << "UNKNOWN";
out << "FAILURE";
out << "\">\n";
out << xml(i_it->source_location());
out << "<description>"
Expand All @@ -838,12 +838,12 @@ void custom_bitvector_analysist::check(
out << '\n';
}

if(result.is_true())
if(!result.is_constant())
unknown++;
else if(to_constant_expr(result).is_true())
pass++;
else if(result.is_false())
fail++;
else
unknown++;
fail++;
}

if(!use_xml)
Expand Down
20 changes: 10 additions & 10 deletions src/analyses/goto_rw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ void rw_range_sett::get_objects_if(
const range_spect &range_start,
const range_spect &size)
{
if(if_expr.cond().is_false())
get_objects_rec(mode, if_expr.false_case(), range_start, size);
else if(if_expr.cond().is_true())
get_objects_rec(mode, if_expr.true_case(), range_start, size);
else
if(!if_expr.cond().is_constant())
{
get_objects_rec(get_modet::READ, if_expr.cond());

get_objects_rec(mode, if_expr.false_case(), range_start, size);
get_objects_rec(mode, if_expr.true_case(), range_start, size);
}
else if(to_constant_expr(if_expr.cond()).is_false())
get_objects_rec(mode, if_expr.false_case(), range_start, size);
else
get_objects_rec(mode, if_expr.true_case(), range_start, size);
}

void rw_range_sett::get_objects_dereference(
Expand Down Expand Up @@ -735,11 +735,7 @@ void rw_guarded_range_set_value_sett::get_objects_if(
const range_spect &range_start,
const range_spect &size)
{
if(if_expr.cond().is_false())
get_objects_rec(mode, if_expr.false_case(), range_start, size);
else if(if_expr.cond().is_true())
get_objects_rec(mode, if_expr.true_case(), range_start, size);
else
if(!if_expr.cond().is_constant())
{
get_objects_rec(get_modet::READ, if_expr.cond());

Expand All @@ -753,6 +749,10 @@ void rw_guarded_range_set_value_sett::get_objects_if(
get_objects_rec(mode, if_expr.true_case(), range_start, size);
guard = std::move(copy);
}
else if(to_constant_expr(if_expr.cond()).is_false())
get_objects_rec(mode, if_expr.false_case(), range_start, size);
else
get_objects_rec(mode, if_expr.true_case(), range_start, size);
}

void rw_guarded_range_set_value_sett::add(
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/guard_bdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ exprt guard_bddt::guard_expr(exprt expr) const
}
else
{
if(expr.is_false())
if(expr.is_constant() && to_constant_expr(expr).is_false())
{
return boolean_negate(as_expr());
}
Expand Down
11 changes: 7 additions & 4 deletions src/analyses/guard_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exprt guard_exprt::guard_expr(exprt expr) const
}
else
{
if(expr.is_false())
if(expr.is_constant() && to_constant_expr(expr).is_false())
{
return boolean_negate(as_expr());
}
Expand All @@ -39,9 +39,10 @@ void guard_exprt::add(const exprt &expr)
{
PRECONDITION(expr.is_boolean());

if(is_false() || expr.is_true())
if(is_false() || (expr.is_constant() && to_constant_expr(expr).is_true()))
return;
else if(is_true() || expr.is_false())
else if(
is_true() || (expr.is_constant() && to_constant_expr(expr).is_false()))
{
this->expr = expr;

Expand Down Expand Up @@ -198,7 +199,9 @@ guard_exprt &operator|=(guard_exprt &g1, const guard_exprt &g2)

if(tmp != and_expr1)
{
if(and_expr1.is_true() || and_expr2.is_true())
if(
(and_expr1.is_constant() && to_constant_expr(and_expr1).is_true()) ||
(and_expr2.is_constant() && to_constant_expr(and_expr2).is_true()))
{
}
else
Expand Down
6 changes: 3 additions & 3 deletions src/analyses/guard_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Author: Daniel Kroening, [email protected]
#ifndef CPROVER_ANALYSES_GUARD_EXPR_H
#define CPROVER_ANALYSES_GUARD_EXPR_H

#include <util/expr.h>
#include <util/std_expr.h>

/// This is unused by this implementation of guards, but can be used by other
/// implementations of the same interface.
Expand Down Expand Up @@ -59,12 +59,12 @@ class guard_exprt

bool is_true() const
{
return expr.is_true();
return expr.is_constant() && to_constant_expr(expr).is_true();
}

bool is_false() const
{
return expr.is_false();
return expr.is_constant() && to_constant_expr(expr).is_false();
}

friend guard_exprt &operator-=(guard_exprt &g1, const guard_exprt &g2);
Expand Down
7 changes: 5 additions & 2 deletions src/analyses/interval_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ void instrument_intervals(
{
goto_programt::const_targett previous = std::prev(i_it);

if(previous->is_goto() && !previous->condition().is_true())
if(
previous->is_goto() &&
(!previous->condition().is_constant() ||
!to_constant_expr(previous->condition()).is_true()))
{
// we follow a branch, instrument
}
Expand All @@ -69,7 +72,7 @@ void instrument_intervals(
for(const auto &symbol_expr : symbols)
{
exprt tmp=d.make_expression(symbol_expr);
if(!tmp.is_true())
if(!tmp.is_constant() || !to_constant_expr(tmp).is_true())
assertion.push_back(tmp);
}

Expand Down
6 changes: 4 additions & 2 deletions src/analyses/interval_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ bool interval_domaint::ai_simplify(
// of when condition is true
if(!a.join(d)) // If d (this) is included in a...
{ // Then the condition is always true
unchanged=condition.is_true();
unchanged =
condition.is_constant() && to_constant_expr(condition).is_true();
condition = true_exprt();
}
}
Expand All @@ -514,7 +515,8 @@ bool interval_domaint::ai_simplify(
d.assume(not_exprt(condition), ns); // Restrict to when condition is false
if(d.is_bottom()) // If there there are none...
{ // Then the condition is always true
unchanged=condition.is_true();
unchanged =
condition.is_constant() && to_constant_expr(condition).is_true();
condition = true_exprt();
}
}
Expand Down
40 changes: 23 additions & 17 deletions 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 Expand Up @@ -394,14 +394,17 @@ void invariant_sett::strengthen_rec(const exprt &expr)
return;
}

if(expr.is_true())
{
// do nothing, it's useless
}
else if(expr.is_false())
if(expr.is_constant())
{
// wow, that's strong
make_false();
if(to_constant_expr(expr).is_true())
{
// do nothing, it's useless
}
else
{
// wow, that's strong
make_false();
}
}
else if(expr.id()==ID_not)
{
Expand Down Expand Up @@ -596,7 +599,7 @@ tvt invariant_sett::implies_rec(const exprt &expr) const
if(is_false) // can't get any stronger
return tvt(true);

if(expr.is_true())
if(expr.is_constant() && to_constant_expr(expr).is_true())
return tvt(true);
else if(expr.id()==ID_not)
{
Expand Down Expand Up @@ -701,15 +704,18 @@ void invariant_sett::nnf(exprt &expr, bool negate)
if(!expr.is_boolean())
throw "nnf: non-Boolean expression";

if(expr.is_true())
{
if(negate)
expr=false_exprt();
}
else if(expr.is_false())
if(expr.is_constant())
{
if(negate)
expr=true_exprt();
if(to_constant_expr(expr).is_true())
{
if(negate)
expr = false_exprt();
}
else
{
if(negate)
expr = true_exprt();
}
}
else if(expr.id()==ID_not)
{
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/local_bitvector_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ local_bitvector_analysist::flagst local_bitvector_analysist::get_rec(
{
if(rhs.is_constant())
{
if(rhs.is_zero())
if(to_constant_expr(rhs).is_zero())
return flagst::mk_null();
else
return flagst::mk_integer_address();
Expand Down
6 changes: 5 additions & 1 deletion src/analyses/local_cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ void local_cfgt::build(const goto_programt &goto_program)
switch(instruction.type())
{
case GOTO:
if(!instruction.condition().is_true())
if(
!instruction.condition().is_constant() ||
!to_constant_expr(instruction.condition()).is_true())
{
node.successors.push_back(loc_nr+1);
}

for(const auto &target : instruction.targets)
{
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/local_may_alias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void local_may_aliast::get_rec(
{
if(rhs.is_constant())
{
if(rhs.is_zero())
if(to_constant_expr(rhs).is_zero())
dest.insert(objects.number(exprt(ID_null_object)));
else
dest.insert(objects.number(exprt(ID_integer_address_object)));
Expand Down
Loading
Loading