34 var_mapt::const_iterator it=
var_map.find(
object);
74 const std::string &suffix,
93 return new_symbol.
name;
101 for(
const auto &vars :
var_map)
106 assignment(goto_program, t, source_location, vars.second.w_buff0_used,
108 assignment(goto_program, t, source_location, vars.second.w_buff1_used,
110 assignment(goto_program, t, source_location, vars.second.flush_delayed,
112 assignment(goto_program, t, source_location, vars.second.read_delayed,
114 assignment(goto_program, t, source_location, vars.second.read_delayed_var,
117 for(
const auto &
id : vars.second.r_buff0_thds)
120 for(
const auto &
id : vars.second.r_buff1_thds)
129 goto_functionst::function_mapt::iterator
133 throw "weak memory instrumentation needs an entry point";
148 std::string identifier=
id2string(id_lhs);
150 const size_t pos=identifier.find(
"[]");
152 if(
pos!=std::string::npos)
155 identifier.erase(
pos);
160 const exprt symbol=ns.
lookup(identifier).symbol_expr();
169 catch(
const std::string &s)
187 assignment(goto_program, target, source_location, vars.read_delayed,
189 assignment(goto_program, target, source_location, vars.read_delayed_var,
194 assignment(goto_program, target, source_location, vars.read_new_var, new_var);
197 assignment(goto_program, target, source_location, write_object, new_var);
203 const std::string identifier=
id2string(write_object);
206 const varst &vars=(*this)(write_object);
233 const varst &vars=(*this)(write_object);
245 target->guard=if_expr;
247 target->source_location=source_location;
259 (void)source_location;
271 const unsigned current_thread)
273 const std::string identifier=
id2string(
object);
276 const varst &vars=(*this)(object);
285 original_instruction.
code().
op1());
305 const exprt cond_expr=
332 const unsigned current_thread)
334 const std::string identifier=
id2string(
object);
339 const varst &vars=(*this)(object);
363 const exprt new_value_expr=
365 buff0_used_and_mine_expr,
368 buff1_used_and_mine_expr,
373 assignment(goto_program, target, source_location,
object, new_value_expr);
384 buff0_used_and_mine_expr,
391 const exprt buff0_or_buff1_used_and_mine_expr=
392 or_exprt(buff0_used_and_mine_expr, buff1_used_and_mine_expr);
400 buff0_or_buff1_used_and_mine_expr,
406 const exprt buff0_thd_expr=
418 const exprt buff1_thd_expr=
427 buff0_or_buff1_used_and_mine_expr,
439 const unsigned current_thread,
440 const bool tso_pso_rmo)
442 const std::string identifier=
id2string(
object);
448 const varst &vars=(*this)(object);
456 const exprt nondet_bool_expr =
460 assignment(goto_program, target, source_location, choice0, nondet_bool_expr);
461 assignment(goto_program, target, source_location, choice2, nondet_bool_expr);
483 goto_program, target, source_location, vars.
flush_delayed, delay_expr);
488 bool instrumented=
false;
494 typedef std::multimap<irep_idt, source_locationt>::iterator m_itt;
495 std::pair<m_itt, m_itt> ran=
cycles_loc.equal_range(
object);
496 for(m_itt ran_it=ran.first; ran_it!=ran.second; ran_it++)
497 if(ran_it->second==source_location)
506 if(tso_pso_rmo || !instrumented)
515 const exprt cond_134_expr=
525 const exprt val_134_expr=lhs;
526 const exprt buff0_used_134_expr=buff0_used_expr;
527 const exprt buff1_used_134_expr=buff1_used_expr;
528 const exprt buff0_134_expr=buff0_expr;
529 const exprt buff1_134_expr=buff1_expr;
530 const exprt buff0_thd_134_expr=buff0_thd_expr;
531 const exprt buff1_thd_134_expr=buff1_thd_expr;
536 const exprt cond_267_expr=
and_exprt(buff0_used_expr, buff0_thd_expr);
537 const exprt val_267_expr=buff0_expr;
540 const exprt buff0_267_expr=buff0_expr;
541 const exprt buff1_267_expr=buff1_expr;
548 const exprt cond_5_expr=
554 const exprt val_5_expr=buff1_expr;
555 const exprt buff0_used_5_expr=buff0_used_expr;
557 const exprt buff0_5_expr=buff0_expr;
558 const exprt buff1_5_expr=buff1_expr;
559 const exprt buff0_thd_5_expr=buff0_thd_expr;
623 buff0_used_5_expr))));
639 buff1_used_5_expr))));
655 buff0_thd_5_expr))));
670 buff1_thd_5_expr))));
683 goto_program, target, source_location, choice1, nondet_bool_expr);
691 const exprt val_1_expr=lhs;
692 const exprt buff0_used_1_expr=buff0_used_expr;
693 const exprt buff1_used_1_expr=buff1_used_expr;
694 const exprt buff0_1_expr=buff0_expr;
695 const exprt buff1_1_expr=buff1_expr;
696 const exprt buff0_thd_1_expr=buff0_thd_expr;
697 const exprt buff1_thd_1_expr=buff1_thd_expr;
702 const exprt cond_267_expr=
703 and_exprt(buff0_used_expr, buff0_thd_expr);
704 const exprt val_267_expr=buff0_expr;
707 const exprt buff0_267_expr=buff0_expr;
708 const exprt buff1_267_expr=buff1_expr;
715 const exprt cond_3_expr=
721 const exprt val_3_expr=
if_exprt(choice0_expr, buff0_expr, lhs);
722 const exprt buff0_used_3_expr=choice0_expr;
724 const exprt buff0_3_expr=buff0_expr;
725 const exprt buff1_3_expr=buff1_expr;
732 const exprt cond_4_expr=
736 const exprt val_4_expr=
744 const exprt buff0_used_4_expr=
746 const exprt buff1_used_4_expr=choice0_expr;
747 const exprt buff0_4_expr=buff0_expr;
748 const exprt buff1_4_expr=buff1_expr;
749 const exprt buff0_thd_4_expr=buff0_thd_expr;
750 const exprt buff1_thd_4_expr=
756 const exprt cond_5_expr=
758 and_exprt(buff0_used_expr, buff1_thd_expr),
760 const exprt val_5_expr=
765 const exprt buff0_used_5_expr=choice0_expr;
767 const exprt buff0_5_expr=buff0_expr;
768 const exprt buff1_5_expr=buff1_expr;
857 buff0_used_3_expr))))));
879 buff1_used_3_expr))))));
901 buff0_thd_3_expr))))));
923 buff1_thd_3_expr))))));
926 catch(
const std::string &s)
944 identifier ==
CPROVER_PREFIX "alloc_size" || identifier ==
"stdin" ||
945 identifier ==
"stdout" || identifier ==
"stderr" ||
946 identifier ==
"sys_nerr" || identifier.
starts_with(
"__unbuffered_") ||
993 typedef std::multimap<irep_idt, source_locationt>::iterator m_itt;
994 std::pair<m_itt, m_itt> ran=
cycles_loc.equal_range(identifier);
995 for(m_itt ran_it=ran.first; ran_it!=ran.second; ran_it++)
996 if(ran_it->second==source_location)
1029 for(
const auto &w_entry : rw_set.
w_entries)
1031 for(
const auto &r_entry : rw_set.
r_entries)
1034 <<
" reads from " <<
id2string(r_entry.second.object)
1102 for(
const auto &w_entry : rw_set.
w_entries)
1109 original_instruction.
swap(instruction);
1119 for(
const auto &r_entry : rw_set.
r_entries)
1123 goto_program, i_it, source_location, r_entry.second.object);
1131 r_entry.second.object,
1133 (model ==
TSO || model ==
PSO || model ==
RMO));
1137 for(
const auto &w_entry : rw_set.
w_entries)
1142 for(
const auto &r_entry : rw_set.
r_entries)
1145 ns, r_entry.second.symbol_expr,
true))
1151 r_entry.second.object,
1152 w_entry.second.object);
1163 w_entry.second.object,
1164 original_instruction,
1172 for(
const auto &r_entry : rw_set.
r_entries)
1176 r_entry.second.object) !=
1184 <<
"writer " << w_entry.second.object <<
" reads "
1202 const exprt nondet_bool_expr =
1225 r_entry.second.object,
1236 w_entry.second.object,
1237 original_instruction.
code().
op1());
1244 for(
const auto &r_entry : rw_set.
r_entries)
1249 <<
"flush restore: " << r_entry.second.object <<
messaget::eom;
1256 delayed_expr, mem_value_expr, r_entry.second.symbol_expr);
1262 r_entry.second.object,
1265 goto_program, i_it, source_location,
1293 original_instruction.
swap(instruction);
1302 for(std::set<irep_idt>::iterator s_it=
past_writes.begin();
1306 goto_program, i_it, source_location, *s_it,
pointer_typet pointer_type(const typet &subtype)
Operator to return the address of an object.
const irep_idt & get_statement() const
Operator to dereference a pointer.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
bool starts_with(const char *s) const
equivalent of as_string().starts_with(s)
Base class for all expressions.
const source_locationt & source_location() const
The Boolean constant false.
A collection of goto functions.
function_mapt function_map
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
This class represents an instruction in the GOTO intermediate representation.
const exprt & call_function() const
Get the function that is called for FUNCTION_CALL.
bool is_end_thread() const
const goto_instruction_codet & code() const
Get the code represented by this instruction.
bool is_start_thread() const
const source_locationt & source_location() const
bool is_function_call() const
void swap(instructiont &instruction)
Swap two instructions.
goto_program_instruction_typet type() const
What kind of instruction?
A generic container class for the GOTO intermediate representation of one function.
instructionst instructions
The list of instructions in the goto program.
instructionst::iterator targett
static instructiont make_atomic_end(const source_locationt &l=source_locationt::nil())
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
static instructiont make_atomic_begin(const source_locationt &l=source_locationt::nil())
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
targett insert_before(const_targett target)
Insertion before the instruction pointed-to by the given instruction iterator target.
The trinary if-then-else operator.
bool get_bool(const irep_idt &name) const
mstreamt & warning() const
message_handlert & get_message_handler()
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
The null pointer constant.
shared_bufferst & shared_buffers
symbol_table_baset & symbol_table
void weak_memory(value_setst &value_sets, const irep_idt &function_id, memory_modelt model)
instruments the program for the pairs detected through the CFG
std::set< irep_idt > past_writes
goto_functionst & goto_functions
std::vector< irep_idt > r_buff0_thds
irep_idt read_delayed_var
std::vector< irep_idt > r_buff1_thds
std::multimap< irep_idt, source_locationt > cycles_loc
const varst & operator()(const irep_idt &object)
instruments the variable
void nondet_flush(const irep_idt &function_id, goto_programt &goto_program, goto_programt::targett &t, const source_locationt &source_location, const irep_idt &object, const unsigned current_thread, const bool tso_pso_rmo)
instruments read
std::string unique()
returns a unique id (for fresh variables)
void write(goto_programt &goto_program, goto_programt::targett &t, const source_locationt &source_location, const irep_idt &object, goto_programt::instructiont &original_instruction, const unsigned current_thread)
instruments write
void affected_by_delay(value_setst &value_sets, goto_functionst &goto_functions)
analysis over the goto-program which computes in affected_by_delay_set the variables (non necessarily...
void det_flush(goto_programt &goto_program, goto_programt::targett &t, const source_locationt &source_location, const irep_idt &object, const unsigned current_thread)
flush buffers (instruments fence)
irep_idt add_fresh_var(const symbolt &object, const std::string &suffix, const typet &type)
void add_initialization(goto_programt &goto_program)
bool is_buffered_in_general(const symbol_exprt &, bool is_write)
void assignment(goto_programt &goto_program, goto_programt::targett &t, const source_locationt &source_location, const irep_idt &id_lhs, const exprt &rhs)
add an assignment in the goto-program
irep_idt add(const symbolt &object, const std::string &suffix, const typet &type, bool added_as_instrumentation)
add a new var for instrumenting the input var
std::set< irep_idt > affected_by_delay_set
class symbol_table_baset & symbol_table
std::set< irep_idt > cycles
void delay_read(goto_programt &goto_program, goto_programt::targett &t, const source_locationt &source_location, const irep_idt &read_object, const irep_idt &write_object)
delays a read (POWER)
void flush_read(goto_programt &goto_program, goto_programt::targett &t, const source_locationt &source_location, const irep_idt &write_object)
flushes read (POWER)
irep_idt choice(const irep_idt &function_id, const std::string &suffix)
void add_initialization_code(goto_functionst &goto_functions)
bool is_buffered(const namespacet &, const symbol_exprt &, bool is_write)
std::set< irep_idt > instrumentations
A side_effect_exprt that returns a non-deterministically chosen value.
Expression to hold a symbol (variable)
const irep_idt & get_identifier() const
typet type
Type of symbol.
irep_idt name
The unique identifier.
exprt value
Initial value of symbol.
The Boolean constant true.
The type of an expression, extends irept.
bool is_fence(const goto_programt::instructiont &instruction, const namespacet &ns)
bool is_lwfence(const goto_programt::instructiont &instruction, const namespacet &ns)
Fences for instrumentation.
int main(int argc, char *argv[])
symbolt & get_fresh_aux_symbol(const typet &type, const std::string &name_prefix, const std::string &basename_prefix, const source_locationt &source_location, const irep_idt &symbol_mode, const namespacet &ns, symbol_table_baset &symbol_table)
Installs a fresh-named symbol with respect to the given namespace ns with the requested name pattern ...
Fresh auxiliary symbol creation.
#define Forall_goto_program_instructions(it, program)
const std::string & id2string(const irep_idt &d)
API to expression classes for Pointers.
Race Detection for Threaded Goto Programs.
#define INITIALIZE_FUNCTION
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.