9
9
// / on instrumentation of data passed in "instrumentation_propst" instance.
10
10
11
11
#include < taint-slicer/instrumenter.h>
12
+ #include < taint-slicer/irept_instrument.h>
12
13
#include < util/msgstream.h>
13
14
14
15
std::string taint_prefix_of_instrumented_variable ()
15
16
{
16
- return " __CPROVER_TAINT_SLICER_INSTRUMENTED_TOKEN_ " ;
17
+ return " @__CPROVER_ " ;
17
18
}
18
19
19
20
static std::string convert_token_id_to_program_identifier (
@@ -38,20 +39,61 @@ static std::string generate_fresh_automaton_variable_for_token(
38
39
return var_name;
39
40
}
40
41
42
+ static irept add_shadow_variables_to_type (
43
+ const irept &type,
44
+ const std::vector<taint_instrumentert::automaton_variable_idt> &vars,
45
+ const taint_datatype_infot &info)
46
+ {
47
+ if (type.id ()==ID_struct)
48
+ {
49
+ const struct_typet &struct_type=
50
+ to_struct_type (static_cast <const typet &>(type));
51
+ const auto tag=" java::" +as_string (struct_type.get_tag ());
52
+ if (tag==info.get_id ())
53
+ {
54
+ if (info.subclass_required ())
55
+ {
56
+ // TODO!
57
+ }
58
+ else
59
+ {
60
+ struct_typet result=struct_type;
61
+ struct_typet::componentst &components=result.components ();
62
+ for (const taint_instrumentert::automaton_variable_idt &var : vars)
63
+ {
64
+ components.push_back (struct_typet::componentt{
65
+ var, bool_typet () });
66
+ components.back ().set_pretty_name (var);
67
+ components.back ().set_access (ID_public);
68
+ }
69
+ return result;
70
+ }
71
+ }
72
+ }
73
+ return type;
74
+ }
75
+
41
76
taint_instrumentert::taint_instrumentert (
42
- const taint_instrumentation_propst &props ,
77
+ const taint_instrumentation_propst &in_props ,
43
78
const taint_programt *const in_program,
44
79
taint_statisticst *const in_statistics,
45
80
const bool use_data_flow_insensitive_instrumentation)
46
- : program(in_program)
81
+ : props(in_props)
82
+ , program(in_program)
47
83
, statistics(in_statistics)
48
84
, use_data_flow_insensitive_version(use_data_flow_insensitive_instrumentation)
49
85
{
50
- // The next line must be here in order to prevent clang produce the error:
51
- // `error: private field 'use_data_flow_insensitive_version' is not used
52
- // [-Werror,-Wunused-private-field]`
53
- (void )use_data_flow_insensitive_version;
86
+ }
54
87
88
+ // / Builds a new symbol table from the original symbol
89
+ // / table in in_program->get_symbol_table(), by removing of symbols not related
90
+ // / to the set of functions defined in the passed instrumentation properties.
91
+ // / The function also build a new set of functions from those defined in
92
+ // / in_program->get_functions() and which appear in props.get_location_props().
93
+ // / These functions are instrumented by a new code accodring to recipes in
94
+ // / individual elements of props.get_location_props().
95
+ void taint_instrumentert::run ()
96
+ {
55
97
assert (program!=nullptr );
56
98
assert (statistics!=nullptr );
57
99
@@ -129,6 +171,13 @@ taint_instrumentert::taint_instrumentert(
129
171
instr.type =ASSUME;
130
172
}
131
173
174
+ if (!use_data_flow_insensitive_version)
175
+ {
176
+ // Now we introduce shadow variables as members of (1) existing types
177
+ // and (2) newly created types (for basic types).
178
+ instrument_data_types (props);
179
+ }
180
+
132
181
// We have to change the way how we identify instrumentation locations.
133
182
// Namely, instead of using iterators for referencing instructions we have to
134
183
// switch to distances from the first instruction. This is because we operate
@@ -182,6 +231,32 @@ taint_instrumentert::taint_instrumentert(
182
231
statistics=nullptr ;
183
232
}
184
233
234
+ void taint_instrumentert::instrument_data_types (
235
+ const taint_instrumentation_propst &props)
236
+ {
237
+ std::set<irep_idt> new_type_names;
238
+ for (const auto &id_info : props.get_datatypes ())
239
+ {
240
+ std::vector<automaton_variable_idt> vars;
241
+ for (const auto &token : id_info.second .get_tokens ())
242
+ vars.push_back (from_tokens_to_vars.at (token));
243
+ if (id_info.second .subclass_required ())
244
+ {
245
+ // TODO!
246
+ }
247
+ else
248
+ {
249
+ symbolt &symbol=instrumented_symbol_table.lookup (id_info.first );
250
+ const irept itype=instrument (symbol.type , std::bind (
251
+ &add_shadow_variables_to_type,
252
+ std::placeholders::_1,
253
+ std::cref (vars),
254
+ std::cref (id_info.second )));
255
+ symbol.type =static_cast <const typet&>(itype);
256
+ }
257
+ }
258
+ }
259
+
185
260
std::size_t taint_instrumentert::instrument_location (
186
261
const taint_instrumentation_propst::location_props_idt lid,
187
262
const std::size_t instruction_index,
0 commit comments