@@ -260,8 +260,7 @@ void goto_symext::symex_goto(statet &state)
260
260
DATA_INVARIANT (
261
261
instruction.targets .size () == 1 , " no support for non-deterministic gotos" );
262
262
263
- goto_programt::const_targett goto_target=
264
- instruction.get_target ();
263
+ goto_programt::const_targett goto_target = instruction.get_target ();
265
264
266
265
const bool backward = instruction.is_backwards_goto ();
267
266
@@ -614,6 +613,198 @@ void goto_symext::symex_unreachable_goto(statet &state)
614
613
symex_transition (state);
615
614
}
616
615
616
+ void goto_symext::symex_goto_retrace (statet &state)
617
+ {
618
+ // get guard, targets as in symex_goto()
619
+ const goto_programt::instructiont &instruction = *state.source .pc ;
620
+
621
+ exprt new_guard = clean_expr (instruction.condition (), state, false );
622
+
623
+ renamedt<exprt, L2> renamed_guard = state.rename (std::move (new_guard), ns);
624
+ renamed_guard = try_evaluate_pointer_comparisons (
625
+ std::move (renamed_guard), state.value_set , language_mode, ns);
626
+ if (symex_config.simplify_opt )
627
+ renamed_guard.simplify (ns);
628
+ new_guard = renamed_guard.get ();
629
+
630
+ target.goto_instruction (state.guard .as_expr (), renamed_guard, state.source );
631
+
632
+ DATA_INVARIANT (
633
+ !instruction.targets .empty (), " goto should have at least one target" );
634
+
635
+ // we only do deterministic gotos for now
636
+ DATA_INVARIANT (
637
+ instruction.targets .size () == 1 , " no support for non-deterministic gotos" );
638
+
639
+ goto_programt::const_targett goto_target=
640
+ instruction.get_target ();
641
+
642
+ const bool backward = instruction.is_backwards_goto ();
643
+
644
+ goto_programt::const_targett next_instruction = state.source .pc ;
645
+ next_instruction++;
646
+
647
+ // goto or next depends on input trace from user
648
+ bool choose_goto;
649
+ static size_t retrace_index = 0 ;
650
+ if (retrace_index < symex_config.retrace_input .size ())
651
+ {
652
+ choose_goto = symex_config.retrace_input [retrace_index] == ' 1' ;
653
+ }
654
+ else
655
+ {
656
+ choose_goto = false ;
657
+ }
658
+ retrace_index++;
659
+
660
+ // print goto choice
661
+ log.conditional_output (
662
+ log.status (),
663
+ [this , &state, &goto_target, &next_instruction, choose_goto](
664
+ messaget::mstreamt &mstream)
665
+ {
666
+ source_locationt cur = state.source .pc ->source_location ();
667
+ source_locationt goto_dest = goto_target->source_location ();
668
+ source_locationt next_dest = next_instruction->source_location ();
669
+ source_locationt t_dest = choose_goto ? goto_dest : next_dest;
670
+ source_locationt nt_dest = choose_goto ? next_dest : goto_dest;
671
+
672
+ auto cur_file = cur.get_file ();
673
+ if (cur_file.empty ())
674
+ cur_file = " <unknown>" ;
675
+ auto t_file = t_dest.get_file ();
676
+ if (t_file.empty ())
677
+ t_file = " <unknown>" ;
678
+ auto nt_file = nt_dest.get_file ();
679
+ if (nt_file.empty ())
680
+ nt_file = " <unknown>" ;
681
+
682
+ // print nothing when files are the same
683
+ if (cur_file == t_file)
684
+ t_file = " " ;
685
+ if (cur_file == nt_file)
686
+ nt_file = " " ;
687
+
688
+ auto cur_line = cur.get_line ();
689
+ if (cur_line.empty ())
690
+ cur_line = " ?" ;
691
+ auto t_line = t_dest.get_line ();
692
+ if (t_line.empty ())
693
+ t_line = " ?" ;
694
+ auto nt_line = nt_dest.get_line ();
695
+ if (nt_line.empty ())
696
+ nt_line = " ?" ;
697
+
698
+ std::string head = symex_config.retrace_input ;
699
+ // add 0s in case input trace was shorter
700
+ head.resize (retrace_index - 1 , ' 0' );
701
+ std::string decision = choose_goto ? " 1" : " 0" ;
702
+
703
+ std::string step = choose_goto ? " goto " : " next " ;
704
+
705
+ std::string padding_1 =
706
+ cur_line.size () < 3 ? std::string (3 - cur_line.size (), ' ' ) : " " ;
707
+ std::string padding_2 =
708
+ t_line.size () < 3 ? std::string (3 - t_line.size (), ' ' ) : " " ;
709
+
710
+ mstream << " Retrace "
711
+ << head << messaget::bold << decision << messaget::reset
712
+ << " at " << cur_file << " :" << cur_line << padding_1
713
+ << step << t_file << " :" << t_line << padding_2
714
+ << " (not " << nt_file << " :" << nt_line << " )"
715
+ << messaget::eom;
716
+ });
717
+
718
+ // warn when not following unconditional goto
719
+ if (new_guard.is_true () && !choose_goto)
720
+ {
721
+ log.result () << " Retrace input "
722
+ << messaget::red << " inconsistent" << messaget::reset
723
+ << " : 0/next although guard is true!"
724
+ << log.eom ;
725
+ }
726
+ else if (new_guard.is_false () && choose_goto)
727
+ {
728
+ log.result () << " Retrace input "
729
+ << messaget::red << " inconsistent" << messaget::reset
730
+ << " : 1/goto although guard is false!"
731
+ << log.eom ;
732
+ }
733
+
734
+ symex_targett::sourcet original_source = state.source ;
735
+ goto_programt::const_targett new_state_pc;
736
+
737
+ if (choose_goto)
738
+ {
739
+ // Jump to the jump target if the input is '1'
740
+ new_state_pc = goto_target;
741
+ symex_transition (state, new_state_pc, backward);
742
+ }
743
+ else
744
+ {
745
+ // Jump to the next instruction
746
+ new_state_pc = state.source .pc ;
747
+ new_state_pc++;
748
+ symex_transition (state);
749
+ }
750
+
751
+ // produce new guard symbol
752
+ exprt guard_expr;
753
+
754
+ if (
755
+ new_guard.id () == ID_symbol ||
756
+ (new_guard.id () == ID_not && to_not_expr (new_guard).op ().id () == ID_symbol))
757
+ {
758
+ guard_expr = new_guard;
759
+ }
760
+ else
761
+ {
762
+ symbol_exprt guard_symbol_expr =
763
+ symbol_exprt (statet::guard_identifier (), bool_typet ());
764
+ exprt new_rhs = boolean_negate (new_guard);
765
+
766
+ ssa_exprt new_lhs =
767
+ state.rename_ssa <L1>(ssa_exprt{guard_symbol_expr}, ns).get ();
768
+ new_lhs =
769
+ state.assignment (std::move (new_lhs), new_rhs, ns, true , false ).get ();
770
+
771
+ guardt guard{true_exprt{}, guard_manager};
772
+
773
+ log.conditional_output (
774
+ log.debug (),
775
+ [this , &new_lhs](messaget::mstreamt &mstream)
776
+ {
777
+ mstream << " Assignment to " << new_lhs.get_identifier ()
778
+ << " [" << pointer_offset_bits (new_lhs.type (), ns).value_or (0 )
779
+ << " bits]"
780
+ << messaget::eom;
781
+ });
782
+
783
+ target.assignment (
784
+ guard.as_expr (),
785
+ new_lhs,
786
+ new_lhs,
787
+ guard_symbol_expr,
788
+ new_rhs,
789
+ original_source,
790
+ symex_targett::assignment_typet::GUARD);
791
+
792
+ guard_expr = state.rename (boolean_negate (guard_symbol_expr), ns).get ();
793
+ }
794
+
795
+ if (choose_goto)
796
+ {
797
+ symex_assume_l2 (state, guard_expr);
798
+ state.guard .add (guard_expr);
799
+ }
800
+ else
801
+ {
802
+ symex_assume_l2 (state, boolean_negate (guard_expr));
803
+ state.guard .add (boolean_negate (guard_expr));
804
+ }
805
+ return ;
806
+ }
807
+
617
808
bool goto_symext::check_break (const irep_idt &loop_id, unsigned unwind)
618
809
{
619
810
// dummy implementation
0 commit comments