Skip to content

Commit 1396782

Browse files
Merge pull request #7523 from peterschrammel/shadow-memory-basic
Shadow memory interface and integration hooks [blocks 7535]
2 parents 882bd0d + 67ce46b commit 1396782

21 files changed

+513
-55
lines changed

src/goto-checker/multi_path_symex_only_checker.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, Peter Schrammel
1313

1414
#include <util/ui_message.h>
1515

16+
#include <goto-symex/shadow_memory.h>
1617
#include <goto-symex/show_program.h>
1718
#include <goto-symex/show_vcc.h>
1819

@@ -72,10 +73,14 @@ operator()(propertiest &properties)
7273

7374
void multi_path_symex_only_checkert::generate_equation()
7475
{
76+
// Gather fields for shadow memory instrumentation
77+
const auto fields =
78+
shadow_memoryt::gather_field_declarations(goto_model, ui_message_handler);
79+
7580
const auto symex_start = std::chrono::steady_clock::now();
7681

77-
symex_symbol_table =
78-
symex.symex_from_entry_point_of(goto_symext::get_goto_function(goto_model));
82+
symex_symbol_table = symex.symex_from_entry_point_of(
83+
goto_symext::get_goto_function(goto_model), fields);
7984

8085
const auto symex_stop = std::chrono::steady_clock::now();
8186
std::chrono::duration<double> symex_runtime =

src/goto-checker/single_path_symex_only_checker.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, Peter Schrammel
1414
#include <util/ui_message.h>
1515

1616
#include <goto-symex/path_storage.h>
17+
#include <goto-symex/shadow_memory.h>
1718
#include <goto-symex/show_program.h>
1819
#include <goto-symex/show_vcc.h>
1920

@@ -73,8 +74,12 @@ void single_path_symex_only_checkert::initialize_worklist()
7374
unwindset);
7475
setup_symex(symex);
7576

77+
// Gather fields for shadow memory instrumentation
78+
const auto fields =
79+
shadow_memoryt::gather_field_declarations(goto_model, ui_message_handler);
80+
7681
symex.initialize_path_storage_from_entry_point_of(
77-
goto_symext::get_goto_function(goto_model), symex_symbol_table);
82+
goto_symext::get_goto_function(goto_model), symex_symbol_table, fields);
7883
}
7984

8085
bool single_path_symex_only_checkert::has_finished_exploration(

src/goto-symex/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ SRC = auto_objects.cpp \
1414
postcondition.cpp \
1515
precondition.cpp \
1616
renaming_level.cpp \
17+
shadow_memory.cpp \
1718
show_program.cpp \
1819
show_vcc.cpp \
1920
slice.cpp \

src/goto-symex/goto_symex.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void goto_symext::symex_assign(
104104
assignment_type = symex_targett::assignment_typet::HIDDEN;
105105

106106
symex_assignt symex_assign{
107-
state, assignment_type, ns, symex_config, target};
107+
shadow_memory, state, assignment_type, ns, symex_config, target};
108108

109109
// Try to constant propagate potential side effects of the assignment, when
110110
// simplification is turned on and there is one thread only. Constant
@@ -118,8 +118,9 @@ void goto_symext::symex_assign(
118118
}
119119

120120
exprt::operandst lhs_if_then_else_conditions;
121-
symex_assign.assign_rec(
122-
lhs, expr_skeletont{}, rhs, lhs_if_then_else_conditions);
121+
symex_assignt{
122+
shadow_memory, state, assignment_type, ns, symex_config, target}
123+
.assign_rec(lhs, expr_skeletont{}, rhs, lhs_if_then_else_conditions);
123124
}
124125
}
125126

src/goto-symex/goto_symex.h

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ Author: Daniel Kroening, [email protected]
1515
#include <util/message.h>
1616

1717
#include "complexity_limiter.h"
18+
#include "shadow_memory.h"
1819
#include "symex_config.h"
1920
#include "symex_target_equation.h"
2021

2122
class address_of_exprt;
2223
class function_application_exprt;
2324
class goto_symex_statet;
2425
class path_storaget;
26+
class shadow_memory_field_definitionst;
2527
class side_effect_exprt;
2628
class symex_assignt;
2729
class typet;
@@ -65,7 +67,16 @@ class goto_symext
6567
path_segment_vccs(0),
6668
_total_vccs(std::numeric_limits<unsigned>::max()),
6769
_remaining_vccs(std::numeric_limits<unsigned>::max()),
68-
complexity_module(mh, options)
70+
complexity_module(mh, options),
71+
shadow_memory(
72+
std::bind(
73+
&goto_symext::symex_assign,
74+
this,
75+
std::placeholders::_1,
76+
std::placeholders::_2,
77+
std::placeholders::_3),
78+
ns,
79+
mh)
6980
{
7081
}
7182

@@ -98,16 +109,24 @@ class goto_symext
98109
/// having the state around afterwards.
99110
/// \param get_goto_function: The delegate to retrieve function bodies (see
100111
/// \ref get_goto_functiont)
112+
/// \param fields The shadow memory field declarations
101113
/// \return A symbol table holding the symbols added during symbolic
102114
/// execution.
103115
NODISCARD
104-
virtual symbol_tablet
105-
symex_from_entry_point_of(const get_goto_functiont &get_goto_function);
116+
virtual symbol_tablet symex_from_entry_point_of(
117+
const get_goto_functiont &get_goto_function,
118+
const shadow_memory_field_definitionst &fields);
106119

