Skip to content

Commit 92e9472

Browse files
zhixing-xutautschnig
authored andcommitted
Update node only checks for lhs loop variable
1 parent 4700bf4 commit 92e9472

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

src/goto-instrument/abstract_loops.cpp

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Zhixing Xu, [email protected]
1717

1818
#include <analyses/natural_loops.h>
1919
#include <analyses/dependence_graph.h>
20+
#include <analyses/goto_rw.h>
2021

2122
#include <goto-programs/remove_skip.h>
2223

@@ -240,10 +241,16 @@ void abstract_loopst::abstract_goto_program(unsigned loop_num,
240241
f_it = goto_functions.function_map.find(fn);
241242
i_it = f_it->second.body.instructions.begin();
242243
std::advance(i_it, loop_info->init_loc - i_it->location_number);
243-
expr = i_it->code;
244-
expr.id(is_inc ? ID_ge : ID_le);
245-
expr.type().id(ID_bool);
246-
i_it->make_assumption(expr);
244+
245+
//init values can be nondet
246+
const code_assignt &code_assign = to_code_assign(i_it->code);
247+
if(!(code_assign.rhs().id() == ID_side_effect))
248+
{
249+
expr = i_it->code;
250+
expr.id(is_inc ? ID_ge : ID_le);
251+
expr.type().id(ID_bool);
252+
i_it->make_assumption(expr);
253+
}
247254

248255
// change loop head into assumption, skip goto at loop end
249256
loop_info->build_assumption();
@@ -295,6 +302,7 @@ void abstract_loopst::check_assertion(unsigned location,
295302
it != control_deps.end(); ++it)
296303
{
297304
add_to_queue(dep_set, dep_queue, (*it)->location_number);
305+
ctrl_set.insert((*it)->location_number);
298306
}
299307
}
300308

@@ -311,7 +319,7 @@ void abstract_loopst::check_assertion(unsigned location,
311319
add_to_queue(dep_set, dep_queue, (*it)->location_number);
312320
//if(is_in_cycle(node, dep_graph))
313321
//update_set.insert(node);
314-
if(ctrl_set.find(node) != ctrl_set.end())
322+
if(ctrl_set.find(node) == ctrl_set.end())
315323
update_set.insert(node);
316324
}
317325
else
@@ -338,18 +346,7 @@ void abstract_loopst::check_assertion(unsigned location,
338346
std::inserter(diff, diff.begin()));
339347
// loops containing the update nodes should not be shrinkable
340348
for(auto loc: diff)
341-
{
342-
for(auto loop_n: insloop_map[loc])
343-
{
344-
irep_idt func = dep_graph[loc].PC->function;
345-
abstract_loopt *loop_info = &(absloop_map[func].find(loop_n)->second);
346-
loop_info->shrinkable = false;
347-
#ifdef DEBUG_ABSTRACT_LOOPS
348-
std::cout << " - leaf node " << loc << " makes " << func << "::"
349-
<< loop_n << " unshrinkable\n";
350-
#endif
351-
}
352-
}
349+
update_shrinkability(loc, dep_graph[loc].PC->function);
353350

354351
// check dependence of update set
355352
diff.clear();
@@ -366,10 +363,17 @@ void abstract_loopst::check_assertion(unsigned location,
366363
else
367364
{
368365
// check if the update depends on loop variable
366+
const goto_programt::instructiont &inst = *(dep_graph[loc].PC);
367+
std::cout << "check location " << loc << " type " << inst.type << "\n";
368+
if(!inst.is_assign())
369+
continue;
369370
value_setst &value_sets=
370371
dep_graph.reaching_definitions().get_value_sets();
371372
rw_range_set_value_sett rw_set(ns, value_sets);
372-
goto_rw(dep_graph[loc].PC, rw_set);
373+
rw_set.set_expr_r_set();
374+
const code_assignt &code_assign = to_code_assign(inst.code);
375+
rw_set.get_objects_rec(dep_graph[loc].PC,
376+
rw_range_sett::get_modet::READ, code_assign.lhs());
373377
bool dep_on_loop_var = false;
374378
for(auto loop_n: insloop_map[loc])
375379
{
@@ -499,16 +503,16 @@ void abstract_loopst::get_loop_info(
499503
print_nodes(loop_info.var_updates);
500504
#endif
501505

502-
// This is for SVcomp cases where values can be nondet
503-
const code_assignt &code_assign =
504-
to_code_assign(dep_graph[loop_info.init_loc].PC->code);
505-
if(code_assign.rhs().id() == ID_side_effect)
506-
{
507-
#ifdef DEBUG_ABSTRACT_LOOPS
508-
std::cout << "Unshrinkable: Loop variable init to nondet\n";
509-
#endif
510-
return;
511-
}
506+
//// This is for SVcomp cases where values can be nondet
507+
//const code_assignt &code_assign =
508+
//to_code_assign(dep_graph[loop_info.init_loc].PC->code);
509+
//if(code_assign.rhs().id() == ID_side_effect)
510+
//{
511+
//#ifdef DEBUG_ABSTRACT_LOOPS
512+
//std::cout << "Unshrinkable: Loop variable init to nondet\n";
513+
//#endif
514+
//return;
515+
//}
512516

513517
// add to the instruction # -> loop # map
514518
// unsafe with function call, further check when doing abstraction

0 commit comments

Comments
 (0)