@@ -606,42 +606,6 @@ void taint_instrumentert::instrument_instructions_with_shadow_variables(
606
606
}
607
607
}
608
608
609
- static irept add_shadow_variables_to_type (
610
- const irept &type,
611
- const std::vector<taint_instrumentert::automaton_variable_idt> &vars,
612
- const taint_datatype_infot &info)
613
- {
614
- if (type.id ()==ID_struct)
615
- {
616
- const struct_typet &struct_type=
617
- to_struct_type (static_cast <const typet &>(type));
618
- const auto tag=" java::" +as_string (struct_type.get_tag ());
619
- if (tag==info.get_id ())
620
- {
621
- if (info.subclass_required ())
622
- {
623
- // Nothing to do here, because we handle subclassed data types
624
- // differently. See calls to 'substitute_subclassed_types' from
625
- // 'taint_instrumentert::instrument_data_types' for details.
626
- }
627
- else
628
- {
629
- struct_typet result=struct_type;
630
- struct_typet::componentst &components=result.components ();
631
- for (const taint_instrumentert::automaton_variable_idt &var : vars)
632
- {
633
- components.push_back (struct_typet::componentt{
634
- var, bool_typet () });
635
- components.back ().set_pretty_name (var);
636
- components.back ().set_access (ID_public);
637
- }
638
- return result;
639
- }
640
- }
641
- }
642
- return type;
643
- }
644
-
645
609
taint_instrumentert::taint_instrumentert (
646
610
const taint_instrumentation_propst &in_props,
647
611
const taint_programt *const in_program,
@@ -870,13 +834,37 @@ void taint_instrumentert::instrument_data_types(
870
834
}
871
835
else
872
836
{
873
- symbolt &symbol=*instrumented_symbol_table.get_writeable (id_info.first );
874
- const irept itype=instrument (symbol.type , std::bind (
875
- &add_shadow_variables_to_type,
876
- std::placeholders::_1,
877
- std::cref (vars),
878
- std::cref (id_info.second )));
879
- symbol.type =static_cast <const typet&>(itype);
837
+ namespacet ns (instrumented_symbol_table);
838
+ const symbolt *symbol_ptr = &ns.lookup (id_info.first );
839
+ while (true )
840
+ {
841
+ INVARIANT (
842
+ symbol_ptr->type .id () == ID_struct,
843
+ " In this branch the instrumented type must always be a struct type." );
844
+ const struct_typet &struct_type = to_struct_type (symbol_ptr->type );
845
+ const struct_typet::componentst &components = struct_type.components ();
846
+ INVARIANT (
847
+ !components.empty (),
848
+ " The class has either a parent or class identifier." );
849
+ auto type = namespacet (instrumented_symbol_table)
850
+ .follow (components.front ().type ());
851
+ if (type.id () != ID_struct)
852
+ break ;
853
+ symbol_ptr =
854
+ &ns.lookup (" java::" + as_string (to_struct_type (type).get_tag ()));
855
+ }
856
+ struct_typet &struct_type = to_struct_type (
857
+ instrumented_symbol_table.get_writeable (symbol_ptr->name )->type );
858
+ struct_typet::componentst &components = struct_type.components ();
859
+ for (const taint_instrumentert::automaton_variable_idt &var : vars)
860
+ {
861
+ if (!struct_type.has_component (var))
862
+ {
863
+ components.push_back (struct_typet::componentt{var, bool_typet ()});
864
+ components.back ().set_pretty_name (var);
865
+ components.back ().set_access (ID_public);
866
+ }
867
+ }
880
868
}
881
869
}
882
870
@@ -927,18 +915,45 @@ static exprt get_accessor_expression_to_shadow_variable_from_call_expression(
927
915
}
928
916
929
917
static exprt make_accessor_expression_to_shadow_variable (
930
- const exprt &argument, const std::string &shadow_variable_name)
918
+ const exprt &argument,
919
+ const std::string &shadow_variable_name,
920
+ const symbol_tablet &symbol_table)
931
921
{
932
- if (argument.type ().id ()==ID_pointer)
922
+ namespacet ns (symbol_table);
923
+ const typet &arg_type = ns.follow (argument.type ());
924
+ if (arg_type.id () == ID_pointer)
933
925
{
934
- const pointer_typet pt= to_pointer_type (argument. type () );
935
- return member_exprt (
926
+ const pointer_typet pt = to_pointer_type (arg_type );
927
+ return make_accessor_expression_to_shadow_variable (
936
928
dereference_exprt (argument, pt.subtype ()),
937
929
shadow_variable_name,
938
- bool_typet () );
930
+ symbol_table );
939
931
}
940
- else
941
- return member_exprt (argument, shadow_variable_name, bool_typet ());
932
+ INVARIANT (
933
+ arg_type.id () == ID_struct,
934
+ " The remaining possible case is that the arg_type is of a class type." );
935
+ exprt access_path = argument;
936
+ typet type = arg_type;
937
+ while (true )
938
+ {
939
+ const struct_typet &struct_type = to_struct_type (type);
940
+ if (struct_type.has_component (shadow_variable_name))
941
+ {
942
+ access_path =
943
+ member_exprt (access_path, shadow_variable_name, bool_typet ());
944
+ break ;
945
+ }
946
+ const struct_typet::componentst &components = struct_type.components ();
947
+ INVARIANT (
948
+ !components.empty (), " The class has either the shadow var of a parent." );
949
+ access_path = member_exprt (
950
+ access_path, components.front ().get_name (), components.front ().type ());
951
+ type = ns.follow (components.front ().type ());
952
+ INVARIANT (
953
+ type.id () == ID_struct,
954
+ " The base class instance is stored by value and must be available." );
955
+ }
956
+ return access_path;
942
957
}
943
958
944
959
void taint_instrumentert::instrument_location (
@@ -989,9 +1004,10 @@ void taint_instrumentert::instrument_location(
989
1004
fn_call,
990
1005
assumption.get_argidx (),
991
1006
instrumented_symbol_table);
992
- const exprt proposition= make_accessor_expression_to_shadow_variable (
1007
+ const exprt proposition = make_accessor_expression_to_shadow_variable (
993
1008
acc_path,
994
- from_tokens_to_vars.at (assumption.get_token_name ()));
1009
+ from_tokens_to_vars.at (assumption.get_token_name ()),
1010
+ instrumented_symbol_table);
995
1011
conjuncts.push_back (proposition);
996
1012
}
997
1013
auto iit=instrumentation_code.add_instruction ();
@@ -1019,10 +1035,11 @@ void taint_instrumentert::instrument_location(
1019
1035
get_accessor_expression_to_shadow_variable_from_call_expression (
1020
1036
fn_call, arg_token.get_argidx (), symbol_table);
1021
1037
auto iit=instrumentation_code.add_instruction (ASSIGN);
1022
- iit->code = code_assignt (
1038
+ iit->code = code_assignt (
1023
1039
make_accessor_expression_to_shadow_variable (
1024
1040
acc_path,
1025
- from_tokens_to_vars.at (arg_token.get_token_name ())),
1041
+ from_tokens_to_vars.at (arg_token.get_token_name ()),
1042
+ symbol_table),
1026
1043
constant_exprt (bool_state_name, typet (ID_bool)));
1027
1044
iit->function =function_id;
1028
1045
}
0 commit comments