-
Notifications
You must be signed in to change notification settings - Fork 275
[TG-2922] Improve logging for byte flatten exceptions #2046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3207291
Introduce nested exception printing
9bd5222
Convert flatten_byte_extract to use structured exceptions
12f25c2
Introduce throwing bv_conversion expection
a97bc28
Introduce throwing a guard conversion exception
b866015
Provide the original goto statement in the error
9d41b0c
Disable nested exception printing for Windows
015b284
Test demonstrating logging with clause for dealing with Windows
21997b2
Add documentation to convert_bitvector
781bf7c
Introduce exceptions for all conversion steps.
54fb9ab
Use format rather than from_expr for output
f2a4054
Remove redundant default constructor
9874a6b
Reformatting touched output function
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+399 Bytes
regression/cbmc-java/dynamic-multi-dimensional-array/TestClass.class
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
regression/cbmc-java/dynamic-multi-dimensional-array/TestClass.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
public class TestClass { | ||
public static void f(int y) { | ||
float[][] a1 = new float[y][3]; | ||
int j = 0; | ||
a1[j][0] = 34.5f; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
regression/cbmc-java/dynamic-multi-dimensional-array/test.desc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CORE | ||
TestClass.class | ||
--function TestClass.f --cover location --unwind 2 | ||
Source GOTO statement: .* | ||
(^ exception: Can't convert byte_extraction|Nested exception printing not supported on Windows) | ||
^EXIT=6$ | ||
-- | ||
-- | ||
The exception thrown in this test is the symptom of a bug; the purpose of this | ||
test is the validate the output of that exception |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Symbolic Execution | ||
|
||
Author: Diffblue Ltd. | ||
|
||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Exceptions that can be raised during the equation conversion phase | ||
|
||
#ifndef CPROVER_GOTO_SYMEX_EQUATION_CONVERSION_EXCEPTIONS_H | ||
#define CPROVER_GOTO_SYMEX_EQUATION_CONVERSION_EXCEPTIONS_H | ||
|
||
#include <ostream> | ||
|
||
#include <util/format_expr.h> | ||
|
||
#include "symex_target_equation.h" | ||
|
||
class equation_conversion_exceptiont : public std::runtime_error | ||
{ | ||
public: | ||
equation_conversion_exceptiont( | ||
const std::string &message, | ||
const symex_target_equationt::SSA_stept &step) | ||
: runtime_error(message), step(step) | ||
{ | ||
std::ostringstream error_msg; | ||
error_msg << runtime_error::what(); | ||
error_msg << "\nSource GOTO statement: " << format(step.source.pc->code); | ||
error_msg << "\nStep:\n"; | ||
step.output(error_msg); | ||
error_message = error_msg.str(); | ||
} | ||
|
||
const char *what() const optional_noexcept override | ||
{ | ||
return error_message.c_str(); | ||
} | ||
|
||
private: | ||
symex_target_equationt::SSA_stept step; | ||
std::string error_message; | ||
}; | ||
|
||
#endif // CPROVER_GOTO_SYMEX_EQUATION_CONVERSION_EXCEPTIONS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,13 +11,20 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "symex_target_equation.h" | ||
|
||
#include <util/format_expr.h> | ||
#include <util/std_expr.h> | ||
#include <util/throw_with_nested.h> | ||
#include <util/unwrap_nested_exception.h> | ||
|
||
// Can be removed once deprecated SSA_stept::output is removed | ||
#include <langapi/language_util.h> | ||
#include <solvers/prop/prop_conv.h> | ||
#include <solvers/prop/prop.h> | ||
|
||
#include <solvers/flattening/bv_conversion_exceptions.h> | ||
#include <solvers/prop/literal_expr.h> | ||
#include <solvers/prop/prop.h> | ||
#include <solvers/prop/prop_conv.h> | ||
|
||
#include "equation_conversion_exceptions.h" | ||
#include "goto_symex_state.h" | ||
|
||
/// read from a shared variable | ||
|
@@ -368,14 +375,23 @@ void symex_target_equationt::constraint( | |
void symex_target_equationt::convert( | ||
prop_convt &prop_conv) | ||
{ | ||
convert_guards(prop_conv); | ||
convert_assignments(prop_conv); | ||
convert_decls(prop_conv); | ||
convert_assumptions(prop_conv); | ||
convert_assertions(prop_conv); | ||
convert_goto_instructions(prop_conv); | ||
convert_io(prop_conv); | ||
convert_constraints(prop_conv); | ||
try | ||
{ | ||
convert_guards(prop_conv); | ||
convert_assignments(prop_conv); | ||
convert_decls(prop_conv); | ||
convert_assumptions(prop_conv); | ||
convert_assertions(prop_conv); | ||
convert_goto_instructions(prop_conv); | ||
convert_io(prop_conv); | ||
convert_constraints(prop_conv); | ||
} | ||
catch(const equation_conversion_exceptiont &conversion_exception) | ||
{ | ||
// unwrap the except and throw like normal | ||
const std::string full_error = unwrap_exception(conversion_exception); | ||
throw full_error; | ||
} | ||
} | ||
|
||
/// converts assignments | ||
|
@@ -402,7 +418,16 @@ void symex_target_equationt::convert_decls( | |
{ | ||
// The result is not used, these have no impact on | ||
// the satisfiability of the formula. | ||
prop_conv.convert(step.cond_expr); | ||
try | ||
{ | ||
prop_conv.convert(step.cond_expr); | ||
} | ||
catch(const bitvector_conversion_exceptiont &conversion_exception) | ||
{ | ||
util_throw_with_nested( | ||
equation_conversion_exceptiont( | ||
"Error converting decls for step", step)); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -417,7 +442,18 @@ void symex_target_equationt::convert_guards( | |
if(step.ignore) | ||
step.guard_literal=const_literal(false); | ||
else | ||
step.guard_literal=prop_conv.convert(step.guard); | ||
{ | ||
try | ||
{ | ||
step.guard_literal = prop_conv.convert(step.guard); | ||
} | ||
catch(const bitvector_conversion_exceptiont &conversion_exception) | ||
{ | ||
util_throw_with_nested( | ||
equation_conversion_exceptiont( | ||
"Error converting guard for step", step)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -433,7 +469,18 @@ void symex_target_equationt::convert_assumptions( | |
if(step.ignore) | ||
step.cond_literal=const_literal(true); | ||
else | ||
step.cond_literal=prop_conv.convert(step.cond_expr); | ||
{ | ||
try | ||
{ | ||
step.cond_literal = prop_conv.convert(step.cond_expr); | ||
} | ||
catch(const bitvector_conversion_exceptiont &conversion_exception) | ||
{ | ||
util_throw_with_nested( | ||
equation_conversion_exceptiont( | ||
"Error converting assumptions for step", step)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -450,7 +497,18 @@ void symex_target_equationt::convert_goto_instructions( | |
if(step.ignore) | ||
step.cond_literal=const_literal(true); | ||
else | ||
step.cond_literal=prop_conv.convert(step.cond_expr); | ||
{ | ||
try | ||
{ | ||
step.cond_literal = prop_conv.convert(step.cond_expr); | ||
} | ||
catch(const bitvector_conversion_exceptiont &conversion_exception) | ||
{ | ||
util_throw_with_nested( | ||
equation_conversion_exceptiont( | ||
"Error converting goto instructions for step", step)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -519,7 +577,16 @@ void symex_target_equationt::convert_assertions( | |
step.cond_expr); | ||
|
||
// do the conversion | ||
step.cond_literal=prop_conv.convert(implication); | ||
try | ||
{ | ||
step.cond_literal = prop_conv.convert(implication); | ||
} | ||
catch(const bitvector_conversion_exceptiont &conversion_exception) | ||
{ | ||
util_throw_with_nested( | ||
equation_conversion_exceptiont( | ||
"Error converting assertions for step", step)); | ||
} | ||
|
||
// store disjunct | ||
disjuncts.push_back(literal_exprt(!step.cond_literal)); | ||
|
@@ -703,3 +770,118 @@ void symex_target_equationt::SSA_stept::output( | |
|
||
out << "Guard: " << from_expr(ns, source.pc->function, guard) << '\n'; | ||
} | ||
|
||
void symex_target_equationt::SSA_stept::output(std::ostream &out) const | ||
{ | ||
if(source.is_set) | ||
{ | ||
out << "Thread " << source.thread_nr; | ||
|
||
if(source.pc->source_location.is_not_nil()) | ||
out << " " << source.pc->source_location << '\n'; | ||
else | ||
out << '\n'; | ||
} | ||
|
||
switch(type) | ||
{ | ||
case goto_trace_stept::typet::ASSERT: | ||
out << "ASSERT " << format(cond_expr) << '\n'; | ||
break; | ||
case goto_trace_stept::typet::ASSUME: | ||
out << "ASSUME " << format(cond_expr) << '\n'; | ||
break; | ||
case goto_trace_stept::typet::LOCATION: | ||
out << "LOCATION" << '\n'; | ||
break; | ||
case goto_trace_stept::typet::INPUT: | ||
out << "INPUT" << '\n'; | ||
break; | ||
case goto_trace_stept::typet::OUTPUT: | ||
out << "OUTPUT" << '\n'; | ||
break; | ||
|
||
case goto_trace_stept::typet::DECL: | ||
out << "DECL" << '\n'; | ||
out << format(ssa_lhs) << '\n'; | ||
break; | ||
|
||
case goto_trace_stept::typet::ASSIGNMENT: | ||
out << "ASSIGNMENT ("; | ||
switch(assignment_type) | ||
{ | ||
case assignment_typet::HIDDEN: | ||
out << "HIDDEN"; | ||
break; | ||
case assignment_typet::STATE: | ||
out << "STATE"; | ||
break; | ||
case assignment_typet::VISIBLE_ACTUAL_PARAMETER: | ||
out << "VISIBLE_ACTUAL_PARAMETER"; | ||
break; | ||
case assignment_typet::HIDDEN_ACTUAL_PARAMETER: | ||
out << "HIDDEN_ACTUAL_PARAMETER"; | ||
break; | ||
case assignment_typet::PHI: | ||
out << "PHI"; | ||
break; | ||
case assignment_typet::GUARD: | ||
out << "GUARD"; | ||
break; | ||
default: | ||
{ | ||
} | ||
} | ||
|
||
out << ")\n"; | ||
break; | ||
|
||
case goto_trace_stept::typet::DEAD: | ||
out << "DEAD\n"; | ||
break; | ||
case goto_trace_stept::typet::FUNCTION_CALL: | ||
out << "FUNCTION_CALL\n"; | ||
break; | ||
case goto_trace_stept::typet::FUNCTION_RETURN: | ||
out << "FUNCTION_RETURN\n"; | ||
break; | ||
case goto_trace_stept::typet::CONSTRAINT: | ||
out << "CONSTRAINT\n"; | ||
break; | ||
case goto_trace_stept::typet::SHARED_READ: | ||
out << "SHARED READ\n"; | ||
break; | ||
case goto_trace_stept::typet::SHARED_WRITE: | ||
out << "SHARED WRITE\n"; | ||
break; | ||
case goto_trace_stept::typet::ATOMIC_BEGIN: | ||
out << "ATOMIC_BEGIN\n"; | ||
break; | ||
case goto_trace_stept::typet::ATOMIC_END: | ||
out << "AUTOMIC_END\n"; | ||
break; | ||
case goto_trace_stept::typet::SPAWN: | ||
out << "SPAWN\n"; | ||
break; | ||
case goto_trace_stept::typet::MEMORY_BARRIER: | ||
out << "MEMORY_BARRIER\n"; | ||
break; | ||
case goto_trace_stept::typet::GOTO: | ||
out << "IF " << format(cond_expr) << " GOTO\n"; | ||
break; | ||
|
||
default: | ||
UNREACHABLE; | ||
} | ||
|
||
if(is_assert() || is_assume() || is_assignment() || is_constraint()) | ||
out << format(cond_expr) << '\n'; | ||
|
||
if(is_assert() || is_constraint()) | ||
out << comment << '\n'; | ||
|
||
if(is_shared_read() || is_shared_write()) | ||
out << format(ssa_lhs) << '\n'; | ||
|
||
out << "Guard: " << format(guard) << '\n'; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not currently reviewing this commit-by-commit so please excuse if my comment is wrong: this should go in a commit of its own. I agree that it can safely be removed, but this shouldn't be done as part of some random changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this happened as I went from
= default
-> one that takes a namespace ->no constructor
. Will update the last commit to go back to= default
and while I'm in the area append an extra commit to remove it. I think this is the most logical commit historyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant, thank you very much!