Skip to content

Commit 932d7df

Browse files
Merge pull request #709 from lucasccordeiro/fixing-issue-20
set internal field in specific variables in the counterexample trace for test-gen-support
2 parents 2499213 + 5081310 commit 932d7df

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

src/goto-programs/goto_trace.h

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class goto_trace_stept
6363
// we may choose to hide a step
6464
bool hidden;
6565

66+
// this is related to an internal expression
67+
bool internal;
68+
6669
// we categorize
6770
typedef enum { STATE, ACTUAL_PARAMETER } assignment_typet;
6871
assignment_typet assignment_type;
@@ -107,6 +110,7 @@ class goto_trace_stept
107110
step_nr(0),
108111
type(NONE),
109112
hidden(false),
113+
internal(false),
110114
assignment_type(STATE),
111115
thread_nr(0),
112116
cond_value(false),

src/goto-programs/json_goto_trace.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void convert(
6868

6969
json_failure["stepType"]=json_stringt("failure");
7070
json_failure["hidden"]=jsont::json_boolean(step.hidden);
71+
json_failure["internal"]=jsont::json_boolean(step.internal);
7172
json_failure["thread"]=json_numbert(std::to_string(step.thread_nr));
7273
json_failure["reason"]=json_stringt(id2string(step.comment));
7374
json_failure["property"]=json_stringt(id2string(property_id));
@@ -118,6 +119,7 @@ void convert(
118119
json_assignment["value"]=full_lhs_value;
119120
json_assignment["lhs"]=json_stringt(full_lhs_string);
120121
json_assignment["hidden"]=jsont::json_boolean(step.hidden);
122+
json_assignment["internal"]=jsont::json_boolean(step.internal);
121123
json_assignment["thread"]=json_numbert(std::to_string(step.thread_nr));
122124

123125
json_assignment["assignmentType"]=
@@ -132,6 +134,7 @@ void convert(
132134

133135
json_output["stepType"]=json_stringt("output");
134136
json_output["hidden"]=jsont::json_boolean(step.hidden);
137+
json_output["internal"]=jsont::json_boolean(step.internal);
135138
json_output["thread"]=json_numbert(std::to_string(step.thread_nr));
136139
json_output["outputID"]=json_stringt(id2string(step.io_id));
137140

@@ -156,6 +159,7 @@ void convert(
156159

157160
json_input["stepType"]=json_stringt("input");
158161
json_input["hidden"]=jsont::json_boolean(step.hidden);
162+
json_input["internal"]=jsont::json_boolean(step.internal);
159163
json_input["thread"]=json_numbert(std::to_string(step.thread_nr));
160164
json_input["inputID"]=json_stringt(id2string(step.io_id));
161165

@@ -184,6 +188,7 @@ void convert(
184188

185189
json_call_return["stepType"]=json_stringt(tag);
186190
json_call_return["hidden"]=jsont::json_boolean(step.hidden);
191+
json_call_return["internal"]=jsont::json_boolean(step.internal);
187192
json_call_return["thread"]=json_numbert(std::to_string(step.thread_nr));
188193

189194
const symbolt &symbol=ns.lookup(step.identifier);
@@ -207,6 +212,7 @@ void convert(
207212
json_objectt &json_location_only=dest_array.push_back().make_object();
208213
json_location_only["stepType"]=json_stringt("location-only");
209214
json_location_only["hidden"]=jsont::json_boolean(step.hidden);
215+
json_location_only["internal"]=jsont::json_boolean(step.internal);
210216
json_location_only["thread"]=
211217
json_numbert(std::to_string(step.thread_nr));
212218
json_location_only["sourceLocation"]=json_location;

src/goto-symex/build_goto_trace.cpp

+83
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,86 @@ exprt adjust_lhs_object(
132132

133133
/*******************************************************************\
134134
135+
Function: set_internal_dynamic_object
136+
137+
Inputs:
138+
139+
Outputs:
140+
141+
Purpose: set internal field for variable assignment related to
142+
dynamic_object[0-9] and dynamic_[0-9]_array.
143+
144+
\*******************************************************************/
145+
146+
void set_internal_dynamic_object(
147+
const exprt &expr,
148+
goto_trace_stept &goto_trace_step,
149+
const namespacet &ns)
150+
{
151+
if(expr.id()==ID_symbol)
152+
{
153+
const irep_idt &id=to_ssa_expr(expr).get_original_name();
154+
const symbolt *symbol;
155+
if(!ns.lookup(id, symbol))
156+
{
157+
bool result=symbol->type.get_bool("#dynamic");
158+
if(result)
159+
goto_trace_step.internal=true;
160+
}
161+
}
162+
else
163+
{
164+
forall_operands(it, expr)
165+
set_internal_dynamic_object(*it, goto_trace_step, ns);
166+
}
167+
}
168+
169+
/*******************************************************************\
170+
171+
Function: update_internal_field
172+
173+
Inputs:
174+
175+
Outputs:
176+
177+
Purpose: set internal for variables assignments related to
178+
dynamic_object and CPROVER internal functions
179+
(e.g., __CPROVER_initialize)
180+
181+
\*******************************************************************/
182+
183+
void update_internal_field(
184+
const symex_target_equationt::SSA_stept &SSA_step,
185+
goto_trace_stept &goto_trace_step,
186+
const namespacet &ns)
187+
{
188+
// set internal for dynamic_object in both lhs and rhs expressions
189+
set_internal_dynamic_object(SSA_step.ssa_lhs, goto_trace_step, ns);
190+
set_internal_dynamic_object(SSA_step.ssa_rhs, goto_trace_step, ns);
191+
192+
// set internal field to CPROVER functions (e.g., __CPROVER_initialize)
193+
if(SSA_step.is_function_call())
194+
{
195+
if(SSA_step.source.pc->source_location.as_string().empty())
196+
goto_trace_step.internal=true;
197+
}
198+
199+
// set internal field to input and output steps
200+
if(goto_trace_step.type==goto_trace_stept::OUTPUT ||
201+
goto_trace_step.type==goto_trace_stept::INPUT)
202+
{
203+
goto_trace_step.internal=true;
204+
}
205+
206+
// set internal field to _start function-return step
207+
if(SSA_step.source.pc->function==goto_functionst::entry_point())
208+
{
209+
goto_trace_step.internal=true;
210+
}
211+
}
212+
213+
/*******************************************************************\
214+
135215
Function: build_goto_trace
136216
137217
Inputs:
@@ -237,6 +317,9 @@ void build_goto_trace(
237317
goto_trace_step.formatted=SSA_step.formatted;
238318
goto_trace_step.identifier=SSA_step.identifier;
239319

320+
// update internal field for specific variables in the counterexample
321+
update_internal_field(SSA_step, goto_trace_step, ns);
322+
240323
goto_trace_step.assignment_type=
241324
(it->is_assignment()&&
242325
(SSA_step.assignment_type==symex_targett::VISIBLE_ACTUAL_PARAMETER ||

0 commit comments

Comments
 (0)