30 var_mapt::const_iterator it=
var_map.find(
object);
37 const symbolt &symbol=ns.lookup(
object);
44 vars.w_buff0_used=
add(
object, symbol.
base_name,
"$w_buff0_used",
46 vars.w_buff1_used=
add(
object, symbol.
base_name,
"$w_buff1_used",
50 vars.flush_delayed=
add(
object, symbol.
base_name,
"$flush_delayed",
55 vars.read_delayed_var=
64 vars.r_buff0_thds.push_back(
70 vars.r_buff1_thds.push_back(
87 const std::string &suffix,
94 new_symbol.
name=identifier;
113 for(
const auto &vars :
var_map)
118 assignment(goto_program, t, source_location, vars.second.w_buff0_used,
120 assignment(goto_program, t, source_location, vars.second.w_buff1_used,
122 assignment(goto_program, t, source_location, vars.second.flush_delayed,
124 assignment(goto_program, t, source_location, vars.second.read_delayed,
126 assignment(goto_program, t, source_location, vars.second.read_delayed_var,
129 for(
const auto &
id : vars.second.r_buff0_thds)
132 for(
const auto &
id : vars.second.r_buff1_thds)
141 goto_functionst::function_mapt::iterator
145 throw "weak memory instrumentation needs an entry point";
160 std::string identifier=
id2string(id_lhs);
162 const size_t pos=identifier.find(
"[]");
164 if(
pos!=std::string::npos)
167 identifier.erase(
pos);
172 const exprt symbol=ns.
lookup(identifier).symbol_expr();
177 t->code.add_source_location()=source_location;
178 t->source_location=source_location;
184 catch(
const std::string &s)
202 assignment(goto_program, target, source_location, vars.read_delayed,
204 assignment(goto_program, target, source_location, vars.read_delayed_var,
209 assignment(goto_program, target, source_location, vars.read_new_var, new_var);
212 assignment(goto_program, target, source_location, write_object, new_var);
218 const std::string identifier=
id2string(write_object);
221 const varst &vars=(*this)(write_object);
248 const varst &vars=(*this)(write_object);
260 target->guard=if_expr;
262 target->source_location=source_location;
274 (void)source_location;
286 const unsigned current_thread)
288 const std::string identifier=
id2string(
object);
291 const varst &vars=(*this)(object);
296 goto_program, target, source_location, vars.
w_buff0,
297 original_instruction.
code.
op1());
317 const exprt cond_expr=
321 target->guard=cond_expr;
324 target->code.add_source_location()=source_location;
325 target->source_location=source_location;
348 const unsigned current_thread)
350 const std::string identifier=
id2string(
object);
355 const varst &vars=(*this)(object);
379 const exprt new_value_expr=
381 buff0_used_and_mine_expr,
384 buff1_used_and_mine_expr,
389 assignment(goto_program, target, source_location,
object, new_value_expr);
400 buff0_used_and_mine_expr,
407 const exprt buff0_or_buff1_used_and_mine_expr=
408 or_exprt(buff0_used_and_mine_expr, buff1_used_and_mine_expr);
416 buff0_or_buff1_used_and_mine_expr,
422 const exprt buff0_thd_expr=
434 const exprt buff1_thd_expr=
443 buff0_or_buff1_used_and_mine_expr,
454 const unsigned current_thread,
455 const bool tso_pso_rmo)
457 const std::string identifier=
id2string(
object);
463 const varst &vars=(*this)(object);
471 const exprt nondet_bool_expr =
475 assignment(goto_program, target, source_location, choice0, nondet_bool_expr);
476 assignment(goto_program, target, source_location, choice2, nondet_bool_expr);
498 goto_program, target, source_location, vars.
flush_delayed, delay_expr);
503 bool instrumented=
false;
509 typedef std::multimap<irep_idt, source_locationt>::iterator m_itt;
510 std::pair<m_itt, m_itt> ran=
cycles_loc.equal_range(
object);
511 for(m_itt ran_it=ran.first; ran_it!=ran.second; ran_it++)
512 if(ran_it->second==source_location)
521 if(tso_pso_rmo || !instrumented)
530 const exprt cond_134_expr=
540 const exprt val_134_expr=lhs;
541 const exprt buff0_used_134_expr=buff0_used_expr;
542 const exprt buff1_used_134_expr=buff1_used_expr;
543 const exprt buff0_134_expr=buff0_expr;
544 const exprt buff1_134_expr=buff1_expr;
545 const exprt buff0_thd_134_expr=buff0_thd_expr;
546 const exprt buff1_thd_134_expr=buff1_thd_expr;
551 const exprt cond_267_expr=
and_exprt(buff0_used_expr, buff0_thd_expr);
552 const exprt val_267_expr=buff0_expr;
555 const exprt buff0_267_expr=buff0_expr;
556 const exprt buff1_267_expr=buff1_expr;
563 const exprt cond_5_expr=
569 const exprt val_5_expr=buff1_expr;
570 const exprt buff0_used_5_expr=buff0_used_expr;
572 const exprt buff0_5_expr=buff0_expr;
573 const exprt buff1_5_expr=buff1_expr;
574 const exprt buff0_thd_5_expr=buff0_thd_expr;
638 buff0_used_5_expr))));
654 buff1_used_5_expr))));
670 buff0_thd_5_expr))));
685 buff1_thd_5_expr))));
698 goto_program, target, source_location, choice1, nondet_bool_expr);
706 const exprt val_1_expr=lhs;
707 const exprt buff0_used_1_expr=buff0_used_expr;
708 const exprt buff1_used_1_expr=buff1_used_expr;
709 const exprt buff0_1_expr=buff0_expr;
710 const exprt buff1_1_expr=buff1_expr;
711 const exprt buff0_thd_1_expr=buff0_thd_expr;
712 const exprt buff1_thd_1_expr=buff1_thd_expr;
717 const exprt cond_267_expr=
718 and_exprt(buff0_used_expr, buff0_thd_expr);
719 const exprt val_267_expr=buff0_expr;
722 const exprt buff0_267_expr=buff0_expr;
723 const exprt buff1_267_expr=buff1_expr;
730 const exprt cond_3_expr=
736 const exprt val_3_expr=
if_exprt(choice0_expr, buff0_expr, lhs);
737 const exprt buff0_used_3_expr=choice0_expr;
739 const exprt buff0_3_expr=buff0_expr;
740 const exprt buff1_3_expr=buff1_expr;
747 const exprt cond_4_expr=
751 const exprt val_4_expr=
759 const exprt buff0_used_4_expr=
761 const exprt buff1_used_4_expr=choice0_expr;
762 const exprt buff0_4_expr=buff0_expr;
763 const exprt buff1_4_expr=buff1_expr;
764 const exprt buff0_thd_4_expr=buff0_thd_expr;
765 const exprt buff1_thd_4_expr=
771 const exprt cond_5_expr=
773 and_exprt(buff0_used_expr, buff1_thd_expr),
775 const exprt val_5_expr=
780 const exprt buff0_used_5_expr=choice0_expr;
782 const exprt buff0_5_expr=buff0_expr;
783 const exprt buff1_5_expr=buff1_expr;
872 buff0_used_3_expr))))));
894 buff1_used_3_expr))))));
916 buff0_thd_3_expr))))));
938 buff1_thd_3_expr))))));
941 catch(
const std::string &s)
959 identifier==
"stdin" ||
960 identifier==
"stdout" ||
961 identifier==
"stderr" ||
962 identifier==
"sys_nerr" ||
1010 typedef std::multimap<irep_idt, source_locationt>::iterator m_itt;
1011 std::pair<m_itt, m_itt> ran=
cycles_loc.equal_range(identifier);
1012 for(m_itt ran_it=ran.first; ran_it!=ran.second; ran_it++)
1013 if(ran_it->second==source_location)
1046 <<
" reads from "<<
id2string(r_it->second.object)
1111 original_instruction.
swap(instruction);
1126 goto_program, i_it, source_location, e_it->second.object);
1130 goto_program, i_it, source_location, e_it->second.object,
1132 (model==
TSO || model==
PSO || model==
RMO));
1145 goto_program, i_it, source_location, r_it->second.object,
1146 e_it->second.object);
1153 goto_program, i_it, source_location,
1154 e_it->second.object, original_instruction,
1164 r_it->second.object)!=
1172 <<e_it->second.object
1179 r_it->second.object, vars.
type);
1191 const exprt nondet_bool_expr =
1211 goto_program, i_it, source_location,
1212 r_it->second.object, rhs);
1218 goto_program, i_it, source_location,
1219 e_it->second.object, original_instruction.
code.
op1());
1236 const exprt cond_expr=
if_exprt(delayed_expr, mem_value_expr,
1237 e_it->second.symbol_expr);
1240 goto_program, i_it, source_location,
1241 e_it->second.object, cond_expr);
1243 goto_program, i_it, source_location,
1249 i_it->make_atomic_end();
1250 i_it->source_location=source_location;
1261 else if(
is_fence(instruction, ns) ||
1270 original_instruction.
swap(instruction);
1280 for(std::set<irep_idt>::iterator s_it=
past_writes.begin();
1284 goto_program, i_it, source_location, *s_it,
1290 i_it->make_atomic_end();
1291 i_it->source_location=source_location;
const irep_idt & get_statement() const
void add_initialization_code(goto_functionst &goto_functions)
irep_idt function
The function this instruction belongs to.
The type of an expression, extends irept.
irep_idt name
The unique identifier.
const std::string & id2string(const irep_idt &d)
pointer_typet pointer_type(const typet &subtype)
targett insert_before(const_targett target)
Insertion before the instruction pointed-to by the given instruction iterator target.
goto_program_instruction_typet type
What kind of instruction?
bool is_function_call() const
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
void weak_memory(value_setst &value_sets, const irep_idt &function, memory_modelt model)
instruments the program for the pairs detected through the CFG
const irep_idt & get_identifier() const
#define forall_rw_set_w_entries(it, rw_set)
The null pointer constant.
exprt value
Initial value of symbol.
The trinary if-then-else operator.
function_mapt function_map
typet & type()
Return the type of the expression.
void add_initialization(goto_programt &goto_program)
irep_idt choice(const irep_idt &function, const std::string &suffix)
bool get_bool(const irep_namet &name) const
std::string unique()
returns a unique id (for fresh variables)
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...
bool is_buffered_in_general(const symbol_exprt &, bool is_write)
mstreamt & warning() const
bool is_fence(const goto_programt::instructiont &instruction, const namespacet &ns)
This class represents an instruction in the GOTO intermediate representation.
std::set< irep_idt > instrumentations
bool is_end_thread() const
goto_functionst & goto_functions
#define forall_rw_set_r_entries(it, rw_set)
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
The Boolean constant true.
irep_idt read_delayed_var
instructionst::iterator targett
virtual bool move(symbolt &symbol, symbolt *&new_symbol) override
Move a symbol into the symbol table.
std::set< irep_idt > past_writes
Operator to dereference a pointer.
#define INITIALIZE_FUNCTION
instructionst instructions
The list of instructions in the goto program.
void flush_read(goto_programt &goto_program, goto_programt::targett &t, const source_locationt &source_location, const irep_idt &write_object)
flushes read (POWER)
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
shared_bufferst & shared_buffers
std::vector< irep_idt > r_buff1_thds
A side_effect_exprt that returns a non-deterministically chosen value.
bool has_prefix(const std::string &s, const std::string &prefix)
const varst & operator()(const irep_idt &object)
instruments the variable
A collection of goto functions.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
irep_idt add_fresh_var(const irep_idt &object, const irep_idt &base_name, const std::string &suffix, const typet &type)
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Operator to return the address of an object.
The Boolean constant false.
std::multimap< irep_idt, source_locationt > cycles_loc
irep_idt add(const irep_idt &object, const irep_idt &base_name, const std::string &suffix, const typet &type, bool added_as_instrumentation)
add a new var for instrumenting the input var
std::vector< irep_idt > r_buff0_thds
A generic container class for the GOTO intermediate representation of one function.
A non-fatal assertion, which checks a condition then permits execution to continue.
typet type
Type of symbol.
void nondet_flush(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
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
source_locationt source_location
The location of the instruction in the source file.
Fences for instrumentation.
bool is_buffered(const namespacet &, const symbol_exprt &, bool is_write)
Base class for all expressions.
irep_idt base_name
Base (non-scoped) name.
symbol_tablet & symbol_table
#define Forall_goto_functions(it, functions)
const source_locationt & source_location() const
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)
void swap(instructiont &instruction)
Swap two instructions.
std::set< irep_idt > cycles
#define Forall_goto_program_instructions(it, program)
Expression to hold a symbol (variable)
class symbol_tablet & symbol_table
std::set< irep_idt > affected_by_delay_set
bool is_start_thread() const
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 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
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
A codet representing an assignment in the program.
const code_function_callt & to_code_function_call(const codet &code)
bool is_lwfence(const goto_programt::instructiont &instruction, const namespacet &ns)
Race Detection for Threaded Goto Programs.