Skip to content

Commit 315d05f

Browse files
authored
Merge pull request #3593 from tautschnig/fix-xml-binary
Fix binary value string in XML representation of expressions
2 parents 99b2288 + 0fe5168 commit 315d05f

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/util/xml_expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ xmlt xml(
164164
std::size_t width=to_bitvector_type(type).get_width();
165165

166166
result.name="integer";
167-
result.set_attribute("binary",
168-
id2string(to_constant_expr(expr).get_value()));
167+
result.set_attribute(
168+
"binary", integer2binary(numeric_cast_v<mp_integer>(expr), width));
169169
result.set_attribute("width", width);
170170

171171
const typet &underlying_type = type.id() == ID_c_bit_field

unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ SRC += analyses/ai/ai.cpp \
6565
util/symbol_table.cpp \
6666
util/symbol.cpp \
6767
util/unicode.cpp \
68+
util/xml_expr.cpp \
6869
# Empty last line
6970

7071
INCLUDES= -I ../src/ -I.

unit/util/xml_expr.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests of expression to xmlt conversion
4+
5+
Author: Michael Tautschnig
6+
7+
\*******************************************************************/
8+
9+
#include <testing-utils/catch.hpp>
10+
11+
#include <util/arith_tools.h>
12+
#include <util/config.h>
13+
#include <util/namespace.h>
14+
#include <util/std_expr.h>
15+
#include <util/symbol_table.h>
16+
#include <util/xml_expr.h>
17+
18+
TEST_CASE("Constant expression to XML")
19+
{
20+
config.set_arch("none");
21+
22+
const symbol_tablet symbol_table;
23+
const namespacet ns(symbol_table);
24+
25+
const constant_exprt number = from_integer(0xFF, unsignedbv_typet(8));
26+
const xmlt x = xml(number, ns);
27+
28+
REQUIRE(x.get_attribute("binary") == "11111111");
29+
}

0 commit comments

Comments
 (0)