Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/solvers/lowering/byte_operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Author: Daniel Kroening, kroening@kroening.com
#include <util/pointer_offset_size.h>
#include <util/replace_symbol.h>
#include <util/simplify_expr.h>
#include <util/string_constant.h>

#include "flatten_byte_extract_exceptions.h"

Expand Down Expand Up @@ -275,6 +276,26 @@ static exprt unpack_rec(
ns,
unpack_byte_array);
}
else if(src.id() == ID_string_constant)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wrong, but I think these are not used by Java, so the commit message may need amending

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amended to not have that unnecessary restriction, but I do see results of git grep string_constantt in jbmc/ as well...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are used for input and output steps only; the Java bytecode parser makes them to describe string literals, but those are later transformed into references to constant java.lang.String instances, so there are no free-floating constants in the same way as there are in C.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok! I guess it must have been some C code where I had seen them in the wild.

{
return unpack_rec(
to_string_constant(src).to_array_expr(),
little_endian,
offset_bytes,
max_bytes,
ns,
unpack_byte_array);
}
else if(src.id() == ID_constant && src.type().id() == ID_string)
{
return unpack_rec(
string_constantt(to_constant_expr(src).get_value()).to_array_expr(),
little_endian,
offset_bytes,
max_bytes,
ns,
unpack_byte_array);
}
else if(src.type().id()!=ID_empty)
{
// a basic type; we turn that into extractbits while considering
Expand Down
30 changes: 30 additions & 0 deletions unit/solvers/lowering/byte_operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <util/simplify_expr.h>
#include <util/simplify_expr_class.h>
#include <util/std_types.h>
#include <util/string_constant.h>
#include <util/symbol_table.h>

SCENARIO("byte_extract_lowering", "[core][solvers][lowering][byte_extract]")
Expand Down Expand Up @@ -90,6 +91,35 @@ SCENARIO("byte_extract_lowering", "[core][solvers][lowering][byte_extract]")
}
}

GIVEN("A a byte_extract from a string constant")
{
string_constantt s("ABCD");
const byte_extract_exprt be1(
ID_byte_extract_little_endian,
s,
from_integer(1, index_type()),
unsignedbv_typet(16));

THEN("byte_extract lowering yields the expected value")
{
const exprt lower_be1 = lower_byte_extract(be1, ns);

REQUIRE(!has_subexpr(lower_be1, ID_byte_extract_little_endian));
REQUIRE(lower_be1.type() == be1.type());
REQUIRE(
lower_be1 == from_integer((int{'C'} << 8) + 'B', unsignedbv_typet(16)));

byte_extract_exprt be2 = be1;
be2.id(ID_byte_extract_big_endian);
const exprt lower_be2 = lower_byte_extract(be2, ns);

REQUIRE(!has_subexpr(lower_be2, ID_byte_extract_big_endian));
REQUIRE(lower_be2.type() == be2.type());
REQUIRE(
lower_be2 == from_integer((int{'B'} << 8) + 'C', unsignedbv_typet(16)));
}
}

GIVEN("A collection of types")
{
unsignedbv_typet u8(8);
Expand Down