Skip to content

Commit 55eec59

Browse files
Merge pull request diffblue#3988 from romainbrenguier/refactor/symex-rename1
Refactoring in goto_symex
2 parents 358d070 + 2c74ebe commit 55eec59

File tree

9 files changed

+27
-52
lines changed

9 files changed

+27
-52
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,9 @@ void goto_symex_statet::rename(
701701
}
702702
}
703703

704+
// expand struct and union tag types
705+
type = ns.follow(type);
706+
704707
if(type.id()==ID_array)
705708
{
706709
auto &array_type = to_array_type(type);
@@ -725,24 +728,6 @@ void goto_symex_statet::rename(
725728
{
726729
rename(to_pointer_type(type).subtype(), irep_idt(), ns, level);
727730
}
728-
else if(type.id() == ID_symbol_type)
729-
{
730-
const symbolt &symbol = ns.lookup(to_symbol_type(type));
731-
type = symbol.type;
732-
rename(type, l1_identifier, ns, level);
733-
}
734-
else if(type.id() == ID_union_tag)
735-
{
736-
const symbolt &symbol = ns.lookup(to_union_tag_type(type));
737-
type = symbol.type;
738-
rename(type, l1_identifier, ns, level);
739-
}
740-
else if(type.id() == ID_struct_tag)
741-
{
742-
const symbolt &symbol = ns.lookup(to_struct_tag_type(type));
743-
type=symbol.type;
744-
rename(type, l1_identifier, ns, level);
745-
}
746731

747732
if(level==L2 &&
748733
!l1_identifier.empty())

src/goto-symex/renaming_level.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Author: Romain Brenguier, [email protected]
1818
#include "goto_symex_state.h"
1919

2020
void symex_level0t::
21-
operator()(ssa_exprt &ssa_expr, const namespacet &ns, unsigned thread_nr)
21+
operator()(ssa_exprt &ssa_expr, const namespacet &ns, unsigned thread_nr) const
2222
{
2323
// already renamed?
2424
if(!ssa_expr.get_level_0().empty())
@@ -42,7 +42,7 @@ operator()(ssa_exprt &ssa_expr, const namespacet &ns, unsigned thread_nr)
4242
ssa_expr.set_level_0(thread_nr);
4343
}
4444

45-
void symex_level1t::operator()(ssa_exprt &ssa_expr)
45+
void symex_level1t::operator()(ssa_exprt &ssa_expr) const
4646
{
4747
// already renamed?
4848
if(!ssa_expr.get_level_1().empty())

src/goto-symex/renaming_level.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ struct symex_renaming_levelt
5656
/// The renaming is built for one particular interleaving.
5757
struct symex_level0t : public symex_renaming_levelt
5858
{
59-
void
60-
operator()(ssa_exprt &ssa_expr, const namespacet &ns, unsigned thread_nr);
59+
void operator()(ssa_exprt &ssa_expr, const namespacet &ns, unsigned thread_nr)
60+
const;
6161

6262
symex_level0t() = default;
6363
~symex_level0t() override = default;
@@ -68,7 +68,7 @@ struct symex_level0t : public symex_renaming_levelt
6868
/// This is to preserve locality in case of recursion
6969
struct symex_level1t : public symex_renaming_levelt
7070
{
71-
void operator()(ssa_exprt &ssa_expr);
71+
void operator()(ssa_exprt &ssa_expr) const;
7272

7373
/// Insert the content of \p other into this renaming
7474
void restore_from(const current_namest &other);

src/goto-symex/symex_dead.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ void goto_symext::symex_dead(statet &state)
3232
// in case of pointers, put something into the value set
3333
if(code.symbol().type().id() == ID_pointer)
3434
{
35-
exprt failed = get_failed_symbol(to_symbol_expr(code.symbol()), ns);
36-
3735
exprt rhs;
38-
39-
if(failed.is_not_nil())
40-
rhs = address_of_exprt(failed, to_pointer_type(code.symbol().type()));
36+
if(auto failed = get_failed_symbol(to_symbol_expr(code.symbol()), ns))
37+
rhs = address_of_exprt(*failed, to_pointer_type(code.symbol().type()));
4138
else
4239
rhs=exprt(ID_invalid);
4340

src/goto-symex/symex_decl.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,9 @@ void goto_symext::symex_decl(statet &state, const symbol_exprt &expr)
4848
// in case of pointers, put something into the value set
4949
if(expr.type().id() == ID_pointer)
5050
{
51-
exprt failed=
52-
get_failed_symbol(expr, ns);
53-
5451
exprt rhs;
55-
56-
if(failed.is_not_nil())
57-
rhs=address_of_exprt(failed, to_pointer_type(expr.type()));
52+
if(auto failed = get_failed_symbol(expr, ns))
53+
rhs = address_of_exprt(*failed, to_pointer_type(expr.type()));
5854
else
5955
rhs=exprt(ID_invalid);
6056

src/goto-symex/symex_start_thread.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ void goto_symext::symex_start_thread(statet &state)
6868
lhs.set_level_0(t);
6969

7070
// set up L1 name
71-
if(!state.level1.current_names.insert(
72-
std::make_pair(lhs.get_l1_object_identifier(),
73-
std::make_pair(lhs, 0))).second)
74-
UNREACHABLE;
71+
auto emplace_result = state.level1.current_names.emplace(
72+
std::piecewise_construct,
73+
std::forward_as_tuple(lhs.get_l1_object_identifier()),
74+
std::forward_as_tuple(lhs, 0));
75+
CHECK_RETURN(emplace_result.second);
7576
state.rename(lhs, ns, goto_symex_statet::L1);
7677
const irep_idt l1_name=lhs.get_l1_object_identifier();
7778
// store it

src/pointer-analysis/add_failed_symbols.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,16 @@ void add_failed_symbols(symbol_table_baset &symbol_table)
8989
/// Get the failed-dereference symbol for the given symbol
9090
/// \param expr: symbol expression to get a failed symbol for
9191
/// \param ns: global namespace
92-
/// \return symbol expression for the failed-dereference symbol, or nil_exprt
93-
/// if none exists.
94-
exprt get_failed_symbol(
95-
const symbol_exprt &expr,
96-
const namespacet &ns)
92+
/// \return symbol expression for the failed-dereference symbol, or an empty
93+
/// optional if none exists.
94+
optionalt<symbol_exprt>
95+
get_failed_symbol(const symbol_exprt &expr, const namespacet &ns)
9796
{
9897
const symbolt &symbol=ns.lookup(expr);
9998
irep_idt failed_symbol_id=symbol.type.get(ID_C_failed_symbol);
10099

101100
if(failed_symbol_id.empty())
102-
return nil_exprt();
101+
return {};
103102

104103
const symbolt &failed_symbol=ns.lookup(failed_symbol_id);
105104

src/pointer-analysis/add_failed_symbols.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#define CPROVER_POINTER_ANALYSIS_ADD_FAILED_SYMBOLS_H
1414

1515
#include <util/irep.h>
16+
#include <util/optional.h>
1617

1718
class symbol_table_baset;
1819
class symbolt;
@@ -27,8 +28,7 @@ void add_failed_symbol_if_needed(
2728

2829
irep_idt failed_symbol_id(const irep_idt &identifier);
2930

30-
exprt get_failed_symbol(
31-
const symbol_exprt &expr,
32-
const namespacet &ns);
31+
optionalt<symbol_exprt>
32+
get_failed_symbol(const symbol_exprt &expr, const namespacet &ns);
3333

3434
#endif // CPROVER_POINTER_ANALYSIS_ADD_FAILED_SYMBOLS_H

src/pointer-analysis/value_set.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,12 +1471,9 @@ void value_sett::apply_code_rec(
14711471
(lhs_type.id() == ID_array && lhs_type.subtype().id() == ID_pointer))
14721472
{
14731473
// assign the address of the failed object
1474-
exprt failed=get_failed_symbol(to_symbol_expr(lhs), ns);
1475-
1476-
if(failed.is_not_nil())
1474+
if(auto failed = get_failed_symbol(to_symbol_expr(lhs), ns))
14771475
{
1478-
address_of_exprt address_of_expr(
1479-
failed, to_pointer_type(lhs.type()));
1476+
address_of_exprt address_of_expr(*failed, to_pointer_type(lhs.type()));
14801477
assign(lhs, address_of_expr, ns, false, false);
14811478
}
14821479
else

0 commit comments

Comments
 (0)