Skip to content

Commit 2c13a21

Browse files
committed
Split l2_thread_write_encoding apart from write_is_shared
l2_thread_write_encoding both makes a quite complicated test regarding whether a write is to be considered shared state, and also enacts some side-effects for both shared and non-shared state. This splits part of its testing into write_is_shared. No behavioural change.
1 parent 96c82a9 commit 2c13a21

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,32 +472,47 @@ void goto_symex_statet::increase_generation_if_exists(const irep_idt identifier)
472472
current_names_iter->second.second = fresh_l2_name_provider(identifier);
473473
}
474474

475-
/// thread encoding
476-
bool goto_symex_statet::l2_thread_write_encoding(
475+
goto_symex_statet::write_is_shared_resultt goto_symex_statet::write_is_shared(
477476
const ssa_exprt &expr,
478-
const namespacet &ns)
477+
const namespacet &ns) const
479478
{
480479
if(!record_events)
481-
return false;
480+
return write_is_shared_resultt::NOT_SHARED;
482481

483-
// is it a shared object?
484-
const irep_idt &obj_identifier=expr.get_object_name();
482+
const irep_idt &obj_identifier = expr.get_object_name();
485483
if(
486484
obj_identifier == guard_identifier() ||
487485
(!ns.lookup(obj_identifier).is_shared() && !(dirty)(obj_identifier)))
488486
{
489-
return false; // not shared
487+
return write_is_shared_resultt::NOT_SHARED;
490488
}
491489

492-
// see whether we are within an atomic section
493-
if(atomic_section_id!=0)
490+
if(atomic_section_id != 0)
491+
return write_is_shared_resultt::IN_ATOMIC_SECTION;
492+
493+
return write_is_shared_resultt::SHARED;
494+
}
495+
496+
/// thread encoding
497+
bool goto_symex_statet::l2_thread_write_encoding(
498+
const ssa_exprt &expr,
499+
const namespacet &ns)
500+
{
501+
switch(write_is_shared(expr, ns))
502+
{
503+
case write_is_shared_resultt::NOT_SHARED:
504+
return false;
505+
case write_is_shared_resultt::IN_ATOMIC_SECTION:
494506
{
495-
ssa_exprt ssa_l1=expr;
507+
ssa_exprt ssa_l1 = expr;
496508
ssa_l1.remove_level_2();
497509

498510
written_in_atomic_section[ssa_l1].push_back(guard);
499511
return false;
500512
}
513+
case write_is_shared_resultt::SHARED:
514+
break;
515+
}
501516

502517
// record a shared write
503518
symex_target->shared_write(
@@ -507,7 +522,7 @@ bool goto_symex_statet::l2_thread_write_encoding(
507522
source);
508523

509524
// do we have threads?
510-
return threads.size()>1;
525+
return threads.size() > 1;
511526
}
512527

513528
template <levelt level>

src/goto-symex/goto_symex_state.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,17 @@ class goto_symex_statet final : public goto_statet
181181

182182
std::vector<threadt> threads;
183183

184+
enum class write_is_shared_resultt
185+
{
186+
NOT_SHARED,
187+
IN_ATOMIC_SECTION,
188+
SHARED
189+
};
190+
184191
bool l2_thread_read_encoding(ssa_exprt &expr, const namespacet &ns);
185192
bool l2_thread_write_encoding(const ssa_exprt &expr, const namespacet &ns);
193+
write_is_shared_resultt
194+
write_is_shared(const ssa_exprt &expr, const namespacet &ns) const;
186195

187196
bool record_events;
188197

0 commit comments

Comments
 (0)