Skip to content

make_binary must not mess up types when dealing with pointers #31

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
Apr 3, 2017
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: 3 additions & 1 deletion src/analyses/local_bitvector_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ local_bitvector_analysist::flagst local_bitvector_analysist::get_rec(
{
if(rhs.operands().size()>=3)
{
return get_rec(make_binary(rhs), loc_info_src);
assert(rhs.op0().type().id()==ID_pointer);
return get_rec(rhs.op0(), loc_info_src) |
flagst::mk_uses_offset();
}
else if(rhs.operands().size()==2)
{
Expand Down
4 changes: 2 additions & 2 deletions src/analyses/local_may_alias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Author: Daniel Kroening, [email protected]
#include <util/arith_tools.h>
#include <util/std_expr.h>
#include <util/std_code.h>
#include <util/expr_util.h>

#include <ansi-c/c_types.h>
#include <langapi/language_util.h>
Expand Down Expand Up @@ -309,7 +308,8 @@ void local_may_aliast::get_rec(
{
if(rhs.operands().size()>=3)
{
get_rec(dest, make_binary(rhs), loc_info_src);
assert(rhs.op0().type().id()==ID_pointer);
get_rec(dest, rhs.op0(), loc_info_src);
}
else if(rhs.operands().size()==2)
{
Expand Down
14 changes: 10 additions & 4 deletions src/pointer-analysis/dereference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Author: Daniel Kroening, [email protected]
#endif

#include <util/std_expr.h>
#include <util/expr_util.h>
#include <util/byte_operators.h>
#include <util/pointer_offset_size.h>
#include <util/base_type.h>
Expand Down Expand Up @@ -279,11 +278,18 @@ exprt dereferencet::dereference_plus(
const exprt &offset,
const typet &type)
{
exprt pointer=expr.op0();
exprt integer=expr.op1();

// need not be binary
if(expr.operands().size()>2)
return dereference_rec(make_binary(expr), offset, type);
{
assert(expr.op0().type().id()==ID_pointer);

// binary
exprt pointer=expr.op0(), integer=expr.op1();
exprt::operandst plus_ops(
++expr.operands().begin(), expr.operands().end());
integer.operands().swap(plus_ops);
}

if(ns.follow(integer.type()).id()==ID_pointer)
std::swap(pointer, integer);
Expand Down
6 changes: 6 additions & 0 deletions src/util/expr_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,19 @@ exprt make_binary(const exprt &expr)
if(operands.size()<=2)
return expr;

// types must be identical for make_binary to be safe to use
const typet &type=expr.type();

exprt previous=operands.front();
assert(previous.type()==type);

for(exprt::operandst::const_iterator
it=++operands.begin();
it!=operands.end();
++it)
{
assert(it->type()==type);

exprt tmp=expr;
tmp.operands().clear();
tmp.operands().resize(2);
Expand Down