Skip to content

Commit 781bf7c

Browse files
author
thk123
committed
Introduce exceptions for all conversion steps.
1 parent 21997b2 commit 781bf7c

File tree

2 files changed

+66
-20
lines changed

2 files changed

+66
-20
lines changed

src/goto-symex/equation_conversion_exceptions.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,21 @@ Author: Diffblue Ltd.
1313
#define CPROVER_GOTO_SYMEX_EQUATION_CONVERSION_EXCEPTIONS_H
1414

1515
#include <ostream>
16+
1617
#include <util/namespace.h>
18+
1719
#include <langapi/language_util.h>
20+
1821
#include "symex_target_equation.h"
1922

20-
class guard_conversion_exceptiont : public std::runtime_error
23+
class equation_conversion_exceptiont : public std::runtime_error
2124
{
2225
public:
23-
guard_conversion_exceptiont(
26+
equation_conversion_exceptiont(
27+
const std::string &message,
2428
const symex_target_equationt::SSA_stept &step,
2529
const namespacet &ns)
26-
: runtime_error("Error converting guard for step"), step(step)
30+
: runtime_error(message), step(step)
2731
{
2832
std::ostringstream error_msg;
2933
error_msg << runtime_error::what();
@@ -34,9 +38,10 @@ class guard_conversion_exceptiont : public std::runtime_error
3438
error_message = error_msg.str();
3539
}
3640

37-
explicit guard_conversion_exceptiont(
41+
explicit equation_conversion_exceptiont(
42+
const std::string &message,
3843
const symex_target_equationt::SSA_stept &step)
39-
: guard_conversion_exceptiont(step, namespacet{symbol_tablet{}})
44+
: equation_conversion_exceptiont(message, step, namespacet{symbol_tablet{}})
4045
{
4146
}
4247

src/goto-symex/symex_target_equation.cpp

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -375,21 +375,20 @@ void symex_target_equationt::convert(
375375
try
376376
{
377377
convert_guards(prop_conv);
378+
convert_assignments(prop_conv);
379+
convert_decls(prop_conv);
380+
convert_assumptions(prop_conv);
381+
convert_assertions(prop_conv);
382+
convert_goto_instructions(prop_conv);
383+
convert_io(prop_conv);
384+
convert_constraints(prop_conv);
378385
}
379-
catch(guard_conversion_exceptiont &guard_conversion_exception)
386+
catch(const equation_conversion_exceptiont &conversion_exception)
380387
{
381388
// unwrap the except and throw like normal
382-
const std::string full_error = unwrap_exception(guard_conversion_exception);
389+
const std::string full_error = unwrap_exception(conversion_exception);
383390
throw full_error;
384391
}
385-
386-
convert_assignments(prop_conv);
387-
convert_decls(prop_conv);
388-
convert_assumptions(prop_conv);
389-
convert_assertions(prop_conv);
390-
convert_goto_instructions(prop_conv);
391-
convert_io(prop_conv);
392-
convert_constraints(prop_conv);
393392
}
394393

395394
/// converts assignments
@@ -416,7 +415,16 @@ void symex_target_equationt::convert_decls(
416415
{
417416
// The result is not used, these have no impact on
418417
// the satisfiability of the formula.
419-
prop_conv.convert(step.cond_expr);
418+
try
419+
{
420+
prop_conv.convert(step.cond_expr);
421+
}
422+
catch(const bitvector_conversion_exceptiont &conversion_exception)
423+
{
424+
util_throw_with_nested(
425+
equation_conversion_exceptiont(
426+
"Error converting decls for step", step, ns));
427+
}
420428
}
421429
}
422430
}
@@ -438,7 +446,9 @@ void symex_target_equationt::convert_guards(
438446
}
439447
catch(const bitvector_conversion_exceptiont &conversion_exception)
440448
{
441-
util_throw_with_nested(guard_conversion_exceptiont(step, ns));
449+
util_throw_with_nested(
450+
equation_conversion_exceptiont(
451+
"Error converting guard for step", step, ns));
442452
}
443453
}
444454
}
@@ -456,7 +466,18 @@ void symex_target_equationt::convert_assumptions(
456466
if(step.ignore)
457467
step.cond_literal=const_literal(true);
458468
else
459-
step.cond_literal=prop_conv.convert(step.cond_expr);
469+
{
470+
try
471+
{
472+
step.cond_literal = prop_conv.convert(step.cond_expr);
473+
}
474+
catch(const bitvector_conversion_exceptiont &conversion_exception)
475+
{
476+
util_throw_with_nested(
477+
equation_conversion_exceptiont(
478+
"Error converting assumptions for step", step, ns));
479+
}
480+
}
460481
}
461482
}
462483
}
@@ -473,7 +494,18 @@ void symex_target_equationt::convert_goto_instructions(
473494
if(step.ignore)
474495
step.cond_literal=const_literal(true);
475496
else
476-
step.cond_literal=prop_conv.convert(step.cond_expr);
497+
{
498+
try
499+
{
500+
step.cond_literal = prop_conv.convert(step.cond_expr);
501+
}
502+
catch(const bitvector_conversion_exceptiont &conversion_exception)
503+
{
504+
util_throw_with_nested(
505+
equation_conversion_exceptiont(
506+
"Error converting goto instructions for step", step, ns));
507+
}
508+
}
477509
}
478510
}
479511
}
@@ -542,7 +574,16 @@ void symex_target_equationt::convert_assertions(
542574
step.cond_expr);
543575

544576
// do the conversion
545-
step.cond_literal=prop_conv.convert(implication);
577+
try
578+
{
579+
step.cond_literal = prop_conv.convert(implication);
580+
}
581+
catch(const bitvector_conversion_exceptiont &conversion_exception)
582+
{
583+
util_throw_with_nested(
584+
equation_conversion_exceptiont(
585+
"Error converting assertions for step", step, ns));
586+
}
546587

547588
// store disjunct
548589
disjuncts.push_back(literal_exprt(!step.cond_literal));

0 commit comments

Comments
 (0)