Skip to content

byte_extract lowering: Fail when we _don't_ have a constant [blocks: #2068] #4122

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 1 commit into from
Feb 7, 2019
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
2 changes: 1 addition & 1 deletion src/solvers/lowering/byte_operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ exprt lower_byte_extract(const byte_extract_exprt &src, const namespacet &ns)
if(!size_bits.has_value())
{
auto op0_bits = pointer_offset_bits(unpacked.op().type(), ns);
if(op0_bits.has_value())
if(!op0_bits.has_value())
{
throw non_const_byte_extraction_sizet(unpacked);
}
Expand Down
28 changes: 28 additions & 0 deletions unit/solvers/lowering/byte_operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@ SCENARIO("byte_extract_lowering", "[core][solvers][lowering][byte_extract]")
}
}

GIVEN("A an unbounded byte_extract over a bounded operand")
{
const exprt deadbeef = from_integer(0xdeadbeef, unsignedbv_typet(32));
const byte_extract_exprt be1(
ID_byte_extract_little_endian,
deadbeef,
from_integer(1, index_type()),
struct_typet(
{{"unbounded_array",
array_typet(
unsignedbv_typet(16), exprt(ID_infinity, size_type()))}}));

THEN("byte_extract lowering does not raise an exception")
{
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());

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());
}
}

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