107120
/// Puts the initial state of the entry point function into the path storage
121+
/// \param get_goto_function: The delegate to retrieve function bodies (see
122+
/// \ref get_goto_functiont)
123+
/// \param new_symbol_table: A symbol table to store the symbols added during
124+
/// symbolic execution
125+
/// \param fields The shadow memory field declarations
108126
virtual void initialize_path_storage_from_entry_point_of(
109127
const get_goto_functiont &get_goto_function,
110-
symbol_table_baset &new_symbol_table);
128+
symbol_table_baset &new_symbol_table,
129+
const shadow_memory_field_definitionst &fields);
111130

112131
/// Performs symbolic execution using a state and equation that have
113132
/// already been used to symbolically execute part of the program. The state
@@ -446,6 +465,16 @@ class goto_symext
446465
statet &state,
447466
const goto_programt::instructiont &instruction);
448467

468+
/// Preserves locality of parameters of a given function by applying L1
469+
/// renaming to them.
470+
/// \param function_identifier The parameter identifier
471+
/// \param state The current state
472+
/// \param goto_function The goto function
473+
virtual void locality(
474+
const irep_idt &function_identifier,
475+
goto_symext::statet &state,
476+
const goto_functionst::goto_functiont &goto_function);
477+
449478
/// Symbolically execute a END_FUNCTION instruction.
450479
/// \param state: Symbolic execution state for current instruction
451480
virtual void symex_end_of_function(statet &);
@@ -815,6 +844,9 @@ class goto_symext
815844

816845
complexity_limitert complexity_module;
817846

847+
/// Shadow memory instrumentation API
848+
shadow_memoryt shadow_memory;
849+
818850
public:
819851
unsigned get_total_vccs() const
820852
{

src/goto-symex/goto_symex_state.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Author: Daniel Kroening, [email protected]
2424
#include "field_sensitivity.h"
2525
#include "goto_state.h"
2626
#include "renaming_level.h"
27+
#include "shadow_memory_state.h"
2728

2829
#include <functional>
2930
#include <memory>
@@ -121,6 +122,8 @@ class goto_symex_statet final : public goto_statet
121122

122123
field_sensitivityt field_sensitivity;
123124

125+
shadow_memory_statet shadow_memory;
126+
124127
protected:
125128
template <levelt>
126129
void rename_address(exprt &expr, const namespacet &ns);

src/goto-symex/shadow_memory.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*******************************************************************\
2+
3+
Module: Symex Shadow Memory Instrumentation
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Symex Shadow Memory Instrumentation
11+
12+
#include "shadow_memory.h"
13+
14+
#include <util/fresh_symbol.h>
15+
16+
#include <langapi/language_util.h>
17+
18+
#include "goto_symex_state.h"
19+
20+
void shadow_memoryt::initialize_shadow_memory(
21+
goto_symex_statet &state,
22+
const exprt &expr,
23+
const shadow_memory_field_definitionst::field_definitiont &fields)
24+
{
25+
// To be implemented
26+
}
27+
28+
symbol_exprt shadow_memoryt::add_field(
29+
goto_symex_statet &state,
30+
const exprt &expr,
31+
const irep_idt &field_name,
32+
const typet &field_type)
33+
{
34+
// To be completed
35+
36+
const auto &function_symbol = ns.lookup(state.source.function_id);
37+
38+
symbolt &new_symbol = get_fresh_aux_symbol(
39+
field_type,
40+
id2string(state.source.function_id),
41+
SHADOW_MEMORY_PREFIX + from_expr(expr) + "__" + id2string(field_name),
42+
state.source.pc->source_location(),
43+
function_symbol.mode,
44+
state.symbol_table);
45+
46+
// Call some function on ns to silence the compiler in the meanwhile.
47+
ns.get_symbol_table();
48+
49+
return new_symbol.symbol_expr();
50+
}
51+
52+
void shadow_memoryt::symex_set_field(
53+
goto_symex_statet &state,
54+
const exprt::operandst &arguments)
55+
{
56+
// To be implemented
57+
}
58+
59+
void shadow_memoryt::symex_get_field(
60+
goto_symex_statet &state,
61+
const exprt &lhs,
62+
const exprt::operandst &arguments)
63+
{
64+
// To be implemented
65+
}
66+
67+
void shadow_memoryt::symex_field_static_init(
68+
goto_symex_statet &state,
69+
const ssa_exprt &lhs)
70+
{
71+
// To be implemented
72+
}
73+
74+
void shadow_memoryt::symex_field_static_init_string_constant(
75+
goto_symex_statet &state,
76+
const ssa_exprt &expr,
77+
const exprt &rhs)
78+
{
79+
// To be implemented
80+
}
81+
82+
void shadow_memoryt::symex_field_local_init(
83+
goto_symex_statet &state,
84+
const ssa_exprt &expr)
85+
{
86+
// To be implemented
87+
}
88+
89+
void shadow_memoryt::symex_field_dynamic_init(
90+
goto_symex_statet &state,
91+
const exprt &expr,
92+
const side_effect_exprt &code)
93+
{
94+
// To be implemented
95+
}
96+
97+
shadow_memory_field_definitionst shadow_memoryt::gather_field_declarations(
98+
abstract_goto_modelt &goto_model,
99+
message_handlert &message_handler)
100+
{
101+
// To be implemented
102+
103+
return shadow_memory_field_definitionst();
104+
}
105+
106+
void shadow_memoryt::convert_field_declaration(
107+
const code_function_callt &code_function_call,
108+
shadow_memory_field_definitionst::field_definitiont &fields)
109+
{
110+
// To be implemented
111+
}

0 commit comments

Comments
 (0)