16
16
#include < util/arith_tools.h>
17
17
#include < util/pointer_offset_size.h>
18
18
#include < util/msgstream.h>
19
+ #include < util/std_expr.h>
20
+
21
+ const c_bool_typet &get_shadow_variable_type ()
22
+ {
23
+ static c_bool_typet type (8 );
24
+ return type;
25
+ }
26
+
27
+ const irep_idt &get_shadow_variable_type_id ()
28
+ {
29
+ return ID_c_bool;
30
+ }
31
+
32
+ const constant_exprt &get_shadow_variable_value_true ()
33
+ {
34
+ static constant_exprt value = from_integer (1 , get_shadow_variable_type ());
35
+ return value;
36
+ }
37
+
38
+ const constant_exprt &get_shadow_variable_value_false ()
39
+ {
40
+ static constant_exprt value = from_integer (0 , get_shadow_variable_type ());
41
+ return value;
42
+ }
19
43
20
44
const std::string &taint_prefix_of_instrumented_variable ()
21
45
{
@@ -132,10 +156,10 @@ exprt make_or_update_initialiser(
132
156
{
133
157
if (names_of_shadow_variables.count (as_string (component.get_name ()))!=0UL )
134
158
{
135
- INVARIANT (component.type ().id ()==ID_bool,
159
+ INVARIANT (
160
+ component.type ().id ()==get_shadow_variable_type_id (),
136
161
" Shadow variables must be bool-typed." );
137
- fixed_initialiser.copy_to_operands (
138
- constant_exprt (ID_false, bool_typet ()));
162
+ fixed_initialiser.copy_to_operands (get_shadow_variable_value_false ());
139
163
}
140
164
else
141
165
{
@@ -188,14 +212,12 @@ static void get_access_paths_to_shadow_vars(
188
212
const struct_typet struc=to_struct_type (expr.type ());
189
213
for (const struct_union_typet::componentt &member : struc.components ())
190
214
{
191
- if (member.type ().id ()==ID_bool )
215
+ if (member.type ().id () == get_shadow_variable_type_id () )
192
216
{
193
217
if (names_of_shadow_variables.count (as_string (member.get_name ()))!=0UL )
194
218
{
195
- access_paths.insert (member_exprt (
196
- expr,
197
- member.get_name (),
198
- bool_typet ()));
219
+ access_paths.insert (
220
+ member_exprt (expr, member.get_name (), get_shadow_variable_type ()));
199
221
}
200
222
}
201
223
else if (member.type ().id ()==ID_struct)
@@ -438,13 +460,15 @@ exprt taint_instrumentert::drive_access_path_through_super_classes(
438
460
component.get_name ())
439
461
)
440
462
{
441
- struct_expr.operands ().push_back (member_exprt (
442
- uncast_access_path, component.get_name (), bool_typet ()));
463
+ struct_expr.operands ().push_back (
464
+ member_exprt (
465
+ uncast_access_path,
466
+ component.get_name (),
467
+ get_shadow_variable_type ()));
443
468
}
444
469
else
445
470
{
446
- struct_expr.operands ().push_back (
447
- constant_exprt (ID_false, bool_typet ()));
471
+ struct_expr.operands ().push_back (get_shadow_variable_value_false ());
448
472
}
449
473
}
450
474
}
@@ -573,9 +597,8 @@ void taint_instrumentert::instrument_instructions_with_shadow_variables(
573
597
for (const exprt &access_path : access_paths)
574
598
{
575
599
auto iit=instrumentation_code.add_instruction (ASSIGN);
576
- iit->code =code_assignt (
577
- access_path,
578
- constant_exprt (ID_false, typet (ID_bool)));
600
+ iit->code =
601
+ code_assignt (access_path, get_shadow_variable_value_false ());
579
602
iit->function =instr_it->function ;
580
603
}
581
604
@@ -667,7 +690,8 @@ void taint_instrumentert::instrument_instructions_with_shadow_variables(
667
690
if (shadows.count (as_string (component.get_name ())))
668
691
{
669
692
member_exprt shadow_member (code_decl.symbol (), component);
670
- code_assignt init_member (shadow_member, false_exprt ());
693
+ code_assignt init_member (
694
+ shadow_member, get_shadow_variable_value_false ());
671
695
auto new_instruction=
672
696
program_to_be_instrumented.insert_after (instr_it);
673
697
new_instruction->make_assignment (init_member);
@@ -843,8 +867,8 @@ void taint_instrumentert::run()
843
867
for (const auto &tid_var : from_tokens_to_vars)
844
868
{
845
869
symbolt symbol;
846
- symbol.type = typet (ID_bool );
847
- symbol.value = constant_exprt (ID_false, typet (ID_bool) );
870
+ symbol.type = get_shadow_variable_type ( );
871
+ symbol.value = get_shadow_variable_value_false ( );
848
872
symbol.location =source_locationt ();
849
873
symbol.name =tid_var.second ;
850
874
symbol.module =" " ;
@@ -936,7 +960,7 @@ void taint_instrumentert::instrument_data_types(
936
960
components.push_back (base_component);
937
961
for (const auto &var : vars)
938
962
{
939
- struct_typet::componentt component (var, bool_typet ());
963
+ struct_typet::componentt component (var, get_shadow_variable_type ());
940
964
component.set_base_name (var);
941
965
component.set_pretty_name (var);
942
966
components.push_back (component);
@@ -981,7 +1005,8 @@ void taint_instrumentert::instrument_data_types(
981
1005
{
982
1006
if (!struct_type.has_component (var))
983
1007
{
984
- components.push_back (struct_typet::componentt{var, bool_typet ()});
1008
+ components.push_back (
1009
+ struct_typet::componentt{var, get_shadow_variable_type ()});
985
1010
components.back ().set_pretty_name (var);
986
1011
components.back ().set_access (ID_public);
987
1012
}
@@ -1061,8 +1086,8 @@ static exprt make_accessor_expression_to_shadow_variable(
1061
1086
const struct_typet &struct_type = to_struct_type (type);
1062
1087
if (struct_type.has_component (shadow_variable_name))
1063
1088
{
1064
- access_path =
1065
- member_exprt ( access_path, shadow_variable_name, bool_typet ());
1089
+ access_path = member_exprt (
1090
+ access_path, shadow_variable_name, get_shadow_variable_type ());
1066
1091
break ;
1067
1092
}
1068
1093
const struct_typet::componentst &components = struct_type.components ();
@@ -1126,10 +1151,12 @@ void taint_instrumentert::instrument_location(
1126
1151
fn_call,
1127
1152
assumption.get_argidx (),
1128
1153
instrumented_symbol_table);
1129
- const exprt proposition = make_accessor_expression_to_shadow_variable (
1130
- acc_path,
1131
- from_tokens_to_vars.at (assumption.get_token_name ()),
1132
- instrumented_symbol_table);
1154
+ const exprt proposition = equal_exprt (
1155
+ make_accessor_expression_to_shadow_variable (
1156
+ acc_path,
1157
+ from_tokens_to_vars.at (assumption.get_token_name ()),
1158
+ instrumented_symbol_table),
1159
+ get_shadow_variable_value_true ());
1133
1160
conjuncts.push_back (proposition);
1134
1161
}
1135
1162
auto iit=instrumentation_code.add_instruction ();
@@ -1143,10 +1170,10 @@ void taint_instrumentert::instrument_location(
1143
1170
{
1144
1171
static void make_assignments_to_shadow_variables (
1145
1172
const std::vector<argidx_and_tokennamet> &args_and_tokens,
1146
- const irep_idt bool_state_name ,
1173
+ const constant_exprt &bool_value ,
1147
1174
const symbol_tablet &symbol_table,
1148
- const std::map<taint_tokent::namet, automaton_variable_idt> &
1149
- from_tokens_to_vars,
1175
+ const std::map<taint_tokent::namet, automaton_variable_idt>
1176
+ & from_tokens_to_vars,
1150
1177
const code_function_callt &fn_call,
1151
1178
const irep_idt function_id,
1152
1179
goto_programt &instrumentation_code)
@@ -1162,22 +1189,22 @@ void taint_instrumentert::instrument_location(
1162
1189
acc_path,
1163
1190
from_tokens_to_vars.at (arg_token.get_token_name ()),
1164
1191
symbol_table),
1165
- constant_exprt (bool_state_name, typet (ID_bool)) );
1192
+ bool_value );
1166
1193
iit->function =function_id;
1167
1194
}
1168
1195
}
1169
1196
};
1170
1197
localt::make_assignments_to_shadow_variables (
1171
1198
loc.get_turn_on (),
1172
- ID_true ,
1199
+ get_shadow_variable_value_true () ,
1173
1200
get_instrumented_symbol_table (),
1174
1201
get_from_tokens_to_vars (),
1175
1202
fn_call,
1176
1203
loc.get_function_id (),
1177
1204
instrumentation_code);
1178
1205
localt::make_assignments_to_shadow_variables (
1179
1206
loc.get_turn_off (),
1180
- ID_false ,
1207
+ get_shadow_variable_value_false () ,
1181
1208
get_instrumented_symbol_table (),
1182
1209
get_from_tokens_to_vars (),
1183
1210
fn_call,
@@ -1216,15 +1243,20 @@ void taint_instrumentert::instrument_location_data_flow_insensitive(
1216
1243
// Here we build GOTO instruction guarded by a negated conjunction of
1217
1244
// state variables, forming propositions of the assumption.
1218
1245
exprt cond=
1219
- symbol_exprt (
1220
- from_tokens_to_vars.at (loc.get_assumption ().front ().get_token_name ()),
1221
- typet (ID_bool));
1246
+ equal_exprt (
1247
+ symbol_exprt (
1248
+ from_tokens_to_vars.at (loc.get_assumption ().front ().get_token_name ()),
1249
+ get_shadow_variable_type ()),
1250
+ get_shadow_variable_value_true ());
1222
1251
for (auto it=std::next (loc.get_assumption ().cbegin ());
1223
1252
it!=loc.get_assumption ().cend ();
1224
1253
++it)
1225
- cond=and_exprt (cond,
1226
- symbol_exprt (from_tokens_to_vars.at (it->get_token_name ()),
1227
- typet (ID_bool)));
1254
+ cond = and_exprt (
1255
+ cond,
1256
+ equal_exprt (
1257
+ symbol_exprt (from_tokens_to_vars.at (it->get_token_name ()),
1258
+ get_shadow_variable_type ()),
1259
+ get_shadow_variable_value_true ()));
1228
1260
auto iit=instrumentation_code.add_instruction ();
1229
1261
iit->make_goto (instrumention_tail_instruction, not_exprt (cond));
1230
1262
iit->function =loc.get_function_id ();
@@ -1233,22 +1265,22 @@ void taint_instrumentert::instrument_location_data_flow_insensitive(
1233
1265
for (const auto &arg_token : loc.get_turn_on ())
1234
1266
{
1235
1267
auto iit=instrumentation_code.add_instruction (ASSIGN);
1236
- iit->code = code_assignt (
1268
+ iit->code = code_assignt (
1237
1269
symbol_exprt (
1238
1270
from_tokens_to_vars.at (arg_token.get_token_name ()),
1239
- typet (ID_bool )),
1240
- constant_exprt (ID_true, typet (ID_bool) ));
1271
+ get_shadow_variable_type ( )),
1272
+ get_shadow_variable_value_true ( ));
1241
1273
iit->function =loc.get_function_id ();
1242
1274
}
1243
1275
// Now we instrument "turn off" assignments of state variables.
1244
1276
for (const auto &arg_token : loc.get_turn_off ())
1245
1277
{
1246
1278
auto iit=instrumentation_code.add_instruction (ASSIGN);
1247
- iit->code = code_assignt (
1279
+ iit->code = code_assignt (
1248
1280
symbol_exprt (
1249
1281
from_tokens_to_vars.at (arg_token.get_token_name ()),
1250
- typet (ID_bool )),
1251
- constant_exprt (ID_false, typet (ID_bool) ));
1282
+ get_shadow_variable_type ( )),
1283
+ get_shadow_variable_value_false ( ));
1252
1284
iit->function =loc.get_function_id ();
1253
1285
}
1254
1286
if (props.get_sinks ().count (lid))
0 commit comments