Skip to content

Commit 8cd4490

Browse files
author
Daniel Kroening
authored
Merge pull request diffblue#1373 from diffblue/symex-trace-fix
Symex trace fix
2 parents 728ac5b + 5d2d07b commit 8cd4490

File tree

6 files changed

+46
-37
lines changed

6 files changed

+46
-37
lines changed

regression/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ DIRS = ansi-c \
1212
invariants \
1313
strings \
1414
strings-smoke-tests \
15+
symex \
1516
test-script \
1617
# Empty last line
1718

regression/symex/show-trace1/main.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ int main()
44
{
55
int i, j, k;
66

7-
i=input();
8-
j=input();
9-
k=input();
7+
i=input(); // expect 2
8+
j=input(); // expect 3
9+
k=input(); // expect 6
1010

1111
if(i==2)
1212
if(j==i+1)
1313
if(k==i*j)
14-
assert(0);
14+
__CPROVER_assert(0, "");
1515
}

regression/symex/show-trace1/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
--show-trace
3+
--trace
44
^EXIT=10$
55
^SIGNAL=0$
66
^VERIFICATION FAILED$

src/path-symex/path_symex.cpp

+27-22
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void path_symext::assign(
129129

130130
// start recursion on lhs
131131
exprt::operandst _guard; // start with empty guard
132-
assign_rec(state, _guard, ssa_lhs, ssa_rhs);
132+
assign_rec(state, _guard, lhs, ssa_lhs, ssa_rhs);
133133
}
134134

