Skip to content

Commit a97bc28

Browse files
author
thk123
committed
Introduce throwing a guard conversion exception
Throw the unwrapped exception as a string
1 parent 12f25c2 commit a97bc28

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*******************************************************************\
2+
3+
Module: Symbolic Execution
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Exceptions that can be raised during the equation conversion phase
11+
12+
#ifndef CPROVER_GOTO_SYMEX_EQUATION_CONVERSION_EXCEPTIONS_H
13+
#define CPROVER_GOTO_SYMEX_EQUATION_CONVERSION_EXCEPTIONS_H
14+
15+
#include <ostream>
16+
#include <util/namespace.h>
17+
#include "symex_target_equation.h"
18+
19+
class guard_conversion_exceptiont : public std::runtime_error
20+
{
21+
public:
22+
guard_conversion_exceptiont(
23+
const symex_target_equationt::SSA_stept &step,
24+
const namespacet &ns)
25+
: runtime_error("Error converting guard for step"), step(step)
26+
{
27+
std::ostringstream error_msg;
28+
error_msg << runtime_error::what();
29+
error_msg << "\nStep:\n";
30+
step.output(ns, error_msg);
31+
error_message = error_msg.str();
32+
}
33+
34+
explicit guard_conversion_exceptiont(
35+
const symex_target_equationt::SSA_stept &step)
36+
: guard_conversion_exceptiont(step, namespacet{symbol_tablet{}})
37+
{
38+
}
39+
40+
const char *what() const noexcept override
41+
{
42+
return error_message.c_str();
43+
}
44+
45+
private:
46+
symex_target_equationt::SSA_stept step;
47+
std::string error_message;
48+
};
49+
50+
#endif // CPROVER_GOTO_SYMEX_EQUATION_CONVERSION_EXCEPTIONS_H

src/goto-symex/symex_target_equation.cpp

+26-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ Author: Daniel Kroening, [email protected]
1212
#include "symex_target_equation.h"
1313

1414
#include <util/std_expr.h>
15+
#include <util/unwrap_nested_exception.h>
1516

1617
#include <langapi/language_util.h>
17-
#include <solvers/prop/prop_conv.h>
18-
#include <solvers/prop/prop.h>
18+
#include <solvers/flattening/bv_conversion_exceptions.h>
1919
#include <solvers/prop/literal_expr.h>
20+
#include <solvers/prop/prop.h>
21+
#include <solvers/prop/prop_conv.h>
2022

23+
#include "equation_conversion_exceptions.h"
2124
#include "goto_symex_state.h"
2225

2326
/// read from a shared variable
@@ -368,7 +371,17 @@ void symex_target_equationt::constraint(
368371
void symex_target_equationt::convert(
369372
prop_convt &prop_conv)
370373
{
371-
convert_guards(prop_conv);
374+
try
375+
{
376+
convert_guards(prop_conv);
377+
}
378+
catch(guard_conversion_exceptiont &guard_conversion_exception)
379+
{
380+
// unwrap the except and throw like normal
381+
const std::string full_error = unwrap_exception(guard_conversion_exception);
382+
throw full_error;
383+
}
384+
372385
convert_assignments(prop_conv);
373386
convert_decls(prop_conv);
374387
convert_assumptions(prop_conv);
@@ -417,7 +430,16 @@ void symex_target_equationt::convert_guards(
417430
if(step.ignore)
418431
step.guard_literal=const_literal(false);
419432
else
420-
step.guard_literal=prop_conv.convert(step.guard);
433+
{
434+
try
435+
{
436+
step.guard_literal = prop_conv.convert(step.guard);
437+
}
438+
catch(const bitvector_conversion_exceptiont &conversion_exception)
439+
{
440+
std::throw_with_nested(guard_conversion_exceptiont(step));
441+
}
442+
}
421443
}
422444
}
423445

0 commit comments

Comments
 (0)