Skip to content

Commit 33d9e32

Browse files
committed
Add binary representation to all bitvector values in the xml trace
The purpose of this is to provide a consistent interface for getting the values of bitvector-ed types out of the trace. An existing test is updated in this commit in order for the existing to test to match new functionality and so that every commit still passes all tests. There are instances when running with `--cprover-smt2` where the type of the expression is `bitvector_typet`, but the expression is not a `constant_exprt`. By removing the printing in this case we can avoid breaking the partial functionality available with the `--cprover-smt2` option.
1 parent 069db73 commit 33d9e32

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

regression/cbmc/xml-trace/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ VERIFICATION FAILED
88
<location file=".*" function="test" line="\d+" working-directory=".*"/>
99
<type>union myunion</type>
1010
<full_lhs>byte_extract_little_endian\(u, 0ll?, .*int.*\)</full_lhs>
11-
<full_lhs_value>\d+ll?</full_lhs_value>
11+
<full_lhs_value binary="[01]+">\d+ll?</full_lhs_value>
1212
<value>\{ \.i=\d+ll? \}</value>
1313
<value_expression>
1414
<union>

src/goto-programs/xml_goto_trace.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ Author: Daniel Kroening
2525
#include "structured_trace_util.h"
2626
#include "xml_expr.h"
2727

28-
bool full_lhs_value_includes_binary(
29-
const goto_trace_stept &step,
30-
const namespacet &ns)
31-
{
32-
return can_cast_type<floatbv_typet>(step.full_lhs_value.type());
33-
}
34-
3528
xmlt full_lhs_value(const goto_trace_stept &step, const namespacet &ns)
3629
{
3730
xmlt full_lhs_value{"full_lhs_value"};
@@ -40,13 +33,19 @@ xmlt full_lhs_value(const goto_trace_stept &step, const namespacet &ns)
4033
const irep_idt identifier =
4134
lhs_object.has_value() ? lhs_object->get_identifier() : irep_idt();
4235

43-
if(step.full_lhs_value.is_not_nil())
44-
full_lhs_value.data = from_expr(ns, identifier, step.full_lhs_value);
45-
if(full_lhs_value_includes_binary(step, ns))
36+
if(step.full_lhs_value.is_nil())
37+
return full_lhs_value;
38+
full_lhs_value.data = from_expr(ns, identifier, step.full_lhs_value);
39+
40+
const auto &bv_type =
41+
type_try_dynamic_cast<bitvector_typet>(step.full_lhs_value.type());
42+
const auto &constant =
43+
expr_try_dynamic_cast<constant_exprt>(step.full_lhs_value);
44+
if(bv_type && constant)
4645
{
47-
const auto width = to_floatbv_type(step.full_lhs_value.type()).get_width();
48-
const auto binary_representation = integer2binary(
49-
bvrep2integer(step.full_lhs_value.get(ID_value), width, false), width);
46+
const auto width = bv_type->get_width();
47+
const auto binary_representation =
48+
integer2binary(bvrep2integer(constant->get_value(), width, false), width);
5049
full_lhs_value.set_attribute("binary", binary_representation);
5150
}
5251
return full_lhs_value;

0 commit comments

Comments
 (0)