Skip to content

fix exprt::opX accesses in goto-instrument #5011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/goto-instrument/accelerate/overflow_instrumenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void overflow_instrumentert::overflow_expr(
expr.id()==ID_mult)
{
// A generic arithmetic operation.
exprt overflow("overflow-" + expr.id_string(), bool_typet());
multi_ary_exprt overflow("overflow-" + expr.id_string(), bool_typet());
overflow.operands()=expr.operands();

if(expr.operands().size()>=3)
Expand All @@ -223,7 +223,7 @@ void overflow_instrumentert::overflow_expr(

if(i==1)
{
tmp=expr.op0();
tmp = to_multi_ary_expr(expr).op0();
}
else
{
Expand Down
7 changes: 4 additions & 3 deletions src/goto-instrument/accelerate/polynomial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ void polynomialt::from_expr(const exprt &expr)
expr.id()==ID_minus ||
expr.id()==ID_mult)
{
const auto &multi_ary_expr = to_multi_ary_expr(expr);
polynomialt poly2;

from_expr(expr.op0());
poly2.from_expr(expr.op1());
from_expr(multi_ary_expr.op0());
poly2.from_expr(multi_ary_expr.op1());

if(expr.id()==ID_minus)
{
Expand Down Expand Up @@ -148,7 +149,7 @@ void polynomialt::from_expr(const exprt &expr)
// Pretty shady... We just throw away the typecast... Pretty sure this
// isn't sound.
// XXX - probably not sound.
from_expr(expr.op0());
from_expr(to_typecast_expr(expr).op());
}
else
{
Expand Down
43 changes: 23 additions & 20 deletions src/goto-instrument/dot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class dott

unsigned subgraphscount;

std::list<exprt> function_calls;
std::list<std::pair<std::string, exprt>> function_calls;
std::list<exprt> clusters;

void
Expand Down Expand Up @@ -145,17 +145,16 @@ void dott::write_dot_subgraph(
tmp.str("Atomic End");
else if(it->is_function_call())
{
std::string t = from_expr(ns, function_id, it->code);
const auto &function_call = it->get_function_call();
std::string t = from_expr(ns, function_id, function_call);
while(t[ t.size()-1 ]=='\n')
t = t.substr(0, t.size()-1);
tmp.str(escape(t));

exprt fc;
std::stringstream ss;
ss << "Node_" << subgraphscount << "_" << it->location_number;
fc.operands().push_back(exprt(ss.str()));
fc.operands().push_back(it->code.op1());
function_calls.push_back(fc);
function_calls.push_back(
std::pair<std::string, exprt>(ss.str(), function_call.function()));
}
else if(it->is_assign() ||
it->is_decl() ||
Expand Down Expand Up @@ -224,36 +223,40 @@ void dott::write_dot_subgraph(
void dott::do_dot_function_calls(
std::ostream &out)
{
for(const auto &expr : function_calls)
for(const auto &call : function_calls)
{
std::list<exprt>::const_iterator cit=clusters.begin();
for( ; cit!=clusters.end(); cit++)
if(cit->get("name")==expr.op1().get(ID_identifier))
if(cit->get("name") == call.second.get(ID_identifier))
break;

if(cit!=clusters.end())
{
out << expr.op0().id() <<
" -> " "Node_" << cit->get("nr") << "_0" <<
" [lhead=\"cluster_" << expr.op1().get(ID_identifier) << "\"," <<
"color=blue];\n";
out << call.first
<< " -> "
"Node_"
<< cit->get("nr") << "_0"
<< " [lhead=\"cluster_" << call.second.get(ID_identifier) << "\","
<< "color=blue];\n";
}
else
{
out << "subgraph \"cluster_" << expr.op1().get(ID_identifier) <<
"\" {\n";
out << "subgraph \"cluster_" << call.second.get(ID_identifier)
<< "\" {\n";
out << "rank=sink;\n";
out << "label=\"" << expr.op1().get(ID_identifier) << "\";\n";
out << "label=\"" << call.second.get(ID_identifier) << "\";\n";
out << "Node_" << subgraphscount << "_0 " <<
"[shape=Mrecord,fontsize=22,label=\"?\"];\n";
out << "}\n";
clusters.push_back(exprt("cluster"));
clusters.back().set("name", expr.op1().get(ID_identifier));
clusters.back().set("name", call.second.get(ID_identifier));
clusters.back().set("nr", subgraphscount);
out << expr.op0().id() <<
" -> " "Node_" << subgraphscount << "_0" <<
" [lhead=\"cluster_" << expr.op1().get("identifier") << "\"," <<
"color=blue];\n";
out << call.first
<< " -> "
"Node_"
<< subgraphscount << "_0"
<< " [lhead=\"cluster_" << call.second.get("identifier") << "\","
<< "color=blue];\n";
subgraphscount++;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/goto-instrument/goto_program2code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ void goto_program2codet::scan_for_varargs()
r.id() == ID_side_effect &&
to_side_effect_expr(r).get_statement() == ID_va_start)
{
assert(r.has_operands());
va_list_expr.insert(r.op0());
va_list_expr.insert(to_unary_expr(r).op());
}
// try our modelling of va_start
else if(l.type().id()==ID_pointer &&
Expand Down Expand Up @@ -315,7 +314,8 @@ goto_programt::const_targett goto_program2codet::convert_assign_varargs(
{
code_function_callt f(
symbol_exprt(ID_va_start, code_typet({}, empty_typet())),
{this_va_list_expr, to_address_of_expr(skip_typecast(r.op0())).object()});
{this_va_list_expr,
to_address_of_expr(skip_typecast(to_unary_expr(r).op())).object()});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say make an exprt for a va_start or do nothing, the fake unary-op isn't really adding any safety


dest.add(std::move(f));
}
Expand Down Expand Up @@ -865,7 +865,7 @@ goto_programt::const_targett goto_program2codet::convert_goto_switch(
// try to figure out whether this was a switch/case
exprt eq_cand=target->guard;
if(eq_cand.id()==ID_or)
eq_cand=eq_cand.op0();
eq_cand = to_or_expr(eq_cand).op0();

if(target->is_backwards_goto() ||
eq_cand.id()!=ID_equal ||
Expand Down