Skip to content

replace_symbolt refactoring and stricter type checking #2723

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 5 commits into from
Aug 31, 2018
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
9 changes: 9 additions & 0 deletions regression/goto-instrument/constant-propagation2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <assert.h>

int main()
{
int i = 0;
int *p = &i;
assert(*p == 0);
return 0;
}
8 changes: 8 additions & 0 deletions regression/goto-instrument/constant-propagation2/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--constant-propagator
^EXIT=0$
^SIGNAL=0$
VERIFICATION SUCCESSFUL
--
^warning: ignoring
2 changes: 1 addition & 1 deletion src/analyses/constant_propagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class constant_propagator_domaint:public ai_domain_baset
struct valuest
{
// maps variables to constants
replace_symbolt replace_const;
address_of_aware_replace_symbolt replace_const;
bool is_bottom = true;

bool merge(const valuest &src);
Expand Down
18 changes: 14 additions & 4 deletions src/goto-instrument/code_contracts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ void code_contractst::apply_contract(

// TODO: return value could be nil
if(type.return_type()!=empty_typet())
replace.insert("__CPROVER_return_value", call.lhs());
{
symbol_exprt ret_val(CPROVER_PREFIX "return_value", call.lhs().type());
replace.insert(ret_val, call.lhs());
}

// formal parameters
code_function_callt::argumentst::const_iterator a_it=
Expand All @@ -200,7 +203,10 @@ void code_contractst::apply_contract(
a_it!=call.arguments().end();
++p_it, ++a_it)
if(!p_it->get_identifier().empty())
replace.insert(p_it->get_identifier(), *a_it);
{
symbol_exprt p(p_it->get_identifier(), p_it->type());
replace.insert(p, *a_it);
}

replace(requires);
replace(ensures);
Expand Down Expand Up @@ -318,7 +324,8 @@ void code_contractst::add_contract_check(

call.lhs()=r;

replace.insert("__CPROVER_return_value", r);
symbol_exprt ret_val(CPROVER_PREFIX "return_value", call.lhs().type());
replace.insert(ret_val, r);
}

// decl parameter1 ...
Expand All @@ -339,7 +346,10 @@ void code_contractst::add_contract_check(
call.arguments().push_back(p);

if(!p_it->get_identifier().empty())
replace.insert(p_it->get_identifier(), p);
{
symbol_exprt cur_p(p_it->get_identifier(), p_it->type());
replace.insert(cur_p, p);
}
}

// assume(requires)
Expand Down
8 changes: 3 additions & 5 deletions src/goto-instrument/concurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,17 @@ void concurrency_instrumentationt::instrument(exprt &expr)
{
if(s_it->id()==ID_symbol)
{
const irep_idt identifier=
to_symbol_expr(*s_it).get_identifier();
const symbol_exprt &s = to_symbol_expr(*s_it);

shared_varst::const_iterator
v_it=shared_vars.find(identifier);
shared_varst::const_iterator v_it = shared_vars.find(s.get_identifier());

if(v_it!=shared_vars.end())
{
index_exprt new_expr;
// new_expr.array()=symbol_expr();
// new_expr.index()=symbol_expr();

replace_symbol.insert(identifier, new_expr);
replace_symbol.insert(s, new_expr);
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/goto-instrument/dump_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,23 +915,26 @@ void dump_ct::cleanup_harness(code_blockt &b)
if(!ns.lookup("argc'", argc_sym))
{
symbol_exprt argc("argc", argc_sym->type);
replace.insert(argc_sym->name, argc);
replace.insert(argc_sym->symbol_expr(), argc);
code_declt d(argc);
decls.add(d);
}
const symbolt *argv_sym=nullptr;
if(!ns.lookup("argv'", argv_sym))
{
symbol_exprt argv("argv", argv_sym->type);
replace.insert(argv_sym->name, argv);
// replace argc' by argc in the type of argv['] to maintain type consistency
// while replacing
replace(argv);
replace.insert(symbol_exprt(argv_sym->name, argv.type()), argv);
code_declt d(argv);
decls.add(d);
}
const symbolt *return_sym=nullptr;
if(!ns.lookup("return'", return_sym))
{
symbol_exprt return_value("return_value", return_sym->type);
replace.insert(return_sym->name, return_value);
replace.insert(return_sym->symbol_expr(), return_value);
code_declt d(return_value);
decls.add(d);
}
Expand Down
11 changes: 8 additions & 3 deletions src/goto-instrument/model_argc_argv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ bool model_argc_argv(
return false;
}

const symbolt &argc_primed = ns.lookup("argc'");
symbol_exprt ARGC("ARGC", argc_primed.type);
const symbolt &argv_primed = ns.lookup("argv'");
symbol_exprt ARGV("ARGV", argv_primed.type);

// set the size of ARGV storage to 4096, which matches the minimum
// guaranteed by POSIX (_POSIX_ARG_MAX):
// http://pubs.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html
Expand Down Expand Up @@ -125,9 +130,9 @@ bool model_argc_argv(
{
value = symbol_pair.second.value;

replace_symbolt replace;
replace.insert("ARGC", ns.lookup("argc'").symbol_expr());
replace.insert("ARGV", ns.lookup("argv'").symbol_expr());
unchecked_replace_symbolt replace;
replace.insert(ARGC, ns.lookup("argc'").symbol_expr());
replace.insert(ARGV, ns.lookup("argv'").symbol_expr());
replace(value);
}
else if(
Expand Down
3 changes: 2 additions & 1 deletion src/linking/linking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,8 @@ void linkingt::duplicate_object_symbol(
else if(set_to_new)
old_symbol.type=new_symbol.type;

object_type_updates.insert(old_symbol.name, old_symbol.symbol_expr());
object_type_updates.insert(
old_symbol.symbol_expr(), old_symbol.symbol_expr());
}

// care about initializers
Expand Down
2 changes: 1 addition & 1 deletion src/linking/linking_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class linkingt:public typecheckt
virtual void typecheck();

rename_symbolt rename_symbol;
replace_symbolt object_type_updates;
unchecked_replace_symbolt object_type_updates;

protected:
bool needs_renaming_type(
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/flattening/flatten_byte_operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static exprt unpack_rec(
{
index_exprt index(src, from_integer(i, index_type()));
replace_symbolt replace;
replace.insert(ID_C_incomplete, index);
replace.insert(dummy, index);

for(const auto &op : sub.operands())
{
Expand Down
7 changes: 3 additions & 4 deletions src/solvers/smt2/smt2_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@ void smt2_solvert::expand_function_applications(exprt &expr)
std::map<irep_idt, exprt> parameter_map;
for(std::size_t i=0; i<f_type.domain().size(); i++)
{
const irep_idt p_identifier=
f_type.domain()[i].get_identifier();

replace_symbol.insert(p_identifier, app.arguments()[i]);
const auto &var = f_type.domain()[i];
const symbol_exprt s(var.get_identifier(), var.type());
replace_symbol.insert(s, app.arguments()[i]);
}

exprt body=f.definition;
Expand Down
Loading