@@ -211,7 +211,63 @@ std::list<loop_idt> cegis_verifiert::get_cause_loop_id(
211
211
return result;
212
212
}
213
213
214
- bool cegis_verifiert::is_instruction_in_transfomed_loop (
214
+ cext::violation_locationt cegis_verifiert::get_violation_location (
215
+ const loop_idt &loop_id,
216
+ const goto_functiont &function,
217
+ unsigned location_number_of_target)
218
+ {
219
+ if (is_instruction_in_transformed_loop_condition (
220
+ loop_id, function, location_number_of_target))
221
+ {
222
+ return cext::violation_locationt::in_condition;
223
+ }
224
+
225
+ if (is_instruction_in_transformed_loop (
226
+ loop_id, function, location_number_of_target))
227
+ {
228
+ return cext::violation_locationt::in_loop;
229
+ }
230
+
231
+ return cext::violation_locationt::after_loop;
232
+ }
233
+
234
+ bool cegis_verifiert::is_instruction_in_transformed_loop_condition (
235
+ const loop_idt &loop_id,
236
+ const goto_functiont &function,
237
+ unsigned location_number_of_target)
238
+ {
239
+ // The transformed loop condition is a set of instructions from
240
+ // loop havocing instructions
241
+ // to
242
+ // if(!guard) GOTO EXIT
243
+ unsigned location_number_of_havocing = 0 ;
244
+ for (auto it = function.body .instructions .begin ();
245
+ it != function.body .instructions .end ();
246
+ ++it)
247
+ {
248
+ // Record the location number of the beginning of a transformed loop.
249
+ if (
250
+ loop_havoc_set.count (it) &&
251
+ original_loop_number_map[it] == loop_id.loop_number )
252
+ {
253
+ location_number_of_havocing = it->location_number ;
254
+ }
255
+
256
+ // Reach the end of the evaluation of the transformed loop condition.
257
+ if (location_number_of_havocing != 0 && it->is_goto ())
258
+ {
259
+ if ((location_number_of_havocing < location_number_of_target &&
260
+ location_number_of_target < it->location_number ))
261
+ {
262
+ return true ;
263
+ }
264
+ location_number_of_havocing = 0 ;
265
+ }
266
+ }
267
+ return false ;
268
+ }
269
+
270
+ bool cegis_verifiert::is_instruction_in_transformed_loop (
215
271
const loop_idt &loop_id,
216
272
const goto_functiont &function,
217
273
unsigned location_number_of_target)
@@ -458,9 +514,9 @@ optionalt<cext> cegis_verifiert::verify()
458
514
//
459
515
// 1. annotate and apply the loop contracts stored in `invariant_candidates`.
460
516
//
461
- // 2. run the CBMC API to verify the intrumented goto model. As the API is not
462
- // merged yet, we preprocess the goto model and run the symex checker on it
463
- // to simulate CBMC API.
517
+ // 2. run the CBMC API to verify the instrumented goto model. As the API is
518
+ // not merged yet, we preprocess the goto model and run the symex checker
519
+ // on it to simulate CBMC API.
464
520
// TODO: ^^^ replace the symex checker once the real API is merged.
465
521
//
466
522
// 3. construct the formatted counterexample from the violated property and
@@ -530,7 +586,7 @@ optionalt<cext> cegis_verifiert::verify()
530
586
}
531
587
532
588
properties = checker->get_properties ();
533
- // Find the violation and construct conterexample from its trace.
589
+ // Find the violation and construct counterexample from its trace.
534
590
for (const auto &property_it : properties)
535
591
{
536
592
if (property_it.second .status != property_statust::FAIL)
@@ -622,21 +678,22 @@ optionalt<cext> cegis_verifiert::verify()
622
678
return cext (violation_type);
623
679
}
624
680
625
- // Decide whether the violation is in the cause loop.
626
- bool is_violation_in_loop = is_instruction_in_transfomed_loop (
627
- cause_loop_ids.front (),
628
- goto_model.get_goto_function (cause_loop_ids.front ().function_id ),
629
- property_it.second .pc ->location_number );
630
-
631
681
log .debug () << " Found cause loop with function id: "
632
682
<< cause_loop_ids.front ().function_id
633
683
<< " , and loop number: " << cause_loop_ids.front ().loop_number
634
684
<< messaget::eom;
635
685
686
+ auto violation_location = cext::violation_locationt::in_loop;
636
687
// We always strengthen in_clause if the violation is
637
688
// invariant-not-preserved.
638
- if (violation_type == cext::violation_typet::cex_not_preserved)
639
- is_violation_in_loop = true ;
689
+ if (violation_type != cext::violation_typet::cex_not_preserved)
690
+ {
691
+ // Get the location of the violation
692
+ violation_location = get_violation_location (
693
+ cause_loop_ids.front (),
694
+ goto_model.get_goto_function (cause_loop_ids.front ().function_id ),
695
+ property_it.second .pc ->location_number );
696
+ }
640
697
641
698
restore_functions ();
642
699
@@ -649,7 +706,7 @@ optionalt<cext> cegis_verifiert::verify()
649
706
->source_location ());
650
707
return_cex.violated_predicate = property_it.second .pc ->condition ();
651
708
return_cex.cause_loop_ids = cause_loop_ids;
652
- return_cex.is_violation_in_loop = is_violation_in_loop ;
709
+ return_cex.violation_location = violation_location ;
653
710
return_cex.violation_type = violation_type;
654
711
655
712
// The pointer checked in the null-pointer-check violation.
0 commit comments