Skip to content

Commit c5e18bd

Browse files
marek-trtiksmowton
authored andcommitted
Instrumentation of shadow vars as class members into symbols table.
1 parent f20fef6 commit c5e18bd

File tree

2 files changed

+74
-4
lines changed

2 files changed

+74
-4
lines changed

src/taint-slicer/instrumenter.cpp

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
/// on instrumentation of data passed in "instrumentation_propst" instance.
1010

1111
#include <taint-slicer/instrumenter.h>
12+
#include <taint-slicer/irept_instrument.h>
1213
#include <util/msgstream.h>
1314

1415
std::string taint_prefix_of_instrumented_variable()
1516
{
16-
return "__CPROVER_TAINT_SLICER_INSTRUMENTED_TOKEN_";
17+
return "@__CPROVER_";
1718
}
1819

1920
static std::string convert_token_id_to_program_identifier(
@@ -38,6 +39,40 @@ static std::string generate_fresh_automaton_variable_for_token(
3839
return var_name;
3940
}
4041

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+
4176
taint_instrumentert::taint_instrumentert(
4277
const taint_instrumentation_propst &props,
4378
const taint_programt *const in_program,
@@ -129,6 +164,13 @@ taint_instrumentert::taint_instrumentert(
129164
instr.type=ASSUME;
130165
}
131166

167+
if(!use_data_flow_insensitive_version)
168+
{
169+
// Now we introduce shadow variables as members of (1) existing types
170+
// and (2) newly created types (for basic types).
171+
instrument_data_types(props);
172+
}
173+
132174
// We have to change the way how we identify instrumentation locations.
133175
// Namely, instead of using iterators for referencing instructions we have to
134176
// switch to distances from the first instruction. This is because we operate
@@ -182,6 +224,32 @@ taint_instrumentert::taint_instrumentert(
182224
statistics=nullptr;
183225
}
184226

227+
void taint_instrumentert::instrument_data_types(
228+
const taint_instrumentation_propst &props)
229+
{
230+
std::set<irep_idt> new_type_names;
231+
for(const auto &id_info : props.get_datatypes())
232+
{
233+
std::vector<automaton_variable_idt> vars;
234+
for(const auto &token : id_info.second.get_tokens())
235+
vars.push_back(from_tokens_to_vars.at(token));
236+
if(id_info.second.subclass_required())
237+
{
238+
// TODO!
239+
}
240+
else
241+
{
242+
symbolt &symbol=instrumented_symbol_table.lookup(id_info.first);
243+
const irept itype=instrument(symbol.type, std::bind(
244+
&add_shadow_variables_to_type,
245+
std::placeholders::_1,
246+
std::cref(vars),
247+
std::cref(id_info.second)));
248+
symbol.type=static_cast<const typet&>(itype);
249+
}
250+
}
251+
}
252+
185253
std::size_t taint_instrumentert::instrument_location(
186254
const taint_instrumentation_propst::location_props_idt lid,
187255
const std::size_t instruction_index,

src/taint-slicer/instrumenter.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class taint_instrumentert
4141
Outputs:
4242
4343
Purpose: The function builds a new symbol table from the original symbol
44-
table in _program->get_symbol_table(), by removing of symbols not related
44+
table in in_program->get_symbol_table(), by removing of symbols not related
4545
to the set of functions defined in the passed instrumentation properties.
46-
The function also build a new set of function from those defined in
47-
_program->get_functions() and which appear in props.get_location_props().
46+
The function also build a new set of functions from those defined in
47+
in_program->get_functions() and which appear in props.get_location_props().
4848
These functions are instrumented by a new code accodring to recipes in
4949
individual elements of props.get_location_props().
5050
@@ -66,6 +66,8 @@ class taint_instrumentert
6666

6767
private:
6868

69+
void instrument_data_types(const taint_instrumentation_propst &props);
70+
6971
/*******************************************************************\
7072
7173
Function: instrument_location

0 commit comments

Comments
 (0)