135135
inline static typet c_sizeof_type_rec(const exprt &expr)
@@ -347,6 +347,7 @@ void path_symext::symex_va_arg_next(
347347
void path_symext::assign_rec(
348348
path_symex_statet &state,
349349
exprt::operandst &guard,
350+
const exprt &full_lhs,
350351
const exprt &ssa_lhs,
351352
const exprt &ssa_rhs)
352353
{
@@ -376,17 +377,17 @@ void path_symext::assign_rec(
376377

377378
// increase the SSA counter and produce new SSA symbol expression
378379
var_info.increment_ssa_counter();
379-
symbol_exprt new_lhs=var_info.ssa_symbol();
380+
symbol_exprt new_ssa_lhs=var_info.ssa_symbol();
380381

381382
#ifdef DEBUG
382-
std::cout << "new_lhs: " << new_lhs.get_identifier() << '\n';
383+
std::cout << "new_ssa_lhs: " << new_ssa_lhs.get_identifier() << '\n';
383384
#endif
384385

385386
// record new state of lhs
386387
{
387388
// reference is not stable
388389
path_symex_statet::var_statet &var_state=state.get_var_state(var_info);
389-
var_state.ssa_symbol=new_lhs;
390+
var_state.ssa_symbol=new_ssa_lhs;
390391
}
391392

392393
// rhs nil means non-det assignment
@@ -398,11 +399,11 @@ void path_symext::assign_rec(
398399
else
399400
{
400401
// consistency check
401-
if(!base_type_eq(ssa_rhs.type(), new_lhs.type(), state.var_map.ns))
402+
if(!base_type_eq(ssa_rhs.type(), new_ssa_lhs.type(), state.var_map.ns))
402403
{
403404
#ifdef DEBUG
404405
std::cout << "ssa_rhs: " << ssa_rhs.pretty() << '\n';
405-
std::cout << "new_lhs: " << new_lhs.pretty() << '\n';
406+
std::cout << "new_ssa_lhs: " << new_ssa_lhs.pretty() << '\n';
406407
#endif
407408
throw "assign_rec got different types";
408409
}
@@ -413,8 +414,8 @@ void path_symext::assign_rec(
413414

414415
if(!guard.empty())
415416
step.guard=conjunction(guard);
416-
step.full_lhs=ssa_lhs;
417-
step.ssa_lhs=new_lhs;
417+
step.full_lhs=full_lhs;
418+
step.ssa_lhs=new_ssa_lhs;
418419
step.ssa_rhs=ssa_rhs;
419420

420421
// propagate the rhs?
@@ -425,10 +426,10 @@ void path_symext::assign_rec(
425426
else if(ssa_lhs.id()==ID_typecast)
426427
{
427428
// dereferencing might yield a typecast
428-
const exprt &new_lhs=to_typecast_expr(ssa_lhs).op();
429-
typecast_exprt new_rhs(ssa_rhs, new_lhs.type());
429+
const exprt &new_ssa_lhs=to_typecast_expr(ssa_lhs).op();
430+
typecast_exprt new_rhs(ssa_rhs, new_ssa_lhs.type());
430431

431-
assign_rec(state, guard, new_lhs, new_rhs);
432+
assign_rec(state, guard, full_lhs, new_ssa_lhs, new_rhs);
432433
}
433434
else if(ssa_lhs.id()==ID_member)
434435
{
@@ -454,17 +455,17 @@ void path_symext::assign_rec(
454455

455456
with_exprt new_rhs(struct_op, member_name, ssa_rhs);
456457

457-
assign_rec(state, guard, struct_op, new_rhs);
458+
assign_rec(state, guard, full_lhs, struct_op, new_rhs);
458459
}
459460
else if(compound_type.id()==ID_union)
460461
{
461462
// rewrite into byte_extract, and do again
462463
exprt offset=from_integer(0, index_type());
463464

464465
byte_extract_exprt
465-
new_lhs(byte_update_id(), struct_op, offset, ssa_rhs.type());
466+
new_ssa_lhs(byte_update_id(), struct_op, offset, ssa_rhs.type());
466467

467-
assign_rec(state, guard, new_lhs, ssa_rhs);
468+
assign_rec(state, guard, full_lhs, new_ssa_lhs, ssa_rhs);
468469
}
469470
else
470471
throw "assign_rec: member expects struct or union type";
@@ -496,12 +497,12 @@ void path_symext::assign_rec(
496497

497498
// true
498499
guard.push_back(cond);
499-
assign_rec(state, guard, lhs_if_expr.true_case(), ssa_rhs);
500+
assign_rec(state, guard, full_lhs, lhs_if_expr.true_case(), ssa_rhs);
500501
guard.pop_back();
501502

502503
// false
503504
guard.push_back(not_exprt(cond));
504-
assign_rec(state, guard, lhs_if_expr.false_case(), ssa_rhs);
505+
assign_rec(state, guard, full_lhs, lhs_if_expr.false_case(), ssa_rhs);
505506
guard.pop_back();
506507
}
507508
else if(ssa_lhs.id()==ID_byte_extract_little_endian ||
@@ -533,9 +534,9 @@ void path_symext::assign_rec(
533534
new_rhs.offset()=byte_extract_expr.offset();
534535
new_rhs.value()=ssa_rhs;
535536

536-
const exprt new_lhs=byte_extract_expr.op();
537+
const exprt new_ssa_lhs=byte_extract_expr.op();
537538

538-
assign_rec(state, guard, new_lhs, new_rhs);
539+
assign_rec(state, guard, full_lhs, new_ssa_lhs, new_rhs);
539540
}
540541
else if(ssa_lhs.id()==ID_struct)
541542
{
@@ -555,7 +556,7 @@ void path_symext::assign_rec(
555556
exprt::operandst::const_iterator lhs_it=operands.begin();
556557
forall_operands(it, ssa_rhs)
557558
{
558-
assign_rec(state, guard, *lhs_it, *it);
559+
assign_rec(state, guard, full_lhs, *lhs_it, *it);
559560
++lhs_it;
560561
}
561562
}
@@ -571,7 +572,7 @@ void path_symext::assign_rec(
571572
components[i].get_name(),
572573
components[i].type()),
573574
state.var_map.ns);
574-
assign_rec(state, guard, operands[i], new_rhs);
575+
assign_rec(state, guard, full_lhs, operands[i], new_rhs);
575576
}
576577
}
577578
}
@@ -594,7 +595,7 @@ void path_symext::assign_rec(
594595
exprt::operandst::const_iterator lhs_it=operands.begin();
595596
forall_operands(it, ssa_rhs)
596597
{
597-
assign_rec(state, guard, *lhs_it, *it);
598+
assign_rec(state, guard, full_lhs, *lhs_it, *it);
598599
++lhs_it;
599600
}
600601
}
@@ -610,7 +611,7 @@ void path_symext::assign_rec(
610611
from_integer(i, index_type()),
611612
array_type.subtype()),
612613
state.var_map.ns);
613-
assign_rec(state, guard, operands[i], new_rhs);
614+
assign_rec(state, guard, full_lhs, operands[i], new_rhs);
614615
}
615616
}
616617
}
@@ -1090,6 +1091,10 @@ void path_symext::operator()(
10901091
{
10911092
// just needs to be recorded
10921093
}
1094+
else if(statement==ID_output)
1095+
{
1096+
// just needs to be recorded
1097+
}
10931098
else
10941099
throw "unexpected OTHER statement: "+id2string(statement);
10951100
}

src/path-symex/path_symex_class.h

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class path_symext
9393
void assign_rec(
9494
path_symex_statet &state,
9595
exprt::operandst &guard, // instantiated
96+
const exprt &full_lhs, // not instantiated, no recursion
9697
const exprt &ssa_lhs, // instantiated, recursion here
9798
const exprt &ssa_rhs); // instantiated
9899

src/symex/symex_parse_options.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,24 @@ Author: Daniel Kroening, [email protected]
2626
#include <cpp/cpp_language.h>
2727
#include <java_bytecode/java_bytecode_language.h>
2828

29-
#include <goto-programs/initialize_goto_model.h>
3029
#include <goto-programs/goto_convert_functions.h>
31-
#include <goto-programs/show_properties.h>
32-
#include <goto-programs/set_properties.h>
33-
#include <goto-programs/read_goto_binary.h>
34-
#include <goto-programs/loop_ids.h>
35-
#include <goto-programs/link_to_library.h>
3630
#include <goto-programs/goto_inline.h>
37-
#include <goto-programs/xml_goto_trace.h>
31+
#include <goto-programs/initialize_goto_model.h>
32+
#include <goto-programs/link_to_library.h>
33+
#include <goto-programs/loop_ids.h>
34+
#include <goto-programs/read_goto_binary.h>
3835
#include <goto-programs/remove_complex.h>
36+
#include <goto-programs/remove_exceptions.h>
3937
#include <goto-programs/remove_function_pointers.h>
38+
#include <goto-programs/remove_instanceof.h>
39+
#include <goto-programs/remove_returns.h>
4040
#include <goto-programs/remove_skip.h>
41+
#include <goto-programs/remove_unused_functions.h>
4142
#include <goto-programs/remove_vector.h>
4243
#include <goto-programs/remove_virtual_functions.h>
43-
#include <goto-programs/remove_exceptions.h>
44-
#include <goto-programs/remove_instanceof.h>
45-
#include <goto-programs/remove_unused_functions.h>
44+
#include <goto-programs/set_properties.h>
45+
#include <goto-programs/show_properties.h>
46+
#include <goto-programs/xml_goto_trace.h>
4647

4748
#include <goto-symex/rewrite_union.h>
4849
#include <goto-symex/adjust_float_expressions.h>
@@ -304,6 +305,7 @@ bool symex_parse_optionst::process_goto_program(const optionst &options)
304305
goto_check(options, goto_model);
305306

306307
// remove stuff
308+
remove_returns(goto_model);
307309
remove_complex(goto_model);
308310
remove_vector(goto_model);
309311
// remove function pointers

0 commit comments

Comments
 (